From aa280de5610879ad00d5e3d492298e469aced68c Mon Sep 17 00:00:00 2001 From: UznetDev Date: Thu, 27 Feb 2025 14:00:37 +0500 Subject: [PATCH 01/71] Refactor logging configuration and update log file path; enhance .gitignore and requirements --- .gitignore | 6 +++++- data/config.py | 2 +- loader.py | 17 +++++++++-------- logs/logging.log | 6 ++++++ main.py | 38 ++++++++++++++++++++++++++++---------- requirements.txt | 30 +++++++++++++++++++++++++++--- utils/notify_admins.py | 5 ++++- 7 files changed, 80 insertions(+), 24 deletions(-) create mode 100644 logs/logging.log diff --git a/.gitignore b/.gitignore index ce02f54..a1ee7b8 100755 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,8 @@ /.env /_build* /.vscode* -*my_test \ No newline at end of file +*my_test +__pycache__ +__pycache__/* +*.so +*.json \ No newline at end of file diff --git a/data/config.py b/data/config.py index 1ea431e..2b048d0 100644 --- a/data/config.py +++ b/data/config.py @@ -20,7 +20,7 @@ soat_minut_sekund = f"{datas.hour}:{datas.minute}:{datas.second}" # The current time (hour:minute:second) # Define the log file name and path -log_file_name = 'db/logging.log' # The log file path for logging database activities +log_file_name = 'logs/logging.log' # The log file path for logging database activities # Date and time diff --git a/loader.py b/loader.py index 3931380..ccef76c 100755 --- a/loader.py +++ b/loader.py @@ -1,22 +1,23 @@ from aiogram import Bot, Dispatcher from aiogram.enums import ParseMode from aiogram.fsm.storage.memory import MemoryStorage -from data.config import * # Import all configurations from the config module +from aiogram.client.bot import DefaultBotProperties # Yangi versiyadagi default sozlamalar uchun +from data.config import * # Konfiguratsiyalarni import qilamiz from utils.db_api.mysql_db import Database from cython_code.file_db import BotDb, FileDB -# Initialize the Telegram bot with the given token and parse mode set to HTML -bot = Bot(token=BOT_TOKEN, parse_mode=ParseMode.HTML) +# Botni token va default parametr orqali yaratamiz +bot = Bot(token=BOT_TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML)) -# Initialize memory storage for the dispatcher +# Xotira asosidagi storage ni yaratamiz storage = MemoryStorage() -# Initialize the dispatcher with the memory storage -dp = Dispatcher(storage=storage) +# Dispatcher obyektini yaratishda bot va storage ni uzatamiz +dp = Dispatcher(bot=bot, storage=storage) -# Initialize the MySQL database connection +# MySQL ma'lumotlar bazasi ulanishini yaratamiz db = Database(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) -# Initialize the BotDb with the specified JSON file +# JSON fayllar bilan ishlash uchun obyektlar DB = BotDb(file='data/db.json') file_db = FileDB(file='data/file_db.json') diff --git a/logs/logging.log b/logs/logging.log new file mode 100644 index 0000000..49c03cd --- /dev/null +++ b/logs/logging.log @@ -0,0 +1,6 @@ +dispatcher.py - start_polling - 527 - aiogram.dispatcher - INFO - Start polling +dispatcher.py - _polling - 341 - aiogram.dispatcher - INFO - Run polling for bot @Biloger_uzbot id=1430978281 - 'B' +dispatcher.py - _signal_stop_polling - 455 - aiogram.dispatcher - WARNING - Received SIGINT signal +dispatcher.py - _polling - 359 - aiogram.dispatcher - INFO - Polling stopped for bot @Biloger_uzbot id=1430978281 - 'B' +dispatcher.py - start_polling - 554 - aiogram.dispatcher - INFO - Polling stopped +main.py - main - 39 - root - INFO - 1 diff --git a/main.py b/main.py index 4ea029b..e9cc21a 100755 --- a/main.py +++ b/main.py @@ -1,6 +1,7 @@ import middlewares, handlers # Import middlewares and handlers modules import asyncio import sys +import os from utils.notify_admins import on_startup_notify # Import the function to notify admins on startup import logging from utils.set_bot_commands import set_default_commands # Import the function to set default bot commands @@ -13,7 +14,7 @@ async def main(): """ The main asynchronous function to start the bot and perform initial setup. """ - await on_startup_notify() # Notify admins about the bot startup + await on_startup_notify() await set_default_commands() # Set the default commands for the bot dp.update.middleware.register(ThrottlingMiddleware()) # Register the ThrottlingMiddleware @@ -40,14 +41,31 @@ async def main(): if __name__ == "__main__": - # Configure logging - format = '%(filename)s - %(funcName)s - %(lineno)d - %(name)s - %(levelname)s - %(message)s' - logging.basicConfig( - filename=log_file_name, # Save error log on file - level=logging.ERROR, # Set the logging level to INFO - format=format, # Set the logging format - # stream=sys.stdout # Log to stdout - ) - # Run the main function asynchronously + + if not os.path.exists('logs'): + os.mkdir('logs') + + if not os.path.exists(log_file_name): + with open(log_file_name, 'w') as f: + pass + + root_logger = logging.getLogger() + root_logger.setLevel(logging.INFO) + + log_format = '%(filename)s - %(funcName)s - %(lineno)d - %(name)s - %(levelname)s - %(message)s' + formatter = logging.Formatter(log_format) + + file_handler = logging.FileHandler(log_file_name) + file_handler.setLevel(logging.INFO) + file_handler.setFormatter(formatter) + root_logger.addHandler(file_handler) + + stream_handler = logging.StreamHandler(sys.stdout) + stream_handler.setLevel(logging.INFO) + stream_handler.setFormatter(formatter) + root_logger.addHandler(stream_handler) + asyncio.run(main()) + + diff --git a/requirements.txt b/requirements.txt index 83b1493..b0e92b2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,13 +1,37 @@ -aiogram==3.5.0 +aiofiles==23.2.1 +aiogram==3.18.0 +aiohttp==3.9.5 +aiosignal==1.3.2 +annotated-types==0.7.0 +attrs==25.1.0 +beautifulsoup4==4.13.3 +certifi==2025.1.31 +charset-normalizer==3.4.1 +Cython==3.0.11 deep-translator==1.11.4 environs==11.0.0 +et_xmlfile==2.0.0 +frozenlist==1.5.0 +idna==3.10 +magic-filter==1.0.12 +marshmallow==3.26.1 +multidict==6.1.0 mysql-connector-python==9.0.0 numpy==2.0.1 openpyxl==3.1.5 +packaging==24.2 pandas==2.2.2 +propcache==0.3.0 pydantic==2.7.4 pydantic_core==2.18.4 +python-dateutil==2.9.0.post0 python-dotenv==1.0.1 -Cython==3.0.11 +pytz==2025.1 requests==2.32.3 -urllib3==2.2.2 \ No newline at end of file +setuptools==75.8.2 +six==1.17.0 +soupsieve==2.6 +typing_extensions==4.12.2 +tzdata==2025.1 +urllib3==2.2.2 +yarl==1.18.3 diff --git a/utils/notify_admins.py b/utils/notify_admins.py index df19c1b..c6d406d 100755 --- a/utils/notify_admins.py +++ b/utils/notify_admins.py @@ -62,10 +62,13 @@ async def on_startup_notify(): # Delete the log file if it exceeds 40 MB if (os.path.getsize(log_file_name)) * (1024 * 124) > 40: - os.remove(log_file_name) + with open(log_file_name, 'w') as file: + file.truncate(0) except Exception as err: # Log any errors that occur while sending the log file logging.error(err) + if not os.path.exists(log_file_name): + os.mkdir(log_file_name) except Exception as Err: # Log any errors that occur while checking the log file logging.exception(Err) From 09b8cecad469fe69cc08813f6a86adfd447df3f0 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Thu, 27 Feb 2025 14:28:21 +0500 Subject: [PATCH 02/71] Update .gitignore to include log files and directories --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index a1ee7b8..2a06190 100755 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,7 @@ __pycache__ __pycache__/* *.so -*.json \ No newline at end of file +*.json +/logs/* +/logs/ +*.log \ No newline at end of file From 8427b204244db19a0f47a478a8f3e171f487e279 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Thu, 27 Feb 2025 14:29:11 +0500 Subject: [PATCH 03/71] Refactor database interaction methods to use 'insert_' prefix for user, admin, channel, and ban operations --- handlers/admins/admin_settings/add_admin.py | 6 +- handlers/admins/channel_settings/get_id.py | 6 +- handlers/admins/check_usr/block_users.py | 6 +- handlers/users/check_ban.py | 4 +- handlers/users/check_usr.py | 4 +- handlers/users/start.py | 6 +- utils/db_api/mysql_db.py | 402 ++++++++++++-------- 7 files changed, 251 insertions(+), 183 deletions(-) diff --git a/handlers/admins/admin_settings/add_admin.py b/handlers/admins/admin_settings/add_admin.py index 7a606b0..282d915 100755 --- a/handlers/admins/admin_settings/add_admin.py +++ b/handlers/admins/admin_settings/add_admin.py @@ -51,9 +51,9 @@ async def add_admin(msg: types.Message, state: FSMContext): if check is None: # Add the new admin to the database - db.add_admin(cid=user_id, - date=f"{yil_oy_kun} / {soat_minut_sekund}", - add=cid) + db.insert_admin(cid=user_id, + date=f"{yil_oy_kun} / {soat_minut_sekund}", + add=cid) text = translator(text="✅ Admin has been successfully added\n\nName: ", dest=lang) text += f"{user.full_name}\n" diff --git a/handlers/admins/channel_settings/get_id.py b/handlers/admins/channel_settings/get_id.py index a695ed0..21d628e 100755 --- a/handlers/admins/channel_settings/get_id.py +++ b/handlers/admins/channel_settings/get_id.py @@ -47,9 +47,9 @@ async def add_channel2(msg: types.Message, state: FSMContext): if check is None: # Add the channel to the database if it doesn't exist - db.add_channel(cid=tx, - date=f'{yil_oy_kun} / {soat_minut_sekund}', - add_cid=cid) + db.insert_channel(cid=tx, + date=f'{yil_oy_kun} / {soat_minut_sekund}', + add_cid=cid) text = translator(text="✅ The channel was successfully added\n", dest=lang) text += f"Name: {channel.full_name}\n" \ f"Username: @{channel.username}" diff --git a/handlers/admins/check_usr/block_users.py b/handlers/admins/check_usr/block_users.py index 243c2bb..098b7e2 100755 --- a/handlers/admins/check_usr/block_users.py +++ b/handlers/admins/check_usr/block_users.py @@ -48,9 +48,9 @@ async def block_users(call: types.CallbackQuery, callback_data: BlockUser, state check = db.check_user_ban(cid=user_id) # Check if the user is already banned user = await bot.get_chat(chat_id=user_id) # Get user details if check is None: - db.add_user_ban(cid=user_id, - admin_cid=cid, - date=f'{yil_oy_kun} / {soat_minut_sekund}') # Add user to ban list + db.insert_user_ban(cid=user_id, + admin_cid=cid, + date=f'{yil_oy_kun} / {soat_minut_sekund}') # Add user to ban list text = translator(text='⛔ User blocked\n\n Username: @', dest=lang) text += str(user.username) await bot.send_message(chat_id=user_id, diff --git a/handlers/users/check_ban.py b/handlers/users/check_ban.py index 2089112..c6d9a57 100755 --- a/handlers/users/check_ban.py +++ b/handlers/users/check_ban.py @@ -42,8 +42,8 @@ async def ban_handler(msg: types.Message): # Add the user to the database if they are not already present if db.check_user(cid=cid) is None: - db.add_user(cid=cid, - date=f"{yil_oy_kun} / {soat_minut_sekund}") + db.insert_user(cid=cid, + date=f"{yil_oy_kun} / {soat_minut_sekund}") except Exception as err: logging.error(f"Error in start_handler: {err}") diff --git a/handlers/users/check_usr.py b/handlers/users/check_usr.py index fe1fc16..9a38a46 100755 --- a/handlers/users/check_usr.py +++ b/handlers/users/check_usr.py @@ -60,8 +60,8 @@ async def start_handler(msg: types.Message): # Add user to the database if not already present if db.check_user(cid=user_id) is None: - db.add_user(cid=user_id, - date=f"{date_day_month} / {time_hour_minute_second}") + db.insert_user(cid=user_id, + date=f"{date_day_month} / {time_hour_minute_second}") except Exception as err: logging.error(f"Error in start_handler: {err}") diff --git a/handlers/users/start.py b/handlers/users/start.py index ad365b1..1e54b7b 100755 --- a/handlers/users/start.py +++ b/handlers/users/start.py @@ -45,8 +45,8 @@ async def start_handler(msg: types.Message): # Check and log the user if not already in the database if db.check_user(cid=user_id) is None: - db.add_user(cid=user_id, - date=f'{yil_oy_kun} / {soat_minut_sekund}', - lang=user_language) + db.insert_user(cid=user_id, + date=f'{yil_oy_kun} / {soat_minut_sekund}', + lang=user_language) except Exception as err: logging.error(f"Error handling /start command: {err}") diff --git a/utils/db_api/mysql_db.py b/utils/db_api/mysql_db.py index 06fd06f..882343a 100755 --- a/utils/db_api/mysql_db.py +++ b/utils/db_api/mysql_db.py @@ -3,6 +3,7 @@ class Database: + def __init__(self, host, user, password, database): """ Initialize the Database object with connection parameters. @@ -19,9 +20,31 @@ def __init__(self, host, user, password, database): self.database = database self.reconnect() + def reconnect(self): """ - Reconnect to the MySQL database. If the connection fails, log the error and attempt to reconnect. + Reconnect to the MySQL database. + + This method initializes or re-initializes the database connection and cursor + objects. It is generally called: + - Right after the object is created (inside __init__). + - After a failed connection or if a connection error occurs. + + If the connection is successful, `self.connection` and `self.cursor` are + reset. If it fails, an error is logged and re-raised. + + Returns: + None + + Raises: + mysql.connector.Error: + If connecting to the database fails due to invalid credentials, + unreachable host, etc. + + Example: + >>> db = Database("root", "secret", "my_database") + >>> # If for some reason the connection is lost, you can manually reconnect: + >>> db.reconnect() """ try: self.connection = mysql.connector.connect( @@ -29,14 +52,29 @@ def reconnect(self): user=self.user, password=self.password, database=self.database, + connection_timeout=30, autocommit=True ) - self.cursor = self.connection.cursor() + self.cursor = self.connection.cursor(dictionary=True) except mysql.connector.Error as err: - logging.error(err) + logging.error(f"Database connection error: {err}") + raise + + + def __del__(self): + """ + Close the database connection when the Database object is deleted. + """ + try: + self.connection.close() + except mysql.connector.Error as err: + logging.error(f"MySQL Error: {err}") self.reconnect() except Exception as err: - logging.error(err) + logging.error(f"General Error: {err}") + + + ## --------------------- Create table ------------------## def create_table_ban(self): """ @@ -48,6 +86,7 @@ def create_table_ban(self): id INT AUTO_INCREMENT PRIMARY KEY, cid bigint(20) NOT NULL UNIQUE, admin_cid bigint(20), + update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, date varchar(255) ) """ @@ -59,7 +98,155 @@ def create_table_ban(self): except Exception as err: logging.error(err) - def add_user_ban(self, cid, date, admin_cid): + + def create_table_users(self): + """ + Create the 'users' table if it does not already exist. + """ + try: + sql = """ + CREATE TABLE IF NOT EXISTS users ( + id INT AUTO_INCREMENT PRIMARY KEY, + cid bigint(20) NOT NULL UNIQUE, + update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + date varchar(255), + lang varchar(5) + ) + """ + self.cursor.execute(sql) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + + def create_table_channel(self): + """ + Create the 'channels' table if it does not already exist. + """ + try: + sql = """ + CREATE TABLE IF NOT EXISTS channels ( + id INT AUTO_INCREMENT PRIMARY KEY, + cid bigint(200), + update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + date varchar(255), + add_cid int(200) + ); + """ + self.cursor.execute(sql) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + + def create_table_admins(self): + """ + Create the 'admins' table if it does not already exist. + """ + try: + sql = """ + CREATE TABLE IF NOT EXISTS admins ( + id INT AUTO_INCREMENT PRIMARY KEY, + cid bigint(20) NOT NULL UNIQUE, + add_cid bigint(20), + send_message TINYINT(1), + statistika TINYINT(1), + download_statistika TINYINT(1), + block_user TINYINT(1), + channel_settings TINYINT(1), + add_admin TINYINT(1), + set TINYINT(1), + get TINYINT(1), + update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + date varchar(255) + ); + """ + self.cursor.execute(sql) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + ## ------------------ Insert data ------------------ ## + + def insert_user(self, cid, date, lang): + """ + Add a user to the 'users' table. + + Parameters: + cid (int): The user's chat ID. + date (str): The date the user was added. + lang (str): The user's language preference. + """ + try: + sql = """ + INSERT INTO `users` (`cid`,`date`,`lang`) VALUES (%s,%s,%s) + """ + values = (cid, date, lang) + self.cursor.execute(sql, values) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + + def insert_channel(self, cid, date, add_cid): + """ + Add a channel to the 'channels' table. + + Parameters: + cid (int): The channel's ID. + date (str): The date the channel was added. + add_cid (int): The chat ID of the admin who added the channel. + """ + try: + sql = """ + INSERT INTO `channels` (`cid`,`date`,`add_cid`) VALUES (%s,%s,%s) + """ + values = (cid, date, add_cid) + self.cursor.execute(sql, values) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + + def insert_admin(self, cid, date, add): + """ + Add an admin to the 'admins' table. + + Parameters: + cid (int): The admin's chat ID. + date (str): The date the admin was added. + add (int): The chat ID of the admin who added this admin. + """ + try: + sql = """ + INSERT INTO `admins` (`cid`,`add_cid`,`date`) VALUES (%s,%s,%s) + """ + values = (cid, add, date) + self.cursor.execute(sql, values) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + + def insert_user_ban(self, cid, date, admin_cid): """ Add a user to the 'ban' table. @@ -81,6 +268,7 @@ def add_user_ban(self, cid, date, admin_cid): except Exception as err: logging.error(err) + def select_all_users_ban(self): """ Select all users from the 'ban' table. @@ -100,6 +288,32 @@ def select_all_users_ban(self): self.reconnect() except Exception as err: logging.error(err) + + ## ------------------ Update ------------------ ## + + + def update_admin_data(self, cid, column, value): + """ + Update an admin's data in the 'admins' table. + + Parameters: + cid (int): The admin's chat ID. + column (str): The column to be updated. + value (str): The new value for the specified column. + """ + try: + sql = f"""UPDATE `admins` SET `{column}` = '{value}' WHERE `cid`=%s""" + values = (cid,) + self.cursor.execute(sql, values) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + ## ------------------ Select ------------------ ## + def stat_ban(self): """ @@ -119,6 +333,7 @@ def stat_ban(self): except Exception as err: logging.error(err) + def check_user_ban(self, cid): """ Check if a user is banned. @@ -139,6 +354,7 @@ def check_user_ban(self, cid): except Exception as err: logging.error(err) + def delete_user_ban(self, cid): """ Delete a user from the 'ban' table. @@ -154,48 +370,6 @@ def delete_user_ban(self, cid): except Exception as err: logging.error(err) - def create_table_users(self): - """ - Create the 'users' table if it does not already exist. - """ - try: - sql = """ - CREATE TABLE IF NOT EXISTS users ( - id INT AUTO_INCREMENT PRIMARY KEY, - cid bigint(20) NOT NULL UNIQUE, - date varchar(255), - lang varchar(5) - ) - """ - self.cursor.execute(sql) - self.connection.commit() - except mysql.connector.Error as err: - logging.error(err) - self.reconnect() - except Exception as err: - logging.error(err) - - def add_user(self, cid, date, lang): - """ - Add a user to the 'users' table. - - Parameters: - cid (int): The user's chat ID. - date (str): The date the user was added. - lang (str): The user's language preference. - """ - try: - sql = """ - INSERT INTO `users` (`cid`,`date`,`lang`) VALUES (%s,%s,%s) - """ - values = (cid, date, lang) - self.cursor.execute(sql, values) - self.connection.commit() - except mysql.connector.Error as err: - logging.error(err) - self.reconnect() - except Exception as err: - logging.error(err) def select_all_users(self): """ @@ -217,6 +391,7 @@ def select_all_users(self): except Exception as err: logging.error(err) + def select_users_by_id(self, start_id: int, end_id: int) -> list: """ Select user from the 'users' table on id. @@ -238,6 +413,7 @@ def select_users_by_id(self, start_id: int, end_id: int) -> list: except Exception as err: logging.error(err) + def stat(self): """ Get the total number of users. @@ -256,6 +432,7 @@ def stat(self): except Exception as err: logging.error(err) + def check_user(self, cid): """ Check if a user exists in the 'users' table. @@ -276,52 +453,6 @@ def check_user(self, cid): except Exception as err: logging.error(err) - def create_table_admins(self): - """ - Create the 'admins' table if it does not already exist. - """ - try: - sql = """ - CREATE TABLE IF NOT EXISTS admins ( - id INT AUTO_INCREMENT PRIMARY KEY, - cid bigint(20) NOT NULL UNIQUE, - add_cid bigint(20), - send_message TINYINT(1), - statistika TINYINT(1), - download_statistika TINYINT(1), - block_user TINYINT(1), - channel_settings TINYINT(1), - add_admin TINYINT(1), - date varchar(255) - ); - """ - self.cursor.execute(sql) - self.connection.commit() - except mysql.connector.Error as err: - logging.error(err) - self.reconnect() - except Exception as err: - logging.error(err) - - def update_admin_data(self, cid, column, value): - """ - Update an admin's data in the 'admins' table. - - Parameters: - cid (int): The admin's chat ID. - column (str): The column to be updated. - value (str): The new value for the specified column. - """ - try: - sql = f"""UPDATE `admins` SET `{column}` = '{value}' WHERE `cid`=%s""" - values = (cid,) - self.cursor.execute(sql, values) - self.connection.commit() - except mysql.connector.Error as err: - logging.error(err) - self.reconnect() - except Exception as err: - logging.error(err) def select_admin_column(self, cid, column): """ @@ -344,27 +475,6 @@ def select_admin_column(self, cid, column): except Exception as err: logging.error(err) - def add_admin(self, cid, date, add): - """ - Add an admin to the 'admins' table. - - Parameters: - cid (int): The admin's chat ID. - date (str): The date the admin was added. - add (int): The chat ID of the admin who added this admin. - """ - try: - sql = """ - INSERT INTO `admins` (`cid`,`add_cid`,`date`) VALUES (%s,%s,%s) - """ - values = (cid, add, date) - self.cursor.execute(sql, values) - self.connection.commit() - except mysql.connector.Error as err: - logging.error(err) - self.reconnect() - except Exception as err: - logging.error(err) def select_admin(self, cid): """ @@ -386,6 +496,7 @@ def select_admin(self, cid): except Exception as err: logging.error(err) + def select_add_admin(self, cid): """ Select all admins added by a specific admin from the 'admins' table. @@ -406,6 +517,7 @@ def select_add_admin(self, cid): except Exception as err: logging.error(err) + def select_all_admins(self): """ Select all admins from the 'admins' table. @@ -426,6 +538,7 @@ def select_all_admins(self): except Exception as err: logging.error(err) + def stat_admins(self): """ Get the total number of admins. @@ -444,6 +557,7 @@ def stat_admins(self): except Exception as err: logging.error(err) + def delete_admin(self, cid): """ Delete an admin from the 'admins' table. @@ -459,48 +573,6 @@ def delete_admin(self, cid): except Exception as err: logging.error(err) - def create_table_channel(self): - """ - Create the 'channels' table if it does not already exist. - """ - try: - sql = """ - CREATE TABLE IF NOT EXISTS channels ( - id INT AUTO_INCREMENT PRIMARY KEY, - cid bigint(200), - date varchar(255), - add_cid int(200) - ); - """ - self.cursor.execute(sql) - self.connection.commit() - except mysql.connector.Error as err: - logging.error(err) - self.reconnect() - except Exception as err: - logging.error(err) - - def add_channel(self, cid, date, add_cid): - """ - Add a channel to the 'channels' table. - - Parameters: - cid (int): The channel's ID. - date (str): The date the channel was added. - add_cid (int): The chat ID of the admin who added the channel. - """ - try: - sql = """ - INSERT INTO `channels` (`cid`,`date`,`add_cid`) VALUES (%s,%s,%s) - """ - values = (cid, date, add_cid) - self.cursor.execute(sql, values) - self.connection.commit() - except mysql.connector.Error as err: - logging.error(err) - self.reconnect() - except Exception as err: - logging.error(err) def select_channels(self): """ @@ -519,6 +591,7 @@ def select_channels(self): except Exception as err: logging.error(err) + def select_channels_add_cid(self, add_cid): """ Select all channels added by a specific admin from the 'channels' table. @@ -539,6 +612,7 @@ def select_channels_add_cid(self, add_cid): except Exception as err: logging.error(err) + def check_channel(self, cid): """ Check if a channel exists in the 'channels' table. @@ -559,6 +633,7 @@ def check_channel(self, cid): except Exception as err: logging.error(err) + def select_all_channel(self): """ Select all channels from the 'channels' table. @@ -579,6 +654,9 @@ def select_all_channel(self): except Exception as err: logging.error(err) + + ## -------------- Delete -------------- ## + def delete_channel(self, cid): """ Delete a channel from the 'channels' table. @@ -594,14 +672,4 @@ def delete_channel(self, cid): except Exception as err: logging.error(err) - def __del__(self): - """ - Close the database connection when the Database object is deleted. - """ - try: - self.connection.close() - except mysql.connector.Error as err: - logging.error(f"MySQL Error: {err}") - self.reconnect() - except Exception as err: - logging.error(f"General Error: {err}") + From 006c06d711f4fb559f90f8d10e5e3c11a75ed426 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Thu, 27 Feb 2025 14:35:18 +0500 Subject: [PATCH 04/71] Fix logging output format in main.py --- utils/db_api/mysql_db.py | 118 +++++++++++++++++++-------------------- 1 file changed, 59 insertions(+), 59 deletions(-) diff --git a/utils/db_api/mysql_db.py b/utils/db_api/mysql_db.py index 882343a..48203a8 100755 --- a/utils/db_api/mysql_db.py +++ b/utils/db_api/mysql_db.py @@ -84,8 +84,8 @@ def create_table_ban(self): sql = """ CREATE TABLE IF NOT EXISTS ban ( id INT AUTO_INCREMENT PRIMARY KEY, - cid bigint(20) NOT NULL UNIQUE, - admin_cid bigint(20), + user_id bigint(20) NOT NULL UNIQUE, + admin_user_id bigint(20), update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, date varchar(255) ) @@ -107,7 +107,7 @@ def create_table_users(self): sql = """ CREATE TABLE IF NOT EXISTS users ( id INT AUTO_INCREMENT PRIMARY KEY, - cid bigint(20) NOT NULL UNIQUE, + user_id bigint(20) NOT NULL UNIQUE, update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, date varchar(255), lang varchar(5) @@ -130,10 +130,10 @@ def create_table_channel(self): sql = """ CREATE TABLE IF NOT EXISTS channels ( id INT AUTO_INCREMENT PRIMARY KEY, - cid bigint(200), + channel_id bigint(200), update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, date varchar(255), - add_cid int(200) + add_user_id int(200) ); """ self.cursor.execute(sql) @@ -153,8 +153,8 @@ def create_table_admins(self): sql = """ CREATE TABLE IF NOT EXISTS admins ( id INT AUTO_INCREMENT PRIMARY KEY, - cid bigint(20) NOT NULL UNIQUE, - add_cid bigint(20), + user_id bigint(20) NOT NULL UNIQUE, + add_user_id bigint(20), send_message TINYINT(1), statistika TINYINT(1), download_statistika TINYINT(1), @@ -177,20 +177,20 @@ def create_table_admins(self): ## ------------------ Insert data ------------------ ## - def insert_user(self, cid, date, lang): + def insert_user(self, user_id, date, lang): """ Add a user to the 'users' table. Parameters: - cid (int): The user's chat ID. + user_id (int): The user's chat ID. date (str): The date the user was added. lang (str): The user's language preference. """ try: sql = """ - INSERT INTO `users` (`cid`,`date`,`lang`) VALUES (%s,%s,%s) + INSERT INTO `users` (`user_id`,`date`,`lang`) VALUES (%s,%s,%s) """ - values = (cid, date, lang) + values = (user_id, date, lang) self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: @@ -200,20 +200,20 @@ def insert_user(self, cid, date, lang): logging.error(err) - def insert_channel(self, cid, date, add_cid): + def insert_channel(self, user_id, date, add_user_id): """ Add a channel to the 'channels' table. Parameters: - cid (int): The channel's ID. + user_id (int): The channel's ID. date (str): The date the channel was added. - add_cid (int): The chat ID of the admin who added the channel. + add_user_id (int): The chat ID of the admin who added the channel. """ try: sql = """ - INSERT INTO `channels` (`cid`,`date`,`add_cid`) VALUES (%s,%s,%s) + INSERT INTO `channels` (`user_id`,`date`,`add_user_id`) VALUES (%s,%s,%s) """ - values = (cid, date, add_cid) + values = (user_id, date, add_user_id) self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: @@ -223,20 +223,20 @@ def insert_channel(self, cid, date, add_cid): logging.error(err) - def insert_admin(self, cid, date, add): + def insert_admin(self, user_id, date, add): """ Add an admin to the 'admins' table. Parameters: - cid (int): The admin's chat ID. + user_id (int): The admin's chat ID. date (str): The date the admin was added. add (int): The chat ID of the admin who added this admin. """ try: sql = """ - INSERT INTO `admins` (`cid`,`add_cid`,`date`) VALUES (%s,%s,%s) + INSERT INTO `admins` (`user_id`,`add_user_id`,`date`) VALUES (%s,%s,%s) """ - values = (cid, add, date) + values = (user_id, add, date) self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: @@ -246,20 +246,20 @@ def insert_admin(self, cid, date, add): logging.error(err) - def insert_user_ban(self, cid, date, admin_cid): + def insert_user_ban(self, user_id, date, admin_user_id): """ Add a user to the 'ban' table. Parameters: - cid (int): The user's chat ID. + user_id (int): The user's chat ID. date (str): The date the user was banned. - admin_cid (int): The admin's chat ID who banned the user. + admin_user_id (int): The admin's chat ID who banned the user. """ try: sql = """ - INSERT INTO `ban` (`cid`,`admin_cid`,`date`) VALUES (%s,%s,%s) + INSERT INTO `ban` (`user_id`,`admin_user_id`,`date`) VALUES (%s,%s,%s) """ - values = (cid, admin_cid, date) + values = (user_id, admin_user_id, date) self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: @@ -292,18 +292,18 @@ def select_all_users_ban(self): ## ------------------ Update ------------------ ## - def update_admin_data(self, cid, column, value): + def update_admin_data(self, user_id, column, value): """ Update an admin's data in the 'admins' table. Parameters: - cid (int): The admin's chat ID. + user_id (int): The admin's chat ID. column (str): The column to be updated. value (str): The new value for the specified column. """ try: - sql = f"""UPDATE `admins` SET `{column}` = '{value}' WHERE `cid`=%s""" - values = (cid,) + sql = f"""UPDATE `admins` SET `{column}` = '{value}' WHERE `user_id`=%s""" + values = (user_id,) self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: @@ -334,18 +334,18 @@ def stat_ban(self): logging.error(err) - def check_user_ban(self, cid): + def check_user_ban(self, user_id): """ Check if a user is banned. Parameters: - cid (int): The user's chat ID. + user_id (int): The user's chat ID. Returns: tuple: The user's ban information if they are banned, None otherwise. """ try: - self.cursor.execute("SELECT * FROM `ban` WHERE `cid`=%s", (cid,)) + self.cursor.execute("SELECT * FROM `ban` WHERE `user_id`=%s", (user_id,)) result = self.cursor.fetchone() return result except mysql.connector.Error as err: @@ -355,15 +355,15 @@ def check_user_ban(self, cid): logging.error(err) - def delete_user_ban(self, cid): + def delete_user_ban(self, user_id): """ Delete a user from the 'ban' table. Parameters: - cid (int): The user's chat ID. + user_id (int): The user's chat ID. """ try: - self.cursor.execute("DELETE FROM `ban` WHERE `cid`=%s", (cid,)) + self.cursor.execute("DELETE FROM `ban` WHERE `user_id`=%s", (user_id,)) except mysql.connector.Error as err: logging.error(err) self.reconnect() @@ -433,18 +433,18 @@ def stat(self): logging.error(err) - def check_user(self, cid): + def check_user(self, user_id): """ Check if a user exists in the 'users' table. Parameters: - cid (int): The user's chat ID. + user_id (int): The user's chat ID. Returns: tuple: The user's information if they exist, None otherwise. """ try: - self.cursor.execute("SELECT * FROM `users` WHERE `cid`=%s", (cid,)) + self.cursor.execute("SELECT * FROM `users` WHERE `user_id`=%s", (user_id,)) result = self.cursor.fetchone() return result except mysql.connector.Error as err: @@ -454,19 +454,19 @@ def check_user(self, cid): logging.error(err) - def select_admin_column(self, cid, column): + def select_admin_column(self, user_id, column): """ Select a specific column for an admin from the 'admins' table. Parameters: - cid (int): The admin's chat ID. + user_id (int): The admin's chat ID. column (str): The column to be selected. Returns: any: The value of the specified column for the admin. """ try: - self.cursor.execute(f"SELECT {column} FROM `admins` WHERE `cid`=%s", (cid,)) + self.cursor.execute(f"SELECT {column} FROM `admins` WHERE `user_id`=%s", (user_id,)) result = self.cursor.fetchone() return result except mysql.connector.Error as err: @@ -476,18 +476,18 @@ def select_admin_column(self, cid, column): logging.error(err) - def select_admin(self, cid): + def select_admin(self, user_id): """ Select an admin from the 'admins' table. Parameters: - cid (int): The admin's chat ID. + user_id (int): The admin's chat ID. Returns: tuple: The admin's information if they exist, None otherwise. """ try: - self.cursor.execute("SELECT * FROM `admins` WHERE `cid`=%s", (cid,)) + self.cursor.execute("SELECT * FROM `admins` WHERE `user_id`=%s", (user_id,)) result = self.cursor.fetchone() return result except mysql.connector.Error as err: @@ -497,18 +497,18 @@ def select_admin(self, cid): logging.error(err) - def select_add_admin(self, cid): + def select_add_admin(self, user_id): """ Select all admins added by a specific admin from the 'admins' table. Parameters: - cid (int): The chat ID of the admin who added other admins. + user_id (int): The chat ID of the admin who added other admins. Returns: list: A list of tuples containing the added admins' information. """ try: - self.cursor.execute("SELECT * FROM `admins` WHERE `add_cid`=%s", (cid,)) + self.cursor.execute("SELECT * FROM `admins` WHERE `add_user_id`=%s", (user_id,)) result = self.cursor.fetchall() return result except mysql.connector.Error as err: @@ -558,15 +558,15 @@ def stat_admins(self): logging.error(err) - def delete_admin(self, cid): + def delete_admin(self, user_id): """ Delete an admin from the 'admins' table. Parameters: - cid (int): The admin's chat ID. + user_id (int): The admin's chat ID. """ try: - self.cursor.execute("DELETE FROM `admins` WHERE `cid`=%s", (cid,)) + self.cursor.execute("DELETE FROM `admins` WHERE `user_id`=%s", (user_id,)) except mysql.connector.Error as err: logging.error(err) self.reconnect() @@ -592,18 +592,18 @@ def select_channels(self): logging.error(err) - def select_channels_add_cid(self, add_cid): + def select_channels_add_user_id(self, add_user_id): """ Select all channels added by a specific admin from the 'channels' table. Parameters: - add_cid (int): The chat ID of the admin who added the channels. + add_user_id (int): The chat ID of the admin who added the channels. Returns: list: A list of tuples containing the added channels' information. """ try: - self.cursor.execute("SELECT * FROM `channels` WHERE `add_cid`=%s", (add_cid,)) + self.cursor.execute("SELECT * FROM `channels` WHERE `add_user_id`=%s", (add_user_id,)) result = self.cursor.fetchall() return result except mysql.connector.Error as err: @@ -613,18 +613,18 @@ def select_channels_add_cid(self, add_cid): logging.error(err) - def check_channel(self, cid): + def check_channel(self, user_id): """ Check if a channel exists in the 'channels' table. Parameters: - cid (int): The channel's ID. + user_id (int): The channel's ID. Returns: tuple: The channel's information if it exists, None otherwise. """ try: - self.cursor.execute("SELECT * FROM `channels` WHERE `cid`=%s", (cid,)) + self.cursor.execute("SELECT * FROM `channels` WHERE `user_id`=%s", (user_id,)) result = self.cursor.fetchone() return result except mysql.connector.Error as err: @@ -657,15 +657,15 @@ def select_all_channel(self): ## -------------- Delete -------------- ## - def delete_channel(self, cid): + def delete_channel(self, user_id): """ Delete a channel from the 'channels' table. Parameters: - cid (int): The channel's ID. + user_id (int): The channel's ID. """ try: - self.cursor.execute("DELETE FROM `channels` WHERE `cid`=%s", (cid,)) + self.cursor.execute("DELETE FROM `channels` WHERE `channel_id`=%s", (user_id,)) except mysql.connector.Error as err: logging.error(err) self.reconnect() From f2ee7adc6389165e36eda2c050b82d301a788201 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Thu, 27 Feb 2025 15:21:46 +0500 Subject: [PATCH 05/71] Update .gitignore to exclude logs directory --- .gitignore | 2 +- utils/db_api/mysql_db.py => db/database.py | 84 +++++++++++----------- handlers/users/check_ban.py | 10 +-- handlers/users/check_join.py | 2 +- handlers/users/check_usr.py | 4 +- handlers/users/start.py | 6 +- loader.py | 2 +- 7 files changed, 55 insertions(+), 55 deletions(-) rename utils/db_api/mysql_db.py => db/database.py (87%) diff --git a/.gitignore b/.gitignore index 2a06190..96b745d 100755 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ /.idea/ /__pycache__/ /env/ -/db/ +/logs/ /build/ /.command* /.env diff --git a/utils/db_api/mysql_db.py b/db/database.py similarity index 87% rename from utils/db_api/mysql_db.py rename to db/database.py index 48203a8..1d91538 100755 --- a/utils/db_api/mysql_db.py +++ b/db/database.py @@ -83,11 +83,11 @@ def create_table_ban(self): try: sql = """ CREATE TABLE IF NOT EXISTS ban ( - id INT AUTO_INCREMENT PRIMARY KEY, - user_id bigint(20) NOT NULL UNIQUE, - admin_user_id bigint(20), - update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - date varchar(255) + `id` INT AUTO_INCREMENT PRIMARY KEY, + `user_id` bigint(200) NOT NULL UNIQUE, + `admin_user_id` bigint(200), + `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `date` DATE ) """ self.cursor.execute(sql) @@ -106,11 +106,11 @@ def create_table_users(self): try: sql = """ CREATE TABLE IF NOT EXISTS users ( - id INT AUTO_INCREMENT PRIMARY KEY, - user_id bigint(20) NOT NULL UNIQUE, - update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - date varchar(255), - lang varchar(5) + `id` INT AUTO_INCREMENT PRIMARY KEY, + `user_id` bigint(200) NOT NULL UNIQUE, + `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `date` DATE, + `language_code` varchar(5) ) """ self.cursor.execute(sql) @@ -128,12 +128,12 @@ def create_table_channel(self): """ try: sql = """ - CREATE TABLE IF NOT EXISTS channels ( - id INT AUTO_INCREMENT PRIMARY KEY, - channel_id bigint(200), - update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - date varchar(255), - add_user_id int(200) + CREATE TABLE IF NOT EXISTS `channels` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `channel_id` bigint(200), + `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `date` DATE, + `initiator_user_id` bigint(200) ); """ self.cursor.execute(sql) @@ -152,19 +152,19 @@ def create_table_admins(self): try: sql = """ CREATE TABLE IF NOT EXISTS admins ( - id INT AUTO_INCREMENT PRIMARY KEY, - user_id bigint(20) NOT NULL UNIQUE, - add_user_id bigint(20), - send_message TINYINT(1), - statistika TINYINT(1), - download_statistika TINYINT(1), - block_user TINYINT(1), - channel_settings TINYINT(1), - add_admin TINYINT(1), - set TINYINT(1), - get TINYINT(1), - update_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - date varchar(255) + `id` INT AUTO_INCREMENT PRIMARY KEY, + `user_id` bigint(200) NOT NULL UNIQUE, + `initiator_user_id` bigint(200), + `send_message` TINYINT(1), + `statistika` TINYINT(1), + `download_statistika` TINYINT(1), + `block_user` TINYINT(1), + `channel_settings` TINYINT(1), + `add_admin` TINYINT(1), + `set_data` TINYINT(1), + `get_data` TINYINT(1), + `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `date` DATE ); """ self.cursor.execute(sql) @@ -177,20 +177,20 @@ def create_table_admins(self): ## ------------------ Insert data ------------------ ## - def insert_user(self, user_id, date, lang): + def insert_user(self, user_id, date, language_code): """ Add a user to the 'users' table. Parameters: user_id (int): The user's chat ID. date (str): The date the user was added. - lang (str): The user's language preference. + language_code (str): The user's language_codeuage preference. """ try: sql = """ - INSERT INTO `users` (`user_id`,`date`,`lang`) VALUES (%s,%s,%s) + INSERT INTO `users` (`user_id`,`date`,`language_code`) VALUES (%s,%s,%s) """ - values = (user_id, date, lang) + values = (user_id, date, language_code) self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: @@ -200,20 +200,20 @@ def insert_user(self, user_id, date, lang): logging.error(err) - def insert_channel(self, user_id, date, add_user_id): + def insert_channel(self, user_id, date, initiator_user_id): """ Add a channel to the 'channels' table. Parameters: user_id (int): The channel's ID. date (str): The date the channel was added. - add_user_id (int): The chat ID of the admin who added the channel. + initiator_user_id (int): The chat ID of the admin who added the channel. """ try: sql = """ - INSERT INTO `channels` (`user_id`,`date`,`add_user_id`) VALUES (%s,%s,%s) + INSERT INTO `channels` (`user_id`,`date`,`initiator_user_id`) VALUES (%s,%s,%s) """ - values = (user_id, date, add_user_id) + values = (user_id, date, initiator_user_id) self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: @@ -234,7 +234,7 @@ def insert_admin(self, user_id, date, add): """ try: sql = """ - INSERT INTO `admins` (`user_id`,`add_user_id`,`date`) VALUES (%s,%s,%s) + INSERT INTO `admins` (`user_id`,`initiator_user_id`,`date`) VALUES (%s,%s,%s) """ values = (user_id, add, date) self.cursor.execute(sql, values) @@ -508,7 +508,7 @@ def select_add_admin(self, user_id): list: A list of tuples containing the added admins' information. """ try: - self.cursor.execute("SELECT * FROM `admins` WHERE `add_user_id`=%s", (user_id,)) + self.cursor.execute("SELECT * FROM `admins` WHERE `initiator_user_id`=%s", (user_id,)) result = self.cursor.fetchall() return result except mysql.connector.Error as err: @@ -592,18 +592,18 @@ def select_channels(self): logging.error(err) - def select_channels_add_user_id(self, add_user_id): + def select_channels_initiator_user_id(self, initiator_user_id): """ Select all channels added by a specific admin from the 'channels' table. Parameters: - add_user_id (int): The chat ID of the admin who added the channels. + initiator_user_id (int): The chat ID of the admin who added the channels. Returns: list: A list of tuples containing the added channels' information. """ try: - self.cursor.execute("SELECT * FROM `channels` WHERE `add_user_id`=%s", (add_user_id,)) + self.cursor.execute("SELECT * FROM `channels` WHERE `initiator_user_id`=%s", (initiator_user_id,)) result = self.cursor.fetchall() return result except mysql.connector.Error as err: diff --git a/handlers/users/check_ban.py b/handlers/users/check_ban.py index c6d9a57..520a619 100755 --- a/handlers/users/check_ban.py +++ b/handlers/users/check_ban.py @@ -21,14 +21,14 @@ async def ban_handler(msg: types.Message): try: # Get the user's language code and ID lang = msg.from_user.language_code - cid = msg.from_user.id + user_id = msg.from_user.id # Check if the user is banned and retrieve ban information - info = db.check_user_ban(cid=cid) + info = db.check_user_ban(user_id=user_id) logging.info(f"User ban info: {info}") # Retrieve admin information - admin_info = await bot.get_chat(chat_id=info[2]) + admin_info = await bot.get_chat(chat_id=info['admin_user_id']) admins = await bot.get_chat(chat_id=ADMIN) # Create the response message @@ -41,8 +41,8 @@ async def ban_handler(msg: types.Message): await msg.answer(text=f"{text}", reply_markup=close_btn()) # Add the user to the database if they are not already present - if db.check_user(cid=cid) is None: - db.insert_user(cid=cid, + if db.check_user(user_id=user_id) is None: + db.insert_user(user_id=user_id, date=f"{yil_oy_kun} / {soat_minut_sekund}") except Exception as err: diff --git a/handlers/users/check_join.py b/handlers/users/check_join.py index 47c9a44..1d510da 100755 --- a/handlers/users/check_join.py +++ b/handlers/users/check_join.py @@ -34,7 +34,7 @@ async def check_join(call: types.CallbackQuery): # Iterate through the channels for x in channels_list: - channel_id = str(-100) + str(x[1]) + channel_id = str(-100) + str(x['channel_id']) channel = await bot.get_chat(channel_id) try: diff --git a/handlers/users/check_usr.py b/handlers/users/check_usr.py index 9a38a46..a57cd97 100755 --- a/handlers/users/check_usr.py +++ b/handlers/users/check_usr.py @@ -34,7 +34,7 @@ async def start_handler(msg: types.Message): # Iterate through the channels for x in channels_list: - channel_id = str(-100) + str(x[1]) + channel_id = str(-100) + str(x['channel_id']) channel = await bot.get_chat(channel_id) try: @@ -93,7 +93,7 @@ async def start_callback_query(call: types.CallbackQuery): # Iterate through the channels for x in channels_list: - channel_id = str(-100) + str(x[1]) + channel_id = str(-100) + str(x['channel_id']) channel = await bot.get_chat(channel_id) try: diff --git a/handlers/users/start.py b/handlers/users/start.py index 1e54b7b..19015b1 100755 --- a/handlers/users/start.py +++ b/handlers/users/start.py @@ -35,7 +35,7 @@ async def start_handler(msg: types.Message): # Create the share button share_button = send_url(url=f'{sharing_message} https://t.me/{bot_username}?start', - lang=user_language) + language_code=user_language) # Translate and personalize the greeting text translated_greeting = translator(text=greeting_text, dest=user_language) @@ -44,8 +44,8 @@ async def start_handler(msg: types.Message): await msg.answer(translated_greeting, reply_markup=share_button) # Check and log the user if not already in the database - if db.check_user(cid=user_id) is None: - db.insert_user(cid=user_id, + if db.check_user(user_id) is None: + db.insert_user(user_id==user_id, date=f'{yil_oy_kun} / {soat_minut_sekund}', lang=user_language) except Exception as err: diff --git a/loader.py b/loader.py index ccef76c..b4dfdb5 100755 --- a/loader.py +++ b/loader.py @@ -3,7 +3,7 @@ from aiogram.fsm.storage.memory import MemoryStorage from aiogram.client.bot import DefaultBotProperties # Yangi versiyadagi default sozlamalar uchun from data.config import * # Konfiguratsiyalarni import qilamiz -from utils.db_api.mysql_db import Database +from db.database import Database from cython_code.file_db import BotDb, FileDB # Botni token va default parametr orqali yaratamiz From 6940d951f220a1c776cd0dff0bb549779852ba97 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Thu, 27 Feb 2025 15:25:34 +0500 Subject: [PATCH 06/71] Refactor user ID references from 'cid' to 'user_ud' in admin and user handlers for consistency --- cython_code/user_check.pyx | 8 +- filters/admin.py | 26 +++---- filters/ban.py | 8 +- handlers/admins/admin_settings/add_admin.py | 20 ++--- .../admin_settings/add_admin_first_step.py | 10 +-- .../admins/admin_settings/admin_setting.py | 10 +-- .../admins/admin_settings/attach_admins.py | 18 ++--- handlers/admins/admin_settings/edit_admin.py | 30 ++++---- .../admins/callback_query/main_admin_panel.py | 8 +- .../admins/channel_settings/add_channel.py | 6 +- .../channel_settings/channel_setting.py | 12 +-- .../admins/channel_settings/delete_channel.py | 22 +++--- handlers/admins/channel_settings/get_id.py | 14 ++-- .../channel_settings/mandatory_membership.py | 8 +- .../admins/channel_settings/remove_channel.py | 10 +-- handlers/admins/check_usr/attach_usr.py | 20 ++--- handlers/admins/check_usr/block_users.py | 22 +++--- handlers/admins/check_usr/check_usr.py | 2 +- handlers/admins/check_usr/send_ads_message.py | 2 +- handlers/admins/check_usr/send_message.py | 4 +- handlers/admins/main_panel.py | 8 +- handlers/admins/send_ads/get_message.py | 4 +- handlers/admins/send_ads/send_ads.py | 2 +- handlers/admins/send_ads/stop_ads.py | 2 +- .../admins/statistika/download_statistics.py | 8 +- handlers/admins/statistika/staristika.py | 4 +- handlers/admins/super_admin.py | 26 +++---- handlers/users/check_usr.py | 4 +- keyboards/inline/admin_btn.py | 76 +++++++++---------- keyboards/inline/button.py | 12 +-- middlewares/check_user.py | 8 +- 31 files changed, 207 insertions(+), 207 deletions(-) diff --git a/cython_code/user_check.pyx b/cython_code/user_check.pyx index 0673113..e274fcc 100644 --- a/cython_code/user_check.pyx +++ b/cython_code/user_check.pyx @@ -47,14 +47,14 @@ class User_Check(BaseFilter, BaseMiddleware): if data['join_channel']: try: # Try to get the user ID from the message object - cid = message.from_user.id + user_ud = message.from_user.id except Exception as err: # If message object is not available, use callback query object - cid = call.from_user.id + user_ud = call.from_user.id logging.error(err) # If the user is not the admin, perform the channel check - if cid != self.ADMIN: + if user_ud != self.ADMIN: force = False result = db.select_channels() for x in result: @@ -64,7 +64,7 @@ class User_Check(BaseFilter, BaseMiddleware): await bot.get_chat(ids) try: # Check the user's membership status in the channel - res = await bot.get_chat_member(chat_id=ids, user_id=cid) + res = await bot.get_chat_member(chat_id=ids, user_id=user_ud) except: # Continue if unable to retrieve chat member information continue diff --git a/filters/admin.py b/filters/admin.py index 7aafb27..bf756a5 100644 --- a/filters/admin.py +++ b/filters/admin.py @@ -53,9 +53,9 @@ async def __call__(self, message: Message) -> bool: Returns: bool: True if the user is an admin or the super admin, False otherwise. """ - self.cid = message.from_user.id - self.dada = db.select_admin(cid=self.cid) - if self.cid == ADMIN: + self.user_ud = message.from_user.id + self.dada = db.select_admin(user_ud=self.user_ud) + if self.user_ud == ADMIN: return True elif self.dada is not None: return True @@ -68,15 +68,15 @@ class SelectAdmin: Class to handle various admin-related actions. Attributes: - cid (int): The user ID. + user_ud (int): The user ID. super_admin (int): The ID of the super admin. dada (list): The admin details from the database. """ - def __init__(self, cid): - self.cid = cid + def __init__(self, user_ud): + self.user_ud = user_ud self.super_admin = ADMIN - self.dada = db.select_admin(cid=self.cid) + self.dada = db.select_admin(user_ud=self.user_ud) def send_message(self) -> bool: """ @@ -85,7 +85,7 @@ def send_message(self) -> bool: Returns: bool: True if the user can send messages, False otherwise. """ - if self.cid == self.super_admin: + if self.user_ud == self.super_admin: return True elif self.dada[3] == 1: return True @@ -99,7 +99,7 @@ def view_statistika(self) -> bool: Returns: bool: True if the user can view statistics, False otherwise. """ - if self.cid == self.super_admin: + if self.user_ud == self.super_admin: return True elif self.dada[4] == 1: return True @@ -113,7 +113,7 @@ def download_statistika(self) -> bool: Returns: bool: True if the user can download statistics, False otherwise. """ - if self.cid == self.super_admin: + if self.user_ud == self.super_admin: return True elif self.dada[5] == 1: return True @@ -127,7 +127,7 @@ def block_user(self) -> bool: Returns: bool: True if the user can block users, False otherwise. """ - if self.cid == self.super_admin: + if self.user_ud == self.super_admin: return True elif self.dada[6] == 1: return True @@ -141,7 +141,7 @@ def channel_settings(self) -> bool: Returns: bool: True if the user can change channel settings, False otherwise. """ - if self.cid == self.super_admin: + if self.user_ud == self.super_admin: return True elif self.dada[7] == 1: return True @@ -155,7 +155,7 @@ def add_admin(self) -> bool: Returns: bool: True if the user can add new admins, False otherwise. """ - if self.cid == self.super_admin: + if self.user_ud == self.super_admin: return True elif self.dada[8] == 1: return True diff --git a/filters/ban.py b/filters/ban.py index 437afd5..1fd1eb7 100644 --- a/filters/ban.py +++ b/filters/ban.py @@ -27,12 +27,12 @@ async def __call__(self, message: Message) -> bool: bool: True if the user is banned, False otherwise. """ try: - self.cid = message.from_user.id - self.dada = db.select_admin(cid=self.cid) - check_ban = db.check_user_ban(cid=self.cid) + self.user_ud = message.from_user.id + self.dada = db.select_admin(user_ud=self.user_ud) + check_ban = db.check_user_ban(user_ud=self.user_ud) # If the user is the super admin, they are not banned - if self.cid == self.super_admin: + if self.user_ud == self.super_admin: return False # If the user is an admin, they are not banned elif self.dada is not None: diff --git a/handlers/admins/admin_settings/add_admin.py b/handlers/admins/admin_settings/add_admin.py index 282d915..01a7291 100755 --- a/handlers/admins/admin_settings/add_admin.py +++ b/handlers/admins/admin_settings/add_admin.py @@ -19,7 +19,7 @@ async def add_admin(msg: types.Message, state: FSMContext): - state (FSMContext): The FSM context to manage the bot's state during the conversation. Functionality: - - Retrieves the admin's user ID (`cid`), the message ID (`mid`), and the language code (`lang`) from the message. + - Retrieves the admin's user ID (`user_ud`), the message ID (`mid`), and the language code (`lang`) from the message. - Checks if the sender has the required permissions to add an admin. - Tries to add the new admin using the provided user ID: - If the admin is successfully added, sends a confirmation message to both the current admin and the newly added admin. @@ -33,27 +33,27 @@ async def add_admin(msg: types.Message, state: FSMContext): - Catches and logs any exceptions that occur during the addition of the new admin or message editing. """ try: - cid = msg.from_user.id # The ID of the admin who is performing the action + user_ud = msg.from_user.id # The ID of the admin who is performing the action mid = msg.message_id # The ID of the message to be updated lang = msg.from_user.language_code # The language code for translation - data = SelectAdmin(cid=cid) # Retrieves admin settings for the current user + data = SelectAdmin(user_ud=user_ud) # Retrieves admin settings for the current user add_admin_db = data.add_admin() # Check if the user has the right to add an admin user_id = int(msg.text) # The ID of the user to be added as an admin if add_admin_db: data_state = await state.get_data() # Get current state data - btn = await admin_setting(cid=cid, lang=lang) # Prepare admin settings buttons + btn = await admin_setting(user_ud=user_ud, lang=lang) # Prepare admin settings buttons text = "🔴 Admin failed because admin was not found!\n" try: user = await bot.get_chat(chat_id=user_id) # Get user information - check = db.select_admin(cid=user_id) # Check if the user is already an admin + check = db.select_admin(user_ud=user_id) # Check if the user is already an admin if check is None: # Add the new admin to the database - db.insert_admin(cid=user_id, + db.insert_admin(user_ud=user_id, date=f"{yil_oy_kun} / {soat_minut_sekund}", - add=cid) + add=user_ud) text = translator(text="✅ Admin has been successfully added\n\nName: ", dest=lang) text += f"{user.full_name}\n" @@ -62,7 +62,7 @@ async def add_admin(msg: types.Message, state: FSMContext): text=f'😊Hi @{user.username}, you have been made an admin\n' f'To open the panel, use /admin ', reply_markup=close_btn()) - btn = await admin_setting(cid=cid, lang=lang) # Prepare admin settings buttons + btn = await admin_setting(user_ud=user_ud, lang=lang) # Prepare admin settings buttons else: text = translator(text="✅ Admin was added before\n\nName: ", dest=lang) @@ -81,7 +81,7 @@ async def add_admin(msg: types.Message, state: FSMContext): finally: text = translator(text=text, dest=lang) - await bot.edit_message_text(chat_id=cid, + await bot.edit_message_text(chat_id=user_ud, message_id=data_state['message_id'], text=text, reply_markup=btn) @@ -89,7 +89,7 @@ async def add_admin(msg: types.Message, state: FSMContext): text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) btn = close_btn() - await bot.edit_message_text(chat_id=cid, + await bot.edit_message_text(chat_id=user_ud, message_id=mid, text=f"{text}", reply_markup=btn) diff --git a/handlers/admins/admin_settings/add_admin_first_step.py b/handlers/admins/admin_settings/add_admin_first_step.py index 9560ee0..67e00c3 100755 --- a/handlers/admins/admin_settings/add_admin_first_step.py +++ b/handlers/admins/admin_settings/add_admin_first_step.py @@ -19,7 +19,7 @@ async def add_admin_first(call: types.CallbackQuery, state: FSMContext): - state (FSMContext): The FSM context to manage the bot's state during the conversation. Functionality: - - Retrieves the ID of the admin who initiated the request (`cid`), the message ID (`mid`), and the language code (`lang`). + - Retrieves the ID of the admin who initiated the request (`user_ud`), the message ID (`mid`), and the language code (`lang`). - Checks if the requesting admin has the rights to add a new admin. - If the requesting admin has the necessary permissions, prompts them to send the ID of the new admin to be added. - Sets the state to `AdminState.add_admin` to handle the next step of the process. @@ -33,16 +33,16 @@ async def add_admin_first(call: types.CallbackQuery, state: FSMContext): - Catches and logs any exceptions that occur during the process of handling the callback query or updating the message. """ try: - cid = call.from_user.id # ID of the admin initiating the request + user_ud = call.from_user.id # ID of the admin initiating the request mid = call.message.message_id # ID of the message to be updated lang = call.from_user.language_code # Language code for translation - data = SelectAdmin(cid=cid) # Retrieves admin settings for the current user + data = SelectAdmin(user_ud=user_ud) # Retrieves admin settings for the current user add_admin = data.add_admin() # Checks if the user has the right to add an admin if add_admin: # Prompt the user to provide the ID of the new admin text = translator(text="🔰 Please send the admin ID number you want to add...", dest=lang) - btn = await admin_setting(cid=cid, lang=lang) # Prepare admin settings buttons + btn = await admin_setting(user_ud=user_ud, lang=lang) # Prepare admin settings buttons await state.set_state(AdminState.add_admin) # Set the FSM state for adding an admin else: # Inform the user that they do not have the necessary permissions @@ -50,7 +50,7 @@ async def add_admin_first(call: types.CallbackQuery, state: FSMContext): btn = close_btn() # Prepare close button # Update the message with the appropriate response and buttons - await bot.edit_message_text(chat_id=cid, + await bot.edit_message_text(chat_id=user_ud, message_id=mid, text=f'{text}', reply_markup=btn) diff --git a/handlers/admins/admin_settings/admin_setting.py b/handlers/admins/admin_settings/admin_setting.py index 3381271..cb422a5 100755 --- a/handlers/admins/admin_settings/admin_setting.py +++ b/handlers/admins/admin_settings/admin_setting.py @@ -18,7 +18,7 @@ async def admin_settings(call: types.CallbackQuery, state: FSMContext): - state (FSMContext): The FSM context to manage the bot's state during the conversation. Functionality: - - Retrieves the ID of the admin (`cid`), the message ID (`mid`), and the language code (`lang`). + - Retrieves the ID of the admin (`user_ud`), the message ID (`mid`), and the language code (`lang`). - Checks if the admin has the permissions to access the Admin settings. - If permissions are granted, presents the admin with the settings options. - If permissions are denied, informs the admin that they lack the necessary rights. @@ -31,23 +31,23 @@ async def admin_settings(call: types.CallbackQuery, state: FSMContext): - Catches and logs any exceptions that occur during the process of handling the callback query or updating the message. """ try: - cid = call.from_user.id # ID of the admin initiating the request + user_ud = call.from_user.id # ID of the admin initiating the request mid = call.message.message_id # ID of the message to be updated lang = call.from_user.language_code # Language code for translation - data = SelectAdmin(cid=cid) # Retrieves admin settings for the current user + data = SelectAdmin(user_ud=user_ud) # Retrieves admin settings for the current user add_admin = data.add_admin() # Checks if the user has the right to access admin settings if add_admin: # The admin has the right to access settings text = translator(text="❗ You are in the Admin settings section!", dest=lang) - btn = await admin_setting(cid=cid, lang=lang) # Prepare admin settings buttons + btn = await admin_setting(user_ud=user_ud, lang=lang) # Prepare admin settings buttons else: # The admin does not have the necessary rights text = translator(text="❌ Unfortunately, you do not have this right!", dest=lang) btn = close_btn() # Prepare close button # Update the message with the appropriate response and buttons - await bot.edit_message_text(chat_id=cid, + await bot.edit_message_text(chat_id=user_ud, message_id=mid, text=f'{text}', reply_markup=btn) diff --git a/handlers/admins/admin_settings/attach_admins.py b/handlers/admins/admin_settings/attach_admins.py index 80d311d..cd14353 100755 --- a/handlers/admins/admin_settings/attach_admins.py +++ b/handlers/admins/admin_settings/attach_admins.py @@ -23,7 +23,7 @@ async def attach_admins(call: types.CallbackQuery, callback_data: AdminSetting, - state (FSMContext): The FSM context for managing the bot's conversation state. Functionality: - - Extracts the admin's ID (`cid`), message ID (`mid`), language code (`lang`), and the target admin ID (`admin_cid`). + - Extracts the admin's ID (`user_ud`), message ID (`mid`), language code (`lang`), and the target admin ID (`admin_user_ud`). - Checks if the current admin has the right to modify admin settings. - If permitted, fetches the target admin's data and checks the permissions of the current admin. - Constructs a response message detailing the target admin's rights. @@ -37,20 +37,20 @@ async def attach_admins(call: types.CallbackQuery, callback_data: AdminSetting, - Catches and logs any exceptions that occur during the execution of the function. """ try: - cid = call.from_user.id # Current admin's ID + user_ud = call.from_user.id # Current admin's ID mid = call.message.message_id # Message ID to be updated lang = call.from_user.language_code # Admin's language preference - admin_cid = callback_data.cid # ID of the admin to be modified - data = SelectAdmin(cid=cid) # Fetches the current admin's data + admin_user_ud = callback_data.user_ud # ID of the admin to be modified + data = SelectAdmin(user_ud=user_ud) # Fetches the current admin's data btn = close_btn() # Default button to close the operation # Check if the admin has rights to add another admin if data.add_admin(): - admin_data = db.select_admin(cid=admin_cid) # Fetch data for the target admin - if admin_data[2] == cid or cid == ADMIN: + admin_data = db.select_admin(user_ud=admin_user_ud) # Fetch data for the target admin + if admin_data[2] == user_ud or user_ud == ADMIN: # If the current admin added the target admin or is the primary admin - btn = attach_admin_btn(cid=admin_cid, lang=lang) # Buttons for setting admin rights - is_admin = SelectAdmin(cid=admin_cid) # Check target admin's permissions + btn = attach_admin_btn(user_ud=admin_user_ud, lang=lang) # Buttons for setting admin rights + is_admin = SelectAdmin(user_ud=admin_user_ud) # Check target admin's permissions # Format the text showing current permissions of the target admin send_message_tx = x_or_y(is_admin.send_message()) @@ -76,7 +76,7 @@ async def attach_admins(call: types.CallbackQuery, callback_data: AdminSetting, text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) # Update the message with the admin rights information or error message - await bot.edit_message_text(chat_id=cid, message_id=mid, text=f'{text}', reply_markup=btn) + await bot.edit_message_text(chat_id=user_ud, message_id=mid, text=f'{text}', reply_markup=btn) await state.set_state(AdminState.add_admin) # Set the state to add admin await state.update_data({"message_id": call.message.message_id}) # Update the state data with the message ID except Exception as err: diff --git a/handlers/admins/admin_settings/edit_admin.py b/handlers/admins/admin_settings/edit_admin.py index e8c7ff4..518d17c 100755 --- a/handlers/admins/admin_settings/edit_admin.py +++ b/handlers/admins/admin_settings/edit_admin.py @@ -23,7 +23,7 @@ async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, - state (FSMContext): The FSM context for managing the bot's conversation state. Functionality: - - Extracts the current admin's ID (`cid`), message ID (`mid`), language code (`lang`), target admin ID (`admin_cid`), and the key to be edited (`edit_key`). + - Extracts the current admin's ID (`user_ud`), message ID (`mid`), language code (`lang`), target admin ID (`admin_user_ud`), and the key to be edited (`edit_key`). - Checks if the current admin has the right to modify admin settings. - If permitted, fetches the target admin's data. - Depending on the edit key, either deletes the target admin or updates a specific admin permission. @@ -38,35 +38,35 @@ async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, - Catches and logs any exceptions that occur during the execution of the function. """ try: - cid = call.from_user.id # Current admin's ID + user_ud = call.from_user.id # Current admin's ID mid = call.message.message_id # Message ID to be updated lang = call.from_user.language_code # Admin's language preference - admin_cid = callback_data.cid # ID of the target admin to be modified + admin_user_ud = callback_data.user_ud # ID of the target admin to be modified edit_key = callback_data.data # The key indicating what action to perform - data = SelectAdmin(cid=cid) # Fetches the current admin's data + data = SelectAdmin(user_ud=user_ud) # Fetches the current admin's data add_admin = data.add_admin() # Checks if the current admin can add admins btn = close_btn() # Default button to close the operation # Check if the admin has rights to add another admin if add_admin: - admin_data = db.select_admin(cid=admin_cid) # Fetch data for the target admin + admin_data = db.select_admin(user_ud=admin_user_ud) # Fetch data for the target admin if admin_data is None: - text = f'⛔{admin_cid} {translator(text="😪 Not available in admin list!", dest=lang)}' + text = f'⛔{admin_user_ud} {translator(text="😪 Not available in admin list!", dest=lang)}' else: - if admin_data[2] == cid or cid == ADMIN: + if admin_data[2] == user_ud or user_ud == ADMIN: if edit_key == "delete_admin": # If the edit action is to delete the admin - db.delete_admin(cid=admin_cid) - admin_info = await bot.get_chat(chat_id=admin_cid) + db.delete_admin(user_ud=admin_user_ud) + admin_info = await bot.get_chat(chat_id=admin_user_ud) text = f'🔪 @{admin_info.username} {translator(text="✅ Removed from admin!", dest=lang)}' - await bot.send_message(chat_id=admin_cid, text='😪 Your admin rights have been revoked!') + await bot.send_message(chat_id=admin_user_ud, text='😪 Your admin rights have been revoked!') else: # Update the specific admin permission - select_column = db.select_admin_column(cid=admin_cid, column=edit_key) + select_column = db.select_admin_column(user_ud=admin_user_ud, column=edit_key) new_value = 0 if select_column[0] == 1 else 1 - db.update_admin_data(cid=admin_cid, column=edit_key, value=new_value) - btn = attach_admin_btn(cid=admin_cid, lang=lang) - is_admin = SelectAdmin(cid=admin_cid) + db.update_admin_data(user_ud=admin_user_ud, column=edit_key, value=new_value) + btn = attach_admin_btn(user_ud=admin_user_ud, lang=lang) + is_admin = SelectAdmin(user_ud=admin_user_ud) send_message_tx = x_or_y(is_admin.send_message()) view_statistika_tx = x_or_y(is_admin.view_statistika()) download_statistika_tx = x_or_y(is_admin.download_statistika()) @@ -88,7 +88,7 @@ async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) # Update the message with the admin rights information or error message - await bot.edit_message_text(chat_id=cid, message_id=mid, text=f"{text}", reply_markup=btn) + await bot.edit_message_text(chat_id=user_ud, message_id=mid, text=f"{text}", reply_markup=btn) await state.set_state(AdminState.add_admin) # Set the state to add admin await state.update_data({"message_id": call.message.message_id}) # Update the state data with the message ID except Exception as err: diff --git a/handlers/admins/callback_query/main_admin_panel.py b/handlers/admins/callback_query/main_admin_panel.py index e9060e8..ac1b392 100755 --- a/handlers/admins/callback_query/main_admin_panel.py +++ b/handlers/admins/callback_query/main_admin_panel.py @@ -18,7 +18,7 @@ async def main_panel(call: types.CallbackQuery, state: FSMContext): - state (FSMContext): The FSM context to manage the bot's state during the conversation. Functionality: - - Retrieves the admin's user ID (`cid`), the message ID (`mid`), and the language code (`lang`) from the callback query. + - Retrieves the admin's user ID (`user_ud`), the message ID (`mid`), and the language code (`lang`) from the callback query. - Translates a greeting message to the admin in their preferred language. - Edits the original message in the chat to display the translated greeting and the main admin panel buttons. - Updates the FSM state with the current message ID. @@ -30,7 +30,7 @@ async def main_panel(call: types.CallbackQuery, state: FSMContext): - Catches and logs any exceptions that occur during the execution, ensuring that errors are recorded for debugging. """ try: - cid = call.from_user.id # The ID of the admin who initiated the action + user_ud = call.from_user.id # The ID of the admin who initiated the action mid = call.message.message_id # The ID of the message to be updated lang = call.from_user.language_code # The language code for translation @@ -38,10 +38,10 @@ async def main_panel(call: types.CallbackQuery, state: FSMContext): text = translator(text="👩‍💻Hello, dear admin, welcome to the main panel!", dest=lang) # Edit the message with the translated text and update it with the main admin panel buttons - await bot.edit_message_text(chat_id=cid, + await bot.edit_message_text(chat_id=user_ud, message_id=mid, text=f'{text}', - reply_markup=main_admin_panel_btn(cid=cid, lang=lang)) + reply_markup=main_admin_panel_btn(user_ud=user_ud, lang=lang)) # Update FSM state with the current message ID await state.update_data({"message_id": call.message.message_id}) diff --git a/handlers/admins/channel_settings/add_channel.py b/handlers/admins/channel_settings/add_channel.py index 06c67d7..3f05b92 100755 --- a/handlers/admins/channel_settings/add_channel.py +++ b/handlers/admins/channel_settings/add_channel.py @@ -29,10 +29,10 @@ async def add_channel(call: types.CallbackQuery, state: FSMContext): - This function is asynchronous and does not return a value but performs actions such as sending messages and updating states. """ try: - cid = call.from_user.id # The ID of the admin initiating the action + user_ud = call.from_user.id # The ID of the admin initiating the action mid = call.message.message_id # The ID of the message triggering the callback lang = call.from_user.language_code # The language code of the admin for message translation - data = SelectAdmin(cid=cid) # Check if the admin has permission to manage channel settings + data = SelectAdmin(user_ud=user_ud) # Check if the admin has permission to manage channel settings btn = close_btn() # Inline button to close the message if data.channel_settings(): @@ -45,7 +45,7 @@ async def add_channel(call: types.CallbackQuery, state: FSMContext): text = translator(text="❌ Unfortunately, you do not have this right!", dest=lang) await bot.edit_message_text( - chat_id=cid, + chat_id=user_ud, message_id=mid, text=f'{text}', reply_markup=btn # Update the message with a translated response diff --git a/handlers/admins/channel_settings/channel_setting.py b/handlers/admins/channel_settings/channel_setting.py index da28346..5e71efa 100755 --- a/handlers/admins/channel_settings/channel_setting.py +++ b/handlers/admins/channel_settings/channel_setting.py @@ -32,19 +32,19 @@ async def channel_setting(call: types.CallbackQuery, state: FSMContext): - This function is asynchronous and does not return a value but performs actions such as sending messages and updating states. """ try: - cid = call.from_user.id # The ID of the admin initiating the action + user_ud = call.from_user.id # The ID of the admin initiating the action mid = call.message.message_id # The ID of the message triggering the callback lang = call.from_user.language_code # The language code of the admin for message translation - data = SelectAdmin(cid=cid) # Check if the admin has permission to manage channel settings + data = SelectAdmin(user_ud=user_ud) # Check if the admin has permission to manage channel settings btn = close_btn() # Inline button to close the message if data.channel_settings(): - if cid == ADMIN: + if user_ud == ADMIN: # Retrieve all channels if the admin is the main ADMIN data = db.select_channels() else: # Retrieve channels added by the current admin - data = db.select_channels_add_cid(add_cid=cid) + data = db.select_channels_add_user_ud(add_user_ud=user_ud) if not data: # If no channels are found, indicate that the list is empty @@ -61,7 +61,7 @@ async def channel_setting(call: types.CallbackQuery, state: FSMContext): text += (f"{count}. Name: {channel.full_name}\n" f"Username: @{channel.username}\n" f"Added date: {x[2]}\n" - f"Added by CID: {x[3]}\n\n") + f"Added by user_ud: {x[3]}\n\n") except Exception as err: logging.error(err) # Log any errors in retrieving channel details btn = channel_settings(lang=lang) # Button for channel settings @@ -70,7 +70,7 @@ async def channel_setting(call: types.CallbackQuery, state: FSMContext): text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) await bot.edit_message_text( - chat_id=cid, + chat_id=user_ud, message_id=mid, text=f'{text}', reply_markup=btn # Update the message with a translated response and appropriate buttons diff --git a/handlers/admins/channel_settings/delete_channel.py b/handlers/admins/channel_settings/delete_channel.py index 70acb8d..a809ba6 100755 --- a/handlers/admins/channel_settings/delete_channel.py +++ b/handlers/admins/channel_settings/delete_channel.py @@ -19,7 +19,7 @@ async def delete_channel(call: types.CallbackQuery, callback_data: AdminCallback - state (FSMContext): FSM context used to manage the bot's state for the current conversation. Functionality: - - Retrieves the admin's user ID (`cid`), the message ID (`mid`), and the language code (`lang`) from the callback query. + - Retrieves the admin's user ID (`user_ud`), the message ID (`mid`), and the language code (`lang`) from the callback query. - Checks if the user has the necessary permissions to manage channel settings using the `SelectAdmin` filter. - If authorized, retrieves the channel ID from `callback_data`, formats it, and checks its existence in the database. - If the channel exists and the user is authorized, deletes the channel from the database and notifies the user. @@ -31,16 +31,16 @@ async def delete_channel(call: types.CallbackQuery, callback_data: AdminCallback - This function is asynchronous and does not return a value. It interacts with the Telegram API to send and edit messages. """ try: - cid = call.from_user.id # The ID of the admin making the request + user_ud = call.from_user.id # The ID of the admin making the request mid = call.message.message_id # The ID of the message associated with the callback lang = call.from_user.language_code # The language code for translating responses - data = SelectAdmin(cid=cid) # Check if the user has admin permissions + data = SelectAdmin(user_ud=user_ud) # Check if the user has admin permissions btn = close_btn() # A button for closing the message if data.channel_settings(): - ch_cid = callback_data.data # Channel ID from the callback data - ch_cid100 = str(-100) + str(ch_cid) # Format channel ID for API - check = db.check_channel(cid=ch_cid) # Check if the channel exists in the database + ch_user_ud = callback_data.data # Channel ID from the callback data + ch_user_ud100 = str(-100) + str(ch_user_ud) # Format channel ID for API + check = db.check_channel(user_ud=ch_user_ud) # Check if the channel exists in the database if not check: # Inform the user if the channel does not exist @@ -49,16 +49,16 @@ async def delete_channel(call: types.CallbackQuery, callback_data: AdminCallback dest=lang) else: # Get channel details using the Telegram API - channel = await bot.get_chat(chat_id=ch_cid100) + channel = await bot.get_chat(chat_id=ch_user_ud100) - if check[3] == cid or cid == ADMIN: + if check[3] == user_ud or user_ud == ADMIN: # Delete the channel if the user is authorized - db.delete_channel(cid=ch_cid) + db.delete_channel(user_ud=ch_user_ud) tx = translator(text='🚫 Channel removed...\n', dest=lang) text = (f"{tx}\n" f"Name: {channel.full_name}\n" f"Username: @{channel.username}\n" - f"ID: {ch_cid}\n\n") + f"ID: {ch_user_ud}\n\n") else: # Inform the user if they do not have permission to delete the channel text = translator(text='⭕ Only an admin can delete this channel.', dest=lang) @@ -66,7 +66,7 @@ async def delete_channel(call: types.CallbackQuery, callback_data: AdminCallback # Inform the user if they lack the necessary permissions text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) - await bot.edit_message_text(chat_id=cid, + await bot.edit_message_text(chat_id=user_ud, message_id=mid, text=f'{text}', reply_markup=btn) # Send or edit the message with the result diff --git a/handlers/admins/channel_settings/get_id.py b/handlers/admins/channel_settings/get_id.py index 21d628e..9afac39 100755 --- a/handlers/admins/channel_settings/get_id.py +++ b/handlers/admins/channel_settings/get_id.py @@ -19,7 +19,7 @@ async def add_channel2(msg: types.Message, state: FSMContext): - state (FSMContext): FSM context used to manage the bot's state for the current conversation. Functionality: - - Retrieves the admin's user ID (`cid`), the message ID (`mid`), and the language code (`lang`) from the message. + - Retrieves the admin's user ID (`user_ud`), the message ID (`mid`), and the language code (`lang`) from the message. - Checks if the user has the necessary permissions to manage channel settings using the `SelectAdmin` filter. - If authorized, attempts to convert the input text into a channel ID, checks if the channel is already in the database, and adds it if not. - If the channel is already in the database, provides details about the existing entry. @@ -31,10 +31,10 @@ async def add_channel2(msg: types.Message, state: FSMContext): - This function is asynchronous and does not return a value. It interacts with the Telegram API to send and edit messages. """ try: - cid = msg.from_user.id # The ID of the admin making the request + user_ud = msg.from_user.id # The ID of the admin making the request mid = msg.message_id # The ID of the message associated with the request lang = msg.from_user.language_code # The language code for translating responses - data = SelectAdmin(cid=cid) # Check if the user has admin permissions + data = SelectAdmin(user_ud=user_ud) # Check if the user has admin permissions btn = close_btn() # A button for closing the message data_state = await state.get_data() # Get data stored in the FSM state @@ -43,13 +43,13 @@ async def add_channel2(msg: types.Message, state: FSMContext): tx = msg.text # The text message containing the channel ID k_id = int(str(-100) + str(tx)) # Format the channel ID for API channel = await bot.get_chat(chat_id=k_id) # Get channel details using the Telegram API - check = db.check_channel(cid=tx) # Check if the channel is already in the database + check = db.check_channel(user_ud=tx) # Check if the channel is already in the database if check is None: # Add the channel to the database if it doesn't exist - db.insert_channel(cid=tx, + db.insert_channel(user_ud=tx, date=f'{yil_oy_kun} / {soat_minut_sekund}', - add_cid=cid) + add_user_ud=user_ud) text = translator(text="✅ The channel was successfully added\n", dest=lang) text += f"Name: {channel.full_name}\n" \ f"Username: @{channel.username}" @@ -71,7 +71,7 @@ async def add_channel2(msg: types.Message, state: FSMContext): text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) # Update the message with the result and close button - await bot.edit_message_text(chat_id=cid, + await bot.edit_message_text(chat_id=user_ud, message_id=data_state['message_id'], text=f'{text}', reply_markup=btn) diff --git a/handlers/admins/channel_settings/mandatory_membership.py b/handlers/admins/channel_settings/mandatory_membership.py index f897a38..788e657 100755 --- a/handlers/admins/channel_settings/mandatory_membership.py +++ b/handlers/admins/channel_settings/mandatory_membership.py @@ -18,7 +18,7 @@ async def mandatory_membership(call: types.CallbackQuery, state: FSMContext): - state (FSMContext): The FSM context to manage the bot's state during the conversation. Functionality: - - Retrieves the admin's user ID (`cid`), the message ID (`mid`), and the language code (`lang`) from the callback query. + - Retrieves the admin's user ID (`user_ud`), the message ID (`mid`), and the language code (`lang`) from the callback query. - Checks if the user has the required permissions to modify channel settings using the `SelectAdmin` filter. - If authorized, reads the current mandatory membership status from the database. - Toggles the membership requirement status: @@ -32,10 +32,10 @@ async def mandatory_membership(call: types.CallbackQuery, state: FSMContext): - This function is asynchronous and does not return a value. It interacts with the Telegram API to update messages and with the database to modify settings. """ try: - cid = call.from_user.id # The ID of the admin who initiated the action + user_ud = call.from_user.id # The ID of the admin who initiated the action mid = call.message.message_id # The ID of the message to be updated lang = call.from_user.language_code # The language code for translation - data = SelectAdmin(cid=cid) # Check if the user has admin permissions + data = SelectAdmin(user_ud=user_ud) # Check if the user has admin permissions btn = close_btn() # Create a button for closing the message if data.channel_settings(): @@ -57,7 +57,7 @@ async def mandatory_membership(call: types.CallbackQuery, state: FSMContext): text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) # Edit the message with the new status and close button - await bot.edit_message_text(chat_id=cid, + await bot.edit_message_text(chat_id=user_ud, message_id=mid, text=f'{text}', reply_markup=btn) diff --git a/handlers/admins/channel_settings/remove_channel.py b/handlers/admins/channel_settings/remove_channel.py index a012a53..a5623fe 100755 --- a/handlers/admins/channel_settings/remove_channel.py +++ b/handlers/admins/channel_settings/remove_channel.py @@ -20,7 +20,7 @@ async def remove_channel(call: types.CallbackQuery, state: FSMContext): - state (FSMContext): The FSM context to manage the bot's state during the conversation. Functionality: - - Retrieves the admin's user ID (`cid`), the message ID (`mid`), and the language code (`lang`) from the callback query. + - Retrieves the admin's user ID (`user_ud`), the message ID (`mid`), and the language code (`lang`) from the callback query. - Checks if the user has the necessary permissions to access channel settings using the `SelectAdmin` filter. - If authorized, retrieves the list of channels either for all admins (if the user is the main admin) or for channels added by the specific admin. - If the channel list is empty, informs the admin. If not, displays a list of channels with options to delete them. @@ -31,10 +31,10 @@ async def remove_channel(call: types.CallbackQuery, state: FSMContext): - This function is asynchronous and does not return a value. It interacts with the Telegram API to update messages and with the database to retrieve channel information. """ try: - cid = call.from_user.id # The ID of the admin who initiated the action + user_ud = call.from_user.id # The ID of the admin who initiated the action mid = call.message.message_id # The ID of the message to be updated lang = call.from_user.language_code # The language code for translation - data = SelectAdmin(cid=cid) # Check if the user has admin permissions + data = SelectAdmin(user_ud=user_ud) # Check if the user has admin permissions btn = InlineKeyboardBuilder() # Create an instance of InlineKeyboardBuilder for the keyboard # Attach the main button to the keyboard @@ -42,10 +42,10 @@ async def remove_channel(call: types.CallbackQuery, state: FSMContext): if data.channel_settings(): # Retrieve the list of channels based on admin permissions - if cid == ADMIN: + if user_ud == ADMIN: data = db.select_channels() else: - data = db.select_channels_add_cid(add_cid=cid) + data = db.select_channels_add_user_ud(add_user_ud=user_ud) if not data: # Inform the admin if no channels are available diff --git a/handlers/admins/check_usr/attach_usr.py b/handlers/admins/check_usr/attach_usr.py index 7f86f32..17f50eb 100755 --- a/handlers/admins/check_usr/attach_usr.py +++ b/handlers/admins/check_usr/attach_usr.py @@ -31,10 +31,10 @@ async def attach_user(msg: types.Message, state: FSMContext): None """ try: - cid = msg.from_user.id # Chat ID of the admin + user_ud = msg.from_user.id # Chat ID of the admin mid = msg.message_id # Message ID of the current message lang = msg.from_user.language_code # Language code of the admin - is_admin = SelectAdmin(cid=cid) # Check admin permissions + is_admin = SelectAdmin(user_ud=user_ud) # Check admin permissions user_id = int(msg.text) # Extract user ID from the message btn = close_btn() # Initialize the close button text = translator(text="🔴 Something went wrong!\n", dest=lang) # Default error message @@ -43,14 +43,14 @@ async def attach_user(msg: types.Message, state: FSMContext): data_state = await state.get_data() # Get the current state data try: user = await bot.get_chat(chat_id=user_id) # Get user information - check = db.check_user_ban(cid=user_id) # Check if the user is banned - check1 = db.check_user(cid=user_id) # Check if the user exists in the bot's list + check = db.check_user_ban(user_ud=user_id) # Check if the user is banned + check1 = db.check_user(user_ud=user_id) # Check if the user exists in the bot's list if check1 is not None: - btn = block_user(cid=cid, user_id=user_id, lang=lang) # Button for blocking/unblocking user + btn = block_user(user_ud=user_ud, user_id=user_id, lang=lang) # Button for blocking/unblocking user if check is None: - check2 = db.select_admin(cid=user_id) # Check if the user is an admin - select_user = db.check_user(cid) # Get information about the user + check2 = db.select_admin(user_ud=user_id) # Check if the user is an admin + select_user = db.check_user(user_ud) # Get information about the user if check2 is None: # User is successfully unblocked @@ -74,7 +74,7 @@ async def attach_user(msg: types.Message, state: FSMContext): text = translator(text="🔴 User not found!\nThe bot may not have found the user..", dest=lang) finally: # Update the message with the result and provide the close button - await bot.edit_message_text(chat_id=cid, + await bot.edit_message_text(chat_id=user_ud, message_id=data_state['message_id'], text=f'{text}', reply_markup=btn) @@ -83,12 +83,12 @@ async def attach_user(msg: types.Message, state: FSMContext): text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) # Edit the original message to reflect the result - await bot.edit_message_text(chat_id=cid, + await bot.edit_message_text(chat_id=user_ud, message_id=mid, text=f'{text}', reply_markup=btn) await state.update_data({"message_id": mid}) # Update state data - await bot.delete_message(chat_id=cid, message_id=mid) # Delete the original message + await bot.delete_message(chat_id=user_ud, message_id=mid) # Delete the original message except Exception as err: # Log any exceptions that occur logging.error(err) diff --git a/handlers/admins/check_usr/block_users.py b/handlers/admins/check_usr/block_users.py index 098b7e2..756a84b 100755 --- a/handlers/admins/check_usr/block_users.py +++ b/handlers/admins/check_usr/block_users.py @@ -35,21 +35,21 @@ async def block_users(call: types.CallbackQuery, callback_data: BlockUser, state - This function is asynchronous and does not return a value but performs actions such as sending messages and updating states. """ try: - user_id = callback_data.cid # The ID of the user to be blocked/unblocked - cid = call.from_user.id # The ID of the admin issuing the block/unblock command + user_id = callback_data.user_ud # The ID of the user to be blocked/unblocked + user_ud = call.from_user.id # The ID of the admin issuing the block/unblock command mid = call.message.message_id # The ID of the message triggering the callback lang = call.from_user.language_code # The language code of the admin for message translation - data = SelectAdmin(cid=cid) # Check if the admin is authorized to perform the action + data = SelectAdmin(user_ud=user_ud) # Check if the admin is authorized to perform the action btn = close_btn() # Inline button to close the message if data.block_user(): - check1 = db.select_admin(cid=user_id) # Check if the user is an admin + check1 = db.select_admin(user_ud=user_id) # Check if the user is an admin if check1 is None: - check = db.check_user_ban(cid=user_id) # Check if the user is already banned + check = db.check_user_ban(user_ud=user_id) # Check if the user is already banned user = await bot.get_chat(chat_id=user_id) # Get user details if check is None: - db.insert_user_ban(cid=user_id, - admin_cid=cid, + db.insert_user_ban(user_ud=user_id, + admin_user_ud=user_ud, date=f'{yil_oy_kun} / {soat_minut_sekund}') # Add user to ban list text = translator(text='⛔ User blocked\n\n Username: @', dest=lang) text += str(user.username) @@ -57,8 +57,8 @@ async def block_users(call: types.CallbackQuery, callback_data: BlockUser, state text='🚫 You are blocked! If you think this is a mistake, contact the admin.', reply_markup=close_btn()) # Notify the user of the block else: - if check[2] == cid or cid == ADMIN: # Check if the unblocking is authorized - db.delete_user_ban(cid=user_id) # Remove user from ban list + if check[2] == user_ud or user_ud == ADMIN: # Check if the unblocking is authorized + db.delete_user_ban(user_ud=user_id) # Remove user from ban list text = translator(text='✅ User unblocked!\n\n Username: @', dest=lang) text += str(user.username) await bot.send_message(chat_id=user_id, @@ -70,13 +70,13 @@ async def block_users(call: types.CallbackQuery, callback_data: BlockUser, state else: text = translator(text='🚫 I cannot block an admin.', dest=lang) try: - db.delete_user_ban(cid=user_id) # Ensure user is not mistakenly banned + db.delete_user_ban(user_ud=user_id) # Ensure user is not mistakenly banned except Exception as err: logging.error(err) # Log any errors encountered await state.set_state(AdminState.check_user) # Update the FSM state else: text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) - await bot.edit_message_text(chat_id=cid, + await bot.edit_message_text(chat_id=user_ud, message_id=mid, text=f'{text}', reply_markup=btn) # Edit the original message with the result diff --git a/handlers/admins/check_usr/check_usr.py b/handlers/admins/check_usr/check_usr.py index d79c7f2..8cacf0a 100755 --- a/handlers/admins/check_usr/check_usr.py +++ b/handlers/admins/check_usr/check_usr.py @@ -33,7 +33,7 @@ async def check_user(call: types.CallbackQuery, state: FSMContext): user_id = call.from_user.id # The ID of the admin initiating the check message_id = call.message.message_id # The ID of the message triggering the callback language = call.from_user.language_code # The language code of the admin for message translation - data = SelectAdmin(cid=user_id) # Check if the admin is authorized to perform the action + data = SelectAdmin(user_ud=user_id) # Check if the admin is authorized to perform the action button = close_btn() # Inline button to close the message if data.block_user(): diff --git a/handlers/admins/check_usr/send_ads_message.py b/handlers/admins/check_usr/send_ads_message.py index 69132cc..110d954 100755 --- a/handlers/admins/check_usr/send_ads_message.py +++ b/handlers/admins/check_usr/send_ads_message.py @@ -32,7 +32,7 @@ async def send_ads_message(msg: types.Message, state: FSMContext): language = msg.from_user.language_code # The language code of the admin for message translation data_state = await state.get_data() # Retrieve data from the FSM context target_user_id = data_state['user_id'] # The ID of the target user who will receive the message - is_admin = SelectAdmin(cid=user_id) # Check if the admin is authorized to send messages + is_admin = SelectAdmin(user_ud=user_id) # Check if the admin is authorized to send messages button = close_btn() # Inline button to close the message if is_admin.send_message(): diff --git a/handlers/admins/check_usr/send_message.py b/handlers/admins/check_usr/send_message.py index 4faa96a..7ae12c6 100755 --- a/handlers/admins/check_usr/send_message.py +++ b/handlers/admins/check_usr/send_message.py @@ -31,11 +31,11 @@ async def send_message(call: types.CallbackQuery, callback_data: BlockUser, stat - This function is asynchronous and does not return a value but performs actions such as sending messages and updating states. """ try: - target_user_id = callback_data.cid # The ID of the user to whom the message will be sent + target_user_id = callback_data.user_ud # The ID of the user to whom the message will be sent user_id = call.from_user.id # The ID of the admin initiating the message send action message_id = call.message.message_id # The ID of the message triggering the callback language = call.from_user.language_code # The language code of the admin for message translation - admin_check = SelectAdmin(cid=user_id) # Check if the admin has permission to send messages + admin_check = SelectAdmin(user_ud=user_id) # Check if the admin has permission to send messages button = close_btn() # Inline button to close the message if admin_check.send_message(): diff --git a/handlers/admins/main_panel.py b/handlers/admins/main_panel.py index 4927b1f..a010b57 100755 --- a/handlers/admins/main_panel.py +++ b/handlers/admins/main_panel.py @@ -27,7 +27,7 @@ async def main_panel(msg: types.Message, state: FSMContext): Exception: Logs any errors encountered during the process. """ try: - cid = msg.from_user.id + user_ud = msg.from_user.id mid = msg.message_id lang = msg.from_user.language_code @@ -35,13 +35,13 @@ async def main_panel(msg: types.Message, state: FSMContext): welcome_text = translator(text=f'👩‍💻Hello, dear admin, welcome to the main panel!', dest=lang) response_msg = await msg.answer(text=f'{welcome_text}', - reply_markup=main_admin_panel_btn(cid=cid, lang=lang)) + reply_markup=main_admin_panel_btn(user_ud=user_ud, lang=lang)) # Manage previous message state_data = await state.get_data() try: if 'message_id' in state_data and state_data['message_id'] > 1: - await bot.delete_message(chat_id=cid, message_id=state_data['message_id']) + await bot.delete_message(chat_id=user_ud, message_id=state_data['message_id']) except Exception as err: logging.error(f"Error deleting previous message: {err}") @@ -51,7 +51,7 @@ async def main_panel(msg: types.Message, state: FSMContext): }) # Delete the original command message - await bot.delete_message(chat_id=cid, message_id=mid) + await bot.delete_message(chat_id=user_ud, message_id=mid) except Exception as err: logging.error(f"Unhandled error: {err}") diff --git a/handlers/admins/send_ads/get_message.py b/handlers/admins/send_ads/get_message.py index e88afc5..3ddbb39 100755 --- a/handlers/admins/send_ads/get_message.py +++ b/handlers/admins/send_ads/get_message.py @@ -42,11 +42,11 @@ async def get_message(msg: types.Message, state: FSMContext): state_data = await state.get_data() # Check if the user has admin permissions - is_admin = SelectAdmin(cid=user_id) + is_admin = SelectAdmin(user_ud=user_id) if is_admin.send_message(): # Prepare the admin panel button and fetch ads data - button_markup = main_admin_panel_btn(cid=user_id, lang=language_code) + button_markup = main_admin_panel_btn(user_ud=user_id, lang=language_code) ads_data = file_db.reading_db().get('ads') if ads_data: diff --git a/handlers/admins/send_ads/send_ads.py b/handlers/admins/send_ads/send_ads.py index 021e972..e13249a 100755 --- a/handlers/admins/send_ads/send_ads.py +++ b/handlers/admins/send_ads/send_ads.py @@ -43,7 +43,7 @@ async def send_ads(call: types.CallbackQuery, state: FSMContext): user_id = call.from_user.id message_id = call.message.message_id language_code = call.from_user.language_code - is_admin = SelectAdmin(cid=user_id) + is_admin = SelectAdmin(user_ud=user_id) button_markup = close_btn() if is_admin.send_message(): diff --git a/handlers/admins/send_ads/stop_ads.py b/handlers/admins/send_ads/stop_ads.py index f6864be..15fd869 100644 --- a/handlers/admins/send_ads/stop_ads.py +++ b/handlers/admins/send_ads/stop_ads.py @@ -39,7 +39,7 @@ async def stop_ads(call: types.CallbackQuery, state: FSMContext): language_code = call.from_user.language_code # Check if the user has admin permissions - is_admin = SelectAdmin(cid=user_id) + is_admin = SelectAdmin(user_ud=user_id) if is_admin.send_message(): # Fetch the current ads data diff --git a/handlers/admins/statistika/download_statistics.py b/handlers/admins/statistika/download_statistics.py index 8458c0b..6f8deeb 100755 --- a/handlers/admins/statistika/download_statistics.py +++ b/handlers/admins/statistika/download_statistics.py @@ -38,13 +38,13 @@ async def download_statistics(call: types.CallbackQuery, state: FSMContext): user_id = call.from_user.id message_id = call.message.message_id language = call.from_user.language_code - is_admin = SelectAdmin(cid=user_id) + is_admin = SelectAdmin(user_ud=user_id) if is_admin.download_statistika(): # Retrieve user data from the database data = db.select_all_users() id_list = [] - cid_list = [] + user_ud_list = [] date_list = [] usernames = [] langs = [] @@ -52,7 +52,7 @@ async def download_statistics(call: types.CallbackQuery, state: FSMContext): # Populate lists with user data for user in data: id_list.append(user[0]) - cid_list.append(user[1]) + user_ud_list.append(user[1]) date_list.append(user[2]) langs.append(user[3]) user_info = await bot.get_chat(chat_id=user[1]) @@ -61,7 +61,7 @@ async def download_statistics(call: types.CallbackQuery, state: FSMContext): # Create a DataFrame and save it to an Excel file statistics_data = { "id": id_list, - "cid": cid_list, + "user_ud": user_ud_list, "date_add": date_list, "username": usernames, "lang": langs diff --git a/handlers/admins/statistika/staristika.py b/handlers/admins/statistika/staristika.py index 009a5e4..6e30737 100755 --- a/handlers/admins/statistika/staristika.py +++ b/handlers/admins/statistika/staristika.py @@ -36,7 +36,7 @@ async def statistika(call: types.CallbackQuery, state: FSMContext): user_id = call.from_user.id message_id = call.message.message_id language = call.from_user.language_code - is_admin = SelectAdmin(cid=user_id) + is_admin = SelectAdmin(user_ud=user_id) if is_admin.view_statistika(): user_count = db.stat() @@ -46,7 +46,7 @@ async def statistika(call: types.CallbackQuery, state: FSMContext): f" {soat_minut_sekund}\n" + translator(text="📆 Date:", dest=language) + f' {yil_oy_kun}\n ' + translator(text="Number of bans: ", dest=language) + str( ban_count)) - button = download_statistika(cid=user_id, lang=language) + button = download_statistika(user_ud=user_id, lang=language) await state.update_data({"message_id": call.message.message_id}) else: text = translator(text="❌ Unfortunately, you do not have this permission!", dest=language) diff --git a/handlers/admins/super_admin.py b/handlers/admins/super_admin.py index 57e7297..5ef361a 100755 --- a/handlers/admins/super_admin.py +++ b/handlers/admins/super_admin.py @@ -36,33 +36,33 @@ async def super_admin(msg: types.Message): """ try: logging.info('Generating stats report') - cid = msg.from_user.id + user_ud = msg.from_user.id mid = msg.message_id data = db.select_all_users_ban() id_list = [] - cid_list = [] + user_ud_list = [] date_list = [] username_list = [] - admin_cid = [] + admin_user_ud = [] try: # Collecting data for the DataFrame for x in data: - id_list.append(x[0]) - cid_list.append(x[1]) - admin_cid.append(x[2]) - date_list.append(x[3]) + id_list.append(x['id']) + user_ud_list.append(x['user_id']) + admin_user_ud.append(x['admin_user_id']) + date_list.append(x['date']) # Fetching username from chat ID - chat = await bot.get_chat(chat_id=x[1]) + chat = await bot.get_chat(chat_id=x['user_id']) username_list.append(f'@{chat.username}') # Creating and saving DataFrame to Excel x_data = { "id": id_list, - "cid": cid_list, - "admin_cid": admin_cid, + "user_ud": user_ud_list, + "admin_user_ud": admin_user_ud, "date_add": date_list, "username": username_list } @@ -72,7 +72,7 @@ async def super_admin(msg: types.Message): # Sending the generated Excel file document = types.InputFile(excel_path) - await bot.send_document(chat_id=cid, + await bot.send_document(chat_id=user_ud, document=document, caption='Ban list') os.remove(excel_path) @@ -84,14 +84,14 @@ async def super_admin(msg: types.Message): # Sending the log file if it exists if os.path.exists(log_file_name) and os.path.getsize(log_file_name) > 0: document2 = types.InputFile(log_file_name) - await bot.send_document(chat_id=cid, + await bot.send_document(chat_id=user_ud, document=document2, caption='Update log') except Exception as err: logging.error(f"Error sending log file: {err}") # Deleting the original message - await bot.delete_message(chat_id=cid, message_id=mid) + await bot.delete_message(chat_id=user_ud, message_id=mid) except Exception as err: logging.error(f"Unhandled error: {err}") diff --git a/handlers/users/check_usr.py b/handlers/users/check_usr.py index a57cd97..6d27eb3 100755 --- a/handlers/users/check_usr.py +++ b/handlers/users/check_usr.py @@ -59,8 +59,8 @@ async def start_handler(msg: types.Message): await msg.answer(text=f"{message_text}", reply_markup=keyboard.as_markup()) # Add user to the database if not already present - if db.check_user(cid=user_id) is None: - db.insert_user(cid=user_id, + if db.check_user(user_ud=user_id) is None: + db.insert_user(user_ud=user_id, date=f"{date_day_month} / {time_hour_minute_second}") except Exception as err: logging.error(f"Error in start_handler: {err}") diff --git a/keyboards/inline/admin_btn.py b/keyboards/inline/admin_btn.py index bdea2e2..25066ee 100644 --- a/keyboards/inline/admin_btn.py +++ b/keyboards/inline/admin_btn.py @@ -30,12 +30,12 @@ def main_btn(): return False -def main_admin_panel_btn(cid, lang): +def main_admin_panel_btn(user_ud, lang): """ Creates the inline keyboard for the main admin panel. Parameters: - cid (int): The ID of the current user. + user_ud (int): The ID of the current user. lang (str): The language code for translation. Returns: @@ -50,7 +50,7 @@ def main_admin_panel_btn(cid, lang): btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = SelectAdmin(cid=cid) + is_admin = SelectAdmin(user_ud=user_ud) if is_admin.add_admin(): btn.button(text=translator(text=f"👮‍♂️ Admins settings!", dest=lang), @@ -79,12 +79,12 @@ def main_admin_panel_btn(cid, lang): return False -async def admin_setting(cid, lang): +async def admin_setting(user_ud, lang): """ Creates the inline keyboard for admin settings. Parameters: - cid (int): The ID of the current user. + user_ud (int): The ID of the current user. lang (str): The language code for translation. Returns: @@ -97,15 +97,15 @@ async def admin_setting(cid, lang): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - if cid == ADMIN: + if user_ud == ADMIN: data = db.select_all_admins() else: - data = db.select_add_admin(cid=cid) + data = db.select_add_admin(user_ud=user_ud) if data is not None: for x in data: info = await bot.get_chat(chat_id=x[1]) btn.button(text=f"👮‍♂️ @{info.username}: {info.full_name}!", - callback_data=AdminSetting(action="attach_admin", cid=x[1]).pack()) + callback_data=AdminSetting(action="attach_admin", user_ud=x[1]).pack()) btn.button(text=translator(text=f"👮‍♂️ ADD Admin!", dest=lang), callback_data=AdminCallback(action="add_admin", data="").pack()) @@ -117,12 +117,12 @@ async def admin_setting(cid, lang): return False -def attach_admin(cid, lang): +def attach_admin(user_ud, lang): """ Creates the inline keyboard for managing admin settings. Parameters: - cid (int): The ID of the current user. + user_ud (int): The ID of the current user. lang (str): The language code for translation. Returns: @@ -136,7 +136,7 @@ def attach_admin(cid, lang): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = SelectAdmin(cid=cid) + is_admin = SelectAdmin(user_ud=user_ud) send_message_tx = x_or_y(is_admin.send_message()) wiew_statistika_tx = x_or_y(is_admin.view_statistika()) download_statistika_tx = x_or_y(is_admin.download_statistika()) @@ -145,28 +145,28 @@ def attach_admin(cid, lang): add_admin_tx = x_or_y(is_admin.add_admin()) btn.button(text=translator(text=f"{send_message_tx} Send a message!", dest=lang), - callback_data=EditAdminSetting(action="edit", cid=cid, data='send_message').pack()) + callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='send_message').pack()) btn.button(text=translator(text=f"{wiew_statistika_tx} Wiew statistics!", dest=lang), - callback_data=EditAdminSetting(action="edit", cid=cid, data='statistika').pack()) + callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='statistika').pack()) btn.button(text=translator(text=f"{download_statistika_tx} Download statistics!", dest=lang), - callback_data=EditAdminSetting(action="edit", cid=cid, data='download_statistika').pack()) + callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='download_statistika').pack()) btn.button(text=translator(text=f"{block_user_tx} Block user!", dest=lang), - callback_data=EditAdminSetting(action="edit", cid=cid, data='block_user').pack()) + callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='block_user').pack()) btn.button(text=translator(text=f"{channel_settings_tx} Channel settings!", dest=lang), - callback_data=EditAdminSetting(action="edit", cid=cid, data='channel_settings').pack()) + callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='channel_settings').pack()) btn.button(text=translator(text=f"{add_admin_tx} Add a admin!", dest=lang), - callback_data=EditAdminSetting(action="edit", cid=cid, data='add_admin').pack()) + callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='add_admin').pack()) btn.button(text=translator(text=f"🔪Delete admin!", dest=lang), - callback_data=EditAdminSetting(action="edit", cid=cid, data='delete_admin').pack()) + callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='delete_admin').pack()) btn.adjust(1) btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) return btn.as_markup() @@ -175,12 +175,12 @@ def attach_admin(cid, lang): return False -def attach_admin_btn(cid, lang): +def attach_admin_btn(user_ud, lang): """ Creates the inline keyboard for managing admin settings. Parameters: - cid (int): The ID of the current user. + user_ud (int): The ID of the current user. lang (str): The language code for translation. Returns: @@ -195,7 +195,7 @@ def attach_admin_btn(cid, lang): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = SelectAdmin(cid=cid) + is_admin = SelectAdmin(user_ud=user_ud) send_message_tx = x_or_y(is_admin.send_message()) wiew_statistika_tx = x_or_y(is_admin.view_statistika()) download_statistika_tx = x_or_y(is_admin.download_statistika()) @@ -204,28 +204,28 @@ def attach_admin_btn(cid, lang): add_admin_tx = x_or_y(is_admin.add_admin()) btn.button(text=translator(text=f"{send_message_tx} Send a message!", dest=lang), - callback_data=EditAdminSetting(action="edit", cid=cid, data='send_message').pack()) + callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='send_message').pack()) btn.button(text=translator(text=f"{wiew_statistika_tx} Wiew statistics!", dest=lang), - callback_data=EditAdminSetting(action="edit", cid=cid, data='statistika').pack()) + callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='statistika').pack()) btn.button(text=translator(text=f"{download_statistika_tx} Download statistics!", dest=lang), - callback_data=EditAdminSetting(action="edit", cid=cid, data='download_statistika').pack()) + callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='download_statistika').pack()) btn.button(text=translator(text=f"{block_user_tx} Block user!", dest=lang), - callback_data=EditAdminSetting(action="edit", cid=cid, data='block_user').pack()) + callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='block_user').pack()) btn.button(text=translator(text=f"{channel_settings_tx} Channel settings!", dest=lang), - callback_data=EditAdminSetting(action="edit", cid=cid, data='channel_settings').pack()) + callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='channel_settings').pack()) btn.button(text=translator(text=f"{add_admin_tx} Add a admin!", dest=lang), - callback_data=EditAdminSetting(action="edit", cid=cid, data='add_admin').pack()) + callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='add_admin').pack()) btn.button(text=translator(text=f"🔪Delete admin!", dest=lang), - callback_data=EditAdminSetting(action="edit", cid=cid, data='delete_admin').pack()) + callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='delete_admin').pack()) btn.adjust(1) btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) return btn.as_markup() @@ -275,12 +275,12 @@ def channel_settings(lang): return False -def block_user(cid, lang, user_id): +def block_user(user_ud, lang, user_id): """ Creates the inline keyboard for blocking or unblocking a user. Parameters: - cid (int): The ID of the current user. + user_ud (int): The ID of the current user. lang (str): The language code for translation. user_id (int): The ID of the user to be blocked or unblocked. @@ -296,18 +296,18 @@ def block_user(cid, lang, user_id): btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = SelectAdmin(cid=cid) + is_admin = SelectAdmin(user_ud=user_ud) if is_admin.block_user(): - data = db.check_user_ban(cid=user_id) + data = db.check_user_ban(user_ud=user_id) if data is None: btn.button(text=translator(text=f"🚫Userni bloklash!", dest=lang), - callback_data=BlockUser(action="block", cid=user_id).pack()) + callback_data=BlockUser(action="block", user_ud=user_id).pack()) else: - if data[2] == cid or cid == ADMIN: + if data[2] == user_ud or user_ud == ADMIN: btn.button(text=translator(text=f"✅Unblock user!", dest=lang), - callback_data=BlockUser(action="block", cid=user_id).pack()) + callback_data=BlockUser(action="block", user_ud=user_id).pack()) btn.adjust(1, 2) btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) return btn.as_markup() @@ -316,12 +316,12 @@ def block_user(cid, lang, user_id): return False -def download_statistika(cid, lang): +def download_statistika(user_ud, lang): """ Creates the inline keyboard for downloading statistics. Parameters: - cid (int): The ID of the current user. + user_ud (int): The ID of the current user. lang (str): The language code for translation. Returns: @@ -334,7 +334,7 @@ def download_statistika(cid, lang): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = SelectAdmin(cid=cid) + is_admin = SelectAdmin(user_ud=user_ud) if is_admin.download_statistika(): btn.button(text=translator(text=f"📜 Dowload statistika!", dest=lang), diff --git a/keyboards/inline/button.py b/keyboards/inline/button.py index 1c3f14e..1695f9b 100644 --- a/keyboards/inline/button.py +++ b/keyboards/inline/button.py @@ -28,11 +28,11 @@ class EditAdminSetting(CallbackData, prefix="edit_setting"): Attributes: action (str): The specific action to be performed on settings. - cid (int): The ID of the admin or user related to the setting. + user_ud (int): The ID of the admin or user related to the setting. data (str): The specific setting to be edited. """ action: str - cid: int + user_ud: int data: str class AdminSetting(CallbackData, prefix="admin_setting"): @@ -41,10 +41,10 @@ class AdminSetting(CallbackData, prefix="admin_setting"): Attributes: action (str): The specific action related to admin settings. - cid (int): The ID of the admin or user related to the setting. + user_ud (int): The ID of the admin or user related to the setting. """ action: str - cid: int + user_ud: int class BlockUser(CallbackData, prefix="block_user"): """ @@ -52,7 +52,7 @@ class BlockUser(CallbackData, prefix="block_user"): Attributes: action (str): The specific action to be performed (block/unblock). - cid (int): The ID of the user to be blocked or unblocked. + user_ud (int): The ID of the user to be blocked or unblocked. """ action: str - cid: int + user_ud: int diff --git a/middlewares/check_user.py b/middlewares/check_user.py index d652773..9c4817e 100755 --- a/middlewares/check_user.py +++ b/middlewares/check_user.py @@ -47,14 +47,14 @@ # if data['join_channel']: # try: # # Try to get the user ID from the message object -# cid = message.from_user.id +# user_ud = message.from_user.id # except Exception as err: # # If message object is not available, use callback query object -# cid = call.from_user.id +# user_ud = call.from_user.id # logging.error(err) # # # If the user is not the admin, perform the channel check -# if cid != self.ADMIN: +# if user_ud != self.ADMIN: # force = False # result = db.select_channels() # for x in result: @@ -64,7 +64,7 @@ # await bot.get_chat(ids) # try: # # Check the user's membership status in the channel -# res = await bot.get_chat_member(chat_id=ids, user_id=cid) +# res = await bot.get_chat_member(chat_id=ids, user_id=user_ud) # except: # # Continue if unable to retrieve chat member information # continue From 9c8f40563fad24dd3149ebd7c689fe06ec2d6dc8 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Thu, 27 Feb 2025 15:26:23 +0500 Subject: [PATCH 07/71] Rename 'mid' to 'message_id' for clarity in main_panel function --- handlers/admins/main_panel.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/handlers/admins/main_panel.py b/handlers/admins/main_panel.py index a010b57..23b4163 100755 --- a/handlers/admins/main_panel.py +++ b/handlers/admins/main_panel.py @@ -28,7 +28,7 @@ async def main_panel(msg: types.Message, state: FSMContext): """ try: user_ud = msg.from_user.id - mid = msg.message_id + message_id = msg.message_id lang = msg.from_user.language_code # Translate and send the welcome message with admin panel buttons @@ -51,7 +51,7 @@ async def main_panel(msg: types.Message, state: FSMContext): }) # Delete the original command message - await bot.delete_message(chat_id=user_ud, message_id=mid) + await bot.delete_message(chat_id=user_ud, message_id=message_id) except Exception as err: logging.error(f"Unhandled error: {err}") From c6191c7b4f31714bb2543da5f9046ced53017b89 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Thu, 27 Feb 2025 15:30:03 +0500 Subject: [PATCH 08/71] Refactor user ID references from 'user_ud' to 'user_id' for consistency and add permission checks in SelectAdmin class --- db/database.py | 2 +- filters/admin.py | 65 ++++++++++++++++++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/db/database.py b/db/database.py index 1d91538..7746174 100755 --- a/db/database.py +++ b/db/database.py @@ -487,7 +487,7 @@ def select_admin(self, user_id): tuple: The admin's information if they exist, None otherwise. """ try: - self.cursor.execute("SELECT * FROM `admins` WHERE `user_id`=%s", (user_id,)) + self.cursor.execute("SELECT * FROM `admins` WHERE `user_id`=%s LIMIT 1", (user_id,)) result = self.cursor.fetchone() return result except mysql.connector.Error as err: diff --git a/filters/admin.py b/filters/admin.py index bf756a5..5316aff 100644 --- a/filters/admin.py +++ b/filters/admin.py @@ -53,9 +53,9 @@ async def __call__(self, message: Message) -> bool: Returns: bool: True if the user is an admin or the super admin, False otherwise. """ - self.user_ud = message.from_user.id - self.dada = db.select_admin(user_ud=self.user_ud) - if self.user_ud == ADMIN: + self.user_id = message.from_user.id + self.dada = db.select_admin(user_id=self.user_id) + if self.user_id == ADMIN: return True elif self.dada is not None: return True @@ -68,15 +68,15 @@ class SelectAdmin: Class to handle various admin-related actions. Attributes: - user_ud (int): The user ID. + user_id (int): The user ID. super_admin (int): The ID of the super admin. dada (list): The admin details from the database. """ - def __init__(self, user_ud): - self.user_ud = user_ud + def __init__(self, user_id): + self.user_id = user_id self.super_admin = ADMIN - self.dada = db.select_admin(user_ud=self.user_ud) + self.dada = db.select_admin(user_id=self.user_id) def send_message(self) -> bool: """ @@ -85,9 +85,9 @@ def send_message(self) -> bool: Returns: bool: True if the user can send messages, False otherwise. """ - if self.user_ud == self.super_admin: + if self.user_id == self.super_admin: return True - elif self.dada[3] == 1: + elif self.dada['send_message'] == 1: return True else: return False @@ -99,9 +99,9 @@ def view_statistika(self) -> bool: Returns: bool: True if the user can view statistics, False otherwise. """ - if self.user_ud == self.super_admin: + if self.user_id == self.super_admin: return True - elif self.dada[4] == 1: + elif self.dada['statistika'] == 1: return True else: return False @@ -113,9 +113,9 @@ def download_statistika(self) -> bool: Returns: bool: True if the user can download statistics, False otherwise. """ - if self.user_ud == self.super_admin: + if self.user_id == self.super_admin: return True - elif self.dada[5] == 1: + elif self.dada['download_statistika'] == 1: return True else: return False @@ -127,9 +127,9 @@ def block_user(self) -> bool: Returns: bool: True if the user can block users, False otherwise. """ - if self.user_ud == self.super_admin: + if self.user_id == self.super_admin: return True - elif self.dada[6] == 1: + elif self.dada['block_user'] == 1: return True else: return False @@ -141,9 +141,9 @@ def channel_settings(self) -> bool: Returns: bool: True if the user can change channel settings, False otherwise. """ - if self.user_ud == self.super_admin: + if self.user_id == self.super_admin: return True - elif self.dada[7] == 1: + elif self.dada['channel_settings'] == 1: return True else: return False @@ -155,10 +155,37 @@ def add_admin(self) -> bool: Returns: bool: True if the user can add new admins, False otherwise. """ - if self.user_ud == self.super_admin: + if self.user_id == self.super_admin: return True - elif self.dada[8] == 1: + elif self.dada['add_admin'] == 1: return True else: return False + + def set_data(self) -> bool: + """ + Checks if the user has permission to set data. + Returns: + bool: True if the user can set data, False otherwise. + """ + if self.user_id == self.super_admin: + return True + elif self.dada['set_data'] == 1: + return True + else: + return False + + + def get_data(self) -> bool: + """ + Checks if the user has permission to get data. + Returns: + bool: True if the user can get data, False otherwise. + """ + if self.user_id == self.super_admin: + return True + elif self.dada['get_data'] == 1: + return True + else: + return False \ No newline at end of file From 6634f79b209a862be111be7b2fcb7792f379115b Mon Sep 17 00:00:00 2001 From: UznetDev Date: Thu, 27 Feb 2025 15:39:13 +0500 Subject: [PATCH 09/71] Refactor database schema to replace 'admin_user_id' with 'initiator_user_id' and update date fields to 'created_time'; add 'settings' table creation method and remove unused date parameter in insert_user function. --- db/database.py | 41 ++++++++++++++++++++++++++++++++--------- handlers/users/start.py | 2 -- 2 files changed, 32 insertions(+), 11 deletions(-) diff --git a/db/database.py b/db/database.py index 7746174..3c68753 100755 --- a/db/database.py +++ b/db/database.py @@ -85,9 +85,9 @@ def create_table_ban(self): CREATE TABLE IF NOT EXISTS ban ( `id` INT AUTO_INCREMENT PRIMARY KEY, `user_id` bigint(200) NOT NULL UNIQUE, - `admin_user_id` bigint(200), + `initiator_user_id` bigint(200), `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `date` DATE + `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) """ self.cursor.execute(sql) @@ -109,7 +109,7 @@ def create_table_users(self): `id` INT AUTO_INCREMENT PRIMARY KEY, `user_id` bigint(200) NOT NULL UNIQUE, `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `date` DATE, + `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `language_code` varchar(5) ) """ @@ -132,7 +132,7 @@ def create_table_channel(self): `id` INT AUTO_INCREMENT PRIMARY KEY, `channel_id` bigint(200), `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `date` DATE, + `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `initiator_user_id` bigint(200) ); """ @@ -164,7 +164,8 @@ def create_table_admins(self): `set_data` TINYINT(1), `get_data` TINYINT(1), `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `date` DATE + `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ); """ self.cursor.execute(sql) @@ -175,22 +176,44 @@ def create_table_admins(self): except Exception as err: logging.error(err) + def create_table_settings(self): + """ + Create the 'settings' table if it does not already exist. + """ + try: + sql = """ + CREATE TABLE IF NOT EXISTS `settings` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `updater_user_id` bigint(200) NOT NULL UNIQUE, + `initiator_user_id` bigint(200), + `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ) + """ + self.cursor.execute(sql) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + ## ------------------ Insert data ------------------ ## - def insert_user(self, user_id, date, language_code): + def insert_user(self, user_id, language_code): """ Add a user to the 'users' table. Parameters: user_id (int): The user's chat ID. - date (str): The date the user was added. language_code (str): The user's language_codeuage preference. """ try: sql = """ - INSERT INTO `users` (`user_id`,`date`,`language_code`) VALUES (%s,%s,%s) + INSERT INTO `users` (`user_id`,`language_code`) VALUES (%s,%s) """ - values = (user_id, date, language_code) + values = (user_id, language_code) self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: diff --git a/handlers/users/start.py b/handlers/users/start.py index 19015b1..411e9a1 100755 --- a/handlers/users/start.py +++ b/handlers/users/start.py @@ -3,7 +3,6 @@ from aiogram.filters import CommandStart from function.translator import translator from loader import dp, bot, db -from data.config import yil_oy_kun, soat_minut_sekund from keyboards.inline.user import send_url @@ -46,7 +45,6 @@ async def start_handler(msg: types.Message): # Check and log the user if not already in the database if db.check_user(user_id) is None: db.insert_user(user_id==user_id, - date=f'{yil_oy_kun} / {soat_minut_sekund}', lang=user_language) except Exception as err: logging.error(f"Error handling /start command: {err}") From 4d2ed49c400ffa5942e8a8ba2af371d7cf71a7de Mon Sep 17 00:00:00 2001 From: UznetDev Date: Thu, 27 Feb 2025 16:14:24 +0500 Subject: [PATCH 10/71] Refactor insert functions in Database class to remove unused date parameters and improve SQL statements; reintroduce select_all_users_ban method for retrieving banned users. --- db/database.py | 62 ++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 32 deletions(-) diff --git a/db/database.py b/db/database.py index 3c68753..c1a5562 100755 --- a/db/database.py +++ b/db/database.py @@ -223,20 +223,19 @@ def insert_user(self, user_id, language_code): logging.error(err) - def insert_channel(self, user_id, date, initiator_user_id): + def insert_channel(self, user_id, initiator_user_id): """ Add a channel to the 'channels' table. Parameters: user_id (int): The channel's ID. - date (str): The date the channel was added. initiator_user_id (int): The chat ID of the admin who added the channel. """ try: sql = """ - INSERT INTO `channels` (`user_id`,`date`,`initiator_user_id`) VALUES (%s,%s,%s) + INSERT INTO `channels` (`user_id`, `initiator_user_id`) VALUES (%s,%s) """ - values = (user_id, date, initiator_user_id) + values = (user_id, initiator_user_id) self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: @@ -246,20 +245,19 @@ def insert_channel(self, user_id, date, initiator_user_id): logging.error(err) - def insert_admin(self, user_id, date, add): + def insert_admin(self, user_id, add): """ Add an admin to the 'admins' table. Parameters: user_id (int): The admin's chat ID. - date (str): The date the admin was added. add (int): The chat ID of the admin who added this admin. """ try: sql = """ - INSERT INTO `admins` (`user_id`,`initiator_user_id`,`date`) VALUES (%s,%s,%s) + INSERT INTO `admins` (`user_id`,`admin_user_idinitiator_user_id`) VALUES (%s,%s) """ - values = (user_id, add, date) + values = (user_id, add) self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: @@ -269,20 +267,19 @@ def insert_admin(self, user_id, date, add): logging.error(err) - def insert_user_ban(self, user_id, date, admin_user_id): + def insert_user_ban(self, user_id, admin_user_id): """ Add a user to the 'ban' table. Parameters: user_id (int): The user's chat ID. - date (str): The date the user was banned. admin_user_id (int): The admin's chat ID who banned the user. """ try: sql = """ - INSERT INTO `ban` (`user_id`,`admin_user_id`,`date`) VALUES (%s,%s,%s) + INSERT INTO `ban` (`user_id`,`admin_user_id`) VALUES (%s,%s) """ - values = (user_id, admin_user_id, date) + values = (user_id, admin_user_id) self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: @@ -292,26 +289,6 @@ def insert_user_ban(self, user_id, date, admin_user_id): logging.error(err) - def select_all_users_ban(self): - """ - Select all users from the 'ban' table. - - Returns: - list: A list of tuples containing all banned users. - """ - try: - sql = """ - SELECT * FROM `ban` - """ - self.cursor.execute(sql) - result = self.cursor.fetchall() - return result - except mysql.connector.Error as err: - logging.error(err) - self.reconnect() - except Exception as err: - logging.error(err) - ## ------------------ Update ------------------ ## @@ -338,6 +315,27 @@ def update_admin_data(self, user_id, column, value): ## ------------------ Select ------------------ ## + def select_all_users_ban(self): + """ + Select all users from the 'ban' table. + + Returns: + list: A list of tuples containing all banned users. + """ + try: + sql = """ + SELECT * FROM `ban` + """ + self.cursor.execute(sql) + result = self.cursor.fetchall() + return result + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + def stat_ban(self): """ Get the total number of banned users. From 690de8c55b66bebbce3e7f2f3224e97ad0369d2f Mon Sep 17 00:00:00 2001 From: UznetDev Date: Thu, 27 Feb 2025 16:25:08 +0500 Subject: [PATCH 11/71] Add settings table methods: insert, update, and select functionality --- db/database.py | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/db/database.py b/db/database.py index c1a5562..bdb8b70 100755 --- a/db/database.py +++ b/db/database.py @@ -186,6 +186,8 @@ def create_table_settings(self): `id` INT AUTO_INCREMENT PRIMARY KEY, `updater_user_id` bigint(200) NOT NULL UNIQUE, `initiator_user_id` bigint(200), + `key` VARCHAR(255) NOT NULL, + `value` VARCHAR(255) NOT NULL, `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) @@ -201,6 +203,24 @@ def create_table_settings(self): ## ------------------ Insert data ------------------ ## + def insert_settings(self, initiator_user_id, key, value): + """ + Add a setting to the 'settings' table. + """ + try: + sql = """ + INSERT INTO `settings` (`updater_user_id`, `initiator_user_id`, `key`, `value`) VALUES (%s, %s, %s, %s) + """ + values = (initiator_user_id, initiator_user_id, key, value) + self.cursor.execute(sql, values) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + def insert_user(self, user_id, language_code): """ Add a user to the 'users' table. @@ -291,6 +311,28 @@ def insert_user_ban(self, user_id, admin_user_id): ## ------------------ Update ------------------ ## + def update_settings_key(self, updater_user_id, key, value): + """ + Update a setting in the 'settings' table. + Parameters: + updater_user_id (int): The chat ID of the admin who updated the setting. + initiator_user_id (int): The chat ID of the admin who initiated the update. + key (str): The key of the setting to be updated. + value (str): The new value for the setting. + """ + try: + sql = """ + UPDATE `settings` SET `value`=%s, `updater_user_id`=%s, WHERE `key`=%s + """ + values = (value, updater_user_id, key) + self.cursor.execute(sql, values) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + def update_admin_data(self, user_id, column, value): """ @@ -314,6 +356,26 @@ def update_admin_data(self, user_id, column, value): ## ------------------ Select ------------------ ## + def select_setting(self, key: str): + """ + Select a setting from the 'settings' table. + Parameters: + key (str): The key of the setting to retrieve. + Returns: + str: The value of the setting. + """ + try: + sql = "SELECT `value` FROM `settings` WHERE `key`=%s" + values = (key,) + self.cursor.execute(sql, values) + result = self.cursor.fetchone() + return result[0] + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + def select_all_users_ban(self): """ From 600fe1eb62575ced2785e549c5768b74f6ab9db2 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Thu, 27 Feb 2025 16:29:51 +0500 Subject: [PATCH 12/71] Add updater_user_id field to users, channels, and admins tables for tracking updates --- db/database.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/db/database.py b/db/database.py index bdb8b70..451b79e 100755 --- a/db/database.py +++ b/db/database.py @@ -86,6 +86,7 @@ def create_table_ban(self): `id` INT AUTO_INCREMENT PRIMARY KEY, `user_id` bigint(200) NOT NULL UNIQUE, `initiator_user_id` bigint(200), + `updater_user_id` bigint(200), `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) @@ -105,7 +106,7 @@ def create_table_users(self): """ try: sql = """ - CREATE TABLE IF NOT EXISTS users ( + CREATE TABLE IF NOT EXISTS `users` ( `id` INT AUTO_INCREMENT PRIMARY KEY, `user_id` bigint(200) NOT NULL UNIQUE, `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, @@ -131,9 +132,11 @@ def create_table_channel(self): CREATE TABLE IF NOT EXISTS `channels` ( `id` INT AUTO_INCREMENT PRIMARY KEY, `channel_id` bigint(200), + `initiator_user_id` bigint(200), + `updater_user_id` bigint(200) `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - `initiator_user_id` bigint(200) + `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ); """ self.cursor.execute(sql) @@ -151,10 +154,11 @@ def create_table_admins(self): """ try: sql = """ - CREATE TABLE IF NOT EXISTS admins ( + CREATE TABLE IF NOT EXISTS `admins` ( `id` INT AUTO_INCREMENT PRIMARY KEY, `user_id` bigint(200) NOT NULL UNIQUE, `initiator_user_id` bigint(200), + `updater_user_id` bigint(200), `send_message` TINYINT(1), `statistika` TINYINT(1), `download_statistika` TINYINT(1), @@ -165,7 +169,6 @@ def create_table_admins(self): `get_data` TINYINT(1), `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP - ); """ self.cursor.execute(sql) @@ -176,6 +179,7 @@ def create_table_admins(self): except Exception as err: logging.error(err) + def create_table_settings(self): """ Create the 'settings' table if it does not already exist. From 5c0dc8b9dd19742e884e0e243423e52326364007 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Thu, 27 Feb 2025 16:32:27 +0500 Subject: [PATCH 13/71] Fix SQL syntax in ban table creation and ensure proper formatting for updater_user_id in channels table --- db/database.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/db/database.py b/db/database.py index 451b79e..912b0e6 100755 --- a/db/database.py +++ b/db/database.py @@ -82,7 +82,7 @@ def create_table_ban(self): """ try: sql = """ - CREATE TABLE IF NOT EXISTS ban ( + CREATE TABLE IF NOT EXISTS `ban` ( `id` INT AUTO_INCREMENT PRIMARY KEY, `user_id` bigint(200) NOT NULL UNIQUE, `initiator_user_id` bigint(200), @@ -133,7 +133,7 @@ def create_table_channel(self): `id` INT AUTO_INCREMENT PRIMARY KEY, `channel_id` bigint(200), `initiator_user_id` bigint(200), - `updater_user_id` bigint(200) + `updater_user_id` bigint(200), `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP From ed5fb48edc08a824f7c93a881bbb0d84fbe1ceaa Mon Sep 17 00:00:00 2001 From: UznetDev Date: Thu, 27 Feb 2025 16:35:48 +0500 Subject: [PATCH 14/71] Add select methods for settings, banned users, all users, admins, and channels in Database class --- db/database.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/db/database.py b/db/database.py index 912b0e6..a0090f4 100755 --- a/db/database.py +++ b/db/database.py @@ -360,6 +360,7 @@ def update_admin_data(self, user_id, column, value): ## ------------------ Select ------------------ ## + # Select a setting from the 'settings' table. def select_setting(self, key: str): """ Select a setting from the 'settings' table. @@ -381,6 +382,7 @@ def select_setting(self, key: str): logging.error(err) + # Select all users from the 'ban' table. def select_all_users_ban(self): """ Select all users from the 'ban' table. @@ -458,6 +460,7 @@ def delete_user_ban(self, user_id): logging.error(err) + # Select all users from the 'users' table. def select_all_users(self): """ Select all users from the 'users' table. @@ -541,6 +544,7 @@ def check_user(self, user_id): logging.error(err) + # Select admin from admins table def select_admin_column(self, user_id, column): """ Select a specific column for an admin from the 'admins' table. @@ -661,6 +665,7 @@ def delete_admin(self, user_id): logging.error(err) + # Select channels from the 'channels' table def select_channels(self): """ Select all channels from the 'channels' table. @@ -758,5 +763,3 @@ def delete_channel(self, user_id): self.reconnect() except Exception as err: logging.error(err) - - From cff6badf83bc6d63aef3882099e44c0c091ab91a Mon Sep 17 00:00:00 2001 From: UznetDev Date: Thu, 27 Feb 2025 17:11:38 +0500 Subject: [PATCH 15/71] Refactor Database class: remove deprecated ban table creation, update insert methods for channels and admins, and add updater_user_id for tracking updates. --- db/database.py | 73 +++++++++++++------------------------------------- 1 file changed, 19 insertions(+), 54 deletions(-) diff --git a/db/database.py b/db/database.py index a0090f4..3d13a5e 100755 --- a/db/database.py +++ b/db/database.py @@ -76,29 +76,6 @@ def __del__(self): ## --------------------- Create table ------------------## - def create_table_ban(self): - """ - Create the 'ban' table if it does not already exist. - """ - try: - sql = """ - CREATE TABLE IF NOT EXISTS `ban` ( - `id` INT AUTO_INCREMENT PRIMARY KEY, - `user_id` bigint(200) NOT NULL UNIQUE, - `initiator_user_id` bigint(200), - `updater_user_id` bigint(200), - `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP - ) - """ - self.cursor.execute(sql) - self.connection.commit() - except mysql.connector.Error as err: - logging.error(err) - self.reconnect() - except Exception as err: - logging.error(err) - def create_table_users(self): """ @@ -109,6 +86,9 @@ def create_table_users(self): CREATE TABLE IF NOT EXISTS `users` ( `id` INT AUTO_INCREMENT PRIMARY KEY, `user_id` bigint(200) NOT NULL UNIQUE, + `status` VARCHAR(255) IN ('remove', 'active', 'blocked', 'ban', 'unban', 'sleep', 'active') DEFAULT 'active', + `initiator_user_id` bigint(200), + `updater_user_id` bigint(200), `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `language_code` varchar(5) @@ -247,19 +227,19 @@ def insert_user(self, user_id, language_code): logging.error(err) - def insert_channel(self, user_id, initiator_user_id): + def insert_channel(self, channel_id, initiator_user_id): """ Add a channel to the 'channels' table. Parameters: - user_id (int): The channel's ID. + channel_id (int): The channel's ID. initiator_user_id (int): The chat ID of the admin who added the channel. """ try: sql = """ - INSERT INTO `channels` (`user_id`, `initiator_user_id`) VALUES (%s,%s) + INSERT INTO `channels` (`channel_id`, `initiator_user_id`) VALUES (%s,%s) """ - values = (user_id, initiator_user_id) + values = (channel_id, initiator_user_id) self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: @@ -269,19 +249,19 @@ def insert_channel(self, user_id, initiator_user_id): logging.error(err) - def insert_admin(self, user_id, add): + def insert_admin(self, user_id, initiator_user_id): """ Add an admin to the 'admins' table. Parameters: user_id (int): The admin's chat ID. - add (int): The chat ID of the admin who added this admin. + initiator_user_id (int): The chat ID of the admin who added this admin. """ try: sql = """ - INSERT INTO `admins` (`user_id`,`admin_user_idinitiator_user_id`) VALUES (%s,%s) + INSERT INTO `admins` (`user_id`,`initiator_user_id`) VALUES (%s,%s) """ - values = (user_id, add) + values = (user_id, initiator_user_id) self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: @@ -291,27 +271,6 @@ def insert_admin(self, user_id, add): logging.error(err) - def insert_user_ban(self, user_id, admin_user_id): - """ - Add a user to the 'ban' table. - - Parameters: - user_id (int): The user's chat ID. - admin_user_id (int): The admin's chat ID who banned the user. - """ - try: - sql = """ - INSERT INTO `ban` (`user_id`,`admin_user_id`) VALUES (%s,%s) - """ - values = (user_id, admin_user_id) - self.cursor.execute(sql, values) - self.connection.commit() - except mysql.connector.Error as err: - logging.error(err) - self.reconnect() - except Exception as err: - logging.error(err) - ## ------------------ Update ------------------ ## @@ -338,7 +297,7 @@ def update_settings_key(self, updater_user_id, key, value): logging.error(err) - def update_admin_data(self, user_id, column, value): + def update_admin_data(self, user_id, column, value, updater_user_id): """ Update an admin's data in the 'admins' table. @@ -346,9 +305,13 @@ def update_admin_data(self, user_id, column, value): user_id (int): The admin's chat ID. column (str): The column to be updated. value (str): The new value for the specified column. + updater_user_id (int): The chat ID of the admin who updated the data. + Returns: + None + """ try: - sql = f"""UPDATE `admins` SET `{column}` = '{value}' WHERE `user_id`=%s""" + sql = f"""UPDATE `admins` SET `{column}` = '{value}', `updater_user_id` = '{updater_user_id}' WHERE `user_id`=%s""" values = (user_id,) self.cursor.execute(sql, values) self.connection.commit() @@ -358,6 +321,8 @@ def update_admin_data(self, user_id, column, value): except Exception as err: logging.error(err) + + ## ------------------ Select ------------------ ## # Select a setting from the 'settings' table. From f2b4c0cfa3bc1842067e520cb974897f002ccdc4 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Fri, 28 Feb 2025 09:40:49 +0500 Subject: [PATCH 16/71] Set default values for boolean fields in the Database class --- db/database.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/db/database.py b/db/database.py index 3d13a5e..41b27ae 100755 --- a/db/database.py +++ b/db/database.py @@ -139,14 +139,14 @@ def create_table_admins(self): `user_id` bigint(200) NOT NULL UNIQUE, `initiator_user_id` bigint(200), `updater_user_id` bigint(200), - `send_message` TINYINT(1), - `statistika` TINYINT(1), - `download_statistika` TINYINT(1), - `block_user` TINYINT(1), - `channel_settings` TINYINT(1), - `add_admin` TINYINT(1), - `set_data` TINYINT(1), - `get_data` TINYINT(1), + `send_message` TINYINT(1) DEFAULT 0, + `statistika` TINYINT(1) DEFAULT 0, + `download_statistika` TINYINT(1) DEFAULT 0, + `block_user` TINYINT(1) DEFAULT 0, + `channel_settings` TINYINT(1) DEFAULT 0, + `add_admin` TINYINT(1) DEFAULT 0, + `set_data` TINYINT(1) DEFAULT 0, + `get_data` TINYINT(1) DEFAULT 0, `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); From b1ca8e5203a11aae597a4e156241dec555098521 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Fri, 28 Feb 2025 09:53:38 +0500 Subject: [PATCH 17/71] Add update_user_status method and refactor ban table references in Database class --- db/database.py | 28 ++++++++++++++++--- .../admins/statistika/download_statistics.py | 10 +++---- main.py | 1 - 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/db/database.py b/db/database.py index 41b27ae..1c707b5 100755 --- a/db/database.py +++ b/db/database.py @@ -322,6 +322,26 @@ def update_admin_data(self, user_id, column, value, updater_user_id): logging.error(err) + def update_user_status(self, user_id, status, updater_user_id): + """ + Update a user's status in the 'users' table. + Parameters: + user_id (int): The user's chat ID. + status (str): The new status for the user. + Returns: + None + """ + try: + sql = f"""UPDATE `users` SET `status` = '{status}', `updater_user_id` = '{updater_user_id}' WHERE `user_id`=%s""" + values = (user_id,) + self.cursor.execute(sql, values) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + ## ------------------ Select ------------------ ## @@ -350,14 +370,14 @@ def select_setting(self, key: str): # Select all users from the 'ban' table. def select_all_users_ban(self): """ - Select all users from the 'ban' table. + Select all users from the 'users' table. Returns: list: A list of tuples containing all banned users. """ try: sql = """ - SELECT * FROM `ban` + SELECT * FROM `users` WHERE `status`='ban'` """ self.cursor.execute(sql) result = self.cursor.fetchall() @@ -377,7 +397,7 @@ def stat_ban(self): int: The total number of banned users. """ try: - sql = "SELECT COUNT(*) FROM `ban`;" + sql = "SELECT COUNT(*) FROM `users` WHERE `status`='ban'`;" self.cursor.execute(sql) result = self.cursor.fetchone() return result[0] @@ -399,7 +419,7 @@ def check_user_ban(self, user_id): tuple: The user's ban information if they are banned, None otherwise. """ try: - self.cursor.execute("SELECT * FROM `ban` WHERE `user_id`=%s", (user_id,)) + self.cursor.execute("SELECT * FROM `users` WHERE `status`='ban' AND `user_id`=%s", (user_id,)) result = self.cursor.fetchone() return result except mysql.connector.Error as err: diff --git a/handlers/admins/statistika/download_statistics.py b/handlers/admins/statistika/download_statistics.py index 6f8deeb..d64eca7 100755 --- a/handlers/admins/statistika/download_statistics.py +++ b/handlers/admins/statistika/download_statistics.py @@ -51,11 +51,11 @@ async def download_statistics(call: types.CallbackQuery, state: FSMContext): # Populate lists with user data for user in data: - id_list.append(user[0]) - user_ud_list.append(user[1]) - date_list.append(user[2]) - langs.append(user[3]) - user_info = await bot.get_chat(chat_id=user[1]) + id_list.append(user['id']) + user_ud_list.append(user['user_id']) + date_list.append(user['created_time']) + langs.append(user['language_code']) + user_info = await bot.get_chat(chat_id=user['user_id']) usernames.append(f'@{user_info.username}') # Create a DataFrame and save it to an Excel file diff --git a/main.py b/main.py index e9cc21a..5d65005 100755 --- a/main.py +++ b/main.py @@ -23,7 +23,6 @@ async def main(): try: file_db.add_data(False, key='ads') db.create_table_admins() # Create the admins table - db.create_table_ban() # Create the ban table db.create_table_users() # Create the users table db.create_table_channel() # Create the channel table except Exception as err: From 45c1c562674ad2d4dc547f8a199d5628651c8fb7 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Fri, 28 Feb 2025 10:01:16 +0500 Subject: [PATCH 18/71] Refactor channel handling in Database class: rename parameters for clarity and remove unused fields --- db/database.py | 10 ++++------ handlers/admins/channel_settings/channel_setting.py | 2 +- handlers/admins/channel_settings/delete_channel.py | 2 +- handlers/admins/channel_settings/get_id.py | 7 +++---- handlers/admins/channel_settings/remove_channel.py | 6 +++--- 5 files changed, 12 insertions(+), 15 deletions(-) diff --git a/db/database.py b/db/database.py index 1c707b5..c5c48f2 100755 --- a/db/database.py +++ b/db/database.py @@ -145,8 +145,6 @@ def create_table_admins(self): `block_user` TINYINT(1) DEFAULT 0, `channel_settings` TINYINT(1) DEFAULT 0, `add_admin` TINYINT(1) DEFAULT 0, - `set_data` TINYINT(1) DEFAULT 0, - `get_data` TINYINT(1) DEFAULT 0, `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); @@ -690,7 +688,7 @@ def select_channels_initiator_user_id(self, initiator_user_id): logging.error(err) - def check_channel(self, user_id): + def check_channel(self, channel_id): """ Check if a channel exists in the 'channels' table. @@ -701,7 +699,7 @@ def check_channel(self, user_id): tuple: The channel's information if it exists, None otherwise. """ try: - self.cursor.execute("SELECT * FROM `channels` WHERE `user_id`=%s", (user_id,)) + self.cursor.execute("SELECT * FROM `channels` WHERE `channel_id`=%s", (channel_id,)) result = self.cursor.fetchone() return result except mysql.connector.Error as err: @@ -734,7 +732,7 @@ def select_all_channel(self): ## -------------- Delete -------------- ## - def delete_channel(self, user_id): + def delete_channel(self, channel_id): """ Delete a channel from the 'channels' table. @@ -742,7 +740,7 @@ def delete_channel(self, user_id): user_id (int): The channel's ID. """ try: - self.cursor.execute("DELETE FROM `channels` WHERE `channel_id`=%s", (user_id,)) + self.cursor.execute("DELETE FROM `channels` WHERE `channel_id`=%s", (channel_id,)) except mysql.connector.Error as err: logging.error(err) self.reconnect() diff --git a/handlers/admins/channel_settings/channel_setting.py b/handlers/admins/channel_settings/channel_setting.py index 5e71efa..e8a19f1 100755 --- a/handlers/admins/channel_settings/channel_setting.py +++ b/handlers/admins/channel_settings/channel_setting.py @@ -44,7 +44,7 @@ async def channel_setting(call: types.CallbackQuery, state: FSMContext): data = db.select_channels() else: # Retrieve channels added by the current admin - data = db.select_channels_add_user_ud(add_user_ud=user_ud) + data = db.select_channels_initiator_user_id(initiator_user_id=user_ud) if not data: # If no channels are found, indicate that the list is empty diff --git a/handlers/admins/channel_settings/delete_channel.py b/handlers/admins/channel_settings/delete_channel.py index a809ba6..b797612 100755 --- a/handlers/admins/channel_settings/delete_channel.py +++ b/handlers/admins/channel_settings/delete_channel.py @@ -53,7 +53,7 @@ async def delete_channel(call: types.CallbackQuery, callback_data: AdminCallback if check[3] == user_ud or user_ud == ADMIN: # Delete the channel if the user is authorized - db.delete_channel(user_ud=ch_user_ud) + db.delete_channel(channel_id=ch_user_ud) tx = translator(text='🚫 Channel removed...\n', dest=lang) text = (f"{tx}\n" f"Name: {channel.full_name}\n" diff --git a/handlers/admins/channel_settings/get_id.py b/handlers/admins/channel_settings/get_id.py index 9afac39..c56157d 100755 --- a/handlers/admins/channel_settings/get_id.py +++ b/handlers/admins/channel_settings/get_id.py @@ -43,13 +43,12 @@ async def add_channel2(msg: types.Message, state: FSMContext): tx = msg.text # The text message containing the channel ID k_id = int(str(-100) + str(tx)) # Format the channel ID for API channel = await bot.get_chat(chat_id=k_id) # Get channel details using the Telegram API - check = db.check_channel(user_ud=tx) # Check if the channel is already in the database + check = db.check_channel(channel_id=tx) # Check if the channel is already in the database if check is None: # Add the channel to the database if it doesn't exist - db.insert_channel(user_ud=tx, - date=f'{yil_oy_kun} / {soat_minut_sekund}', - add_user_ud=user_ud) + db.insert_channel(channel_id=tx, + initiator_user_id=user_ud) text = translator(text="✅ The channel was successfully added\n", dest=lang) text += f"Name: {channel.full_name}\n" \ f"Username: @{channel.username}" diff --git a/handlers/admins/channel_settings/remove_channel.py b/handlers/admins/channel_settings/remove_channel.py index a5623fe..70a9219 100755 --- a/handlers/admins/channel_settings/remove_channel.py +++ b/handlers/admins/channel_settings/remove_channel.py @@ -45,7 +45,7 @@ async def remove_channel(call: types.CallbackQuery, state: FSMContext): if user_ud == ADMIN: data = db.select_channels() else: - data = db.select_channels_add_user_ud(add_user_ud=user_ud) + data = db.select_channels_initiator_user_id(initiator_user_id=user_ud) if not data: # Inform the admin if no channels are available @@ -58,10 +58,10 @@ async def remove_channel(call: types.CallbackQuery, state: FSMContext): for x in data: try: count += 1 - channel = await bot.get_chat(chat_id=str(-100) + str(x[1])) + channel = await bot.get_chat(chat_id=str(-100) + str(x['channel_id'])) # Add a button for each channel to the keyboard btn.button(text=f"{channel.full_name}: @{channel.username}", - callback_data=AdminCallback(action="delete_channel", data=str(x[1])).pack()) + callback_data=AdminCallback(action="delete_channel", data=str(x['channel_id'])).pack()) text += (f"{count}. Name: {channel.full_name}\n" f"Username: @{channel.username}\n" f"Added date: {x[2]}\n\n") From 1204a755ddef7752d7181850f446faf49c1b682c Mon Sep 17 00:00:00 2001 From: UznetDev Date: Fri, 28 Feb 2025 10:11:49 +0500 Subject: [PATCH 19/71] Refactor admin management: update parameter names for clarity, enhance database interactions, and improve language handling --- handlers/admins/admin_settings/add_admin.py | 2 +- handlers/admins/admin_settings/attach_admins.py | 16 ++++++++-------- keyboards/inline/admin_btn.py | 4 ++-- keyboards/inline/button.py | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/handlers/admins/admin_settings/add_admin.py b/handlers/admins/admin_settings/add_admin.py index 01a7291..98880e5 100755 --- a/handlers/admins/admin_settings/add_admin.py +++ b/handlers/admins/admin_settings/add_admin.py @@ -53,7 +53,7 @@ async def add_admin(msg: types.Message, state: FSMContext): # Add the new admin to the database db.insert_admin(user_ud=user_id, date=f"{yil_oy_kun} / {soat_minut_sekund}", - add=user_ud) + initiator_user_id=user_ud) text = translator(text="✅ Admin has been successfully added\n\nName: ", dest=lang) text += f"{user.full_name}\n" diff --git a/handlers/admins/admin_settings/attach_admins.py b/handlers/admins/admin_settings/attach_admins.py index cd14353..2266c06 100755 --- a/handlers/admins/admin_settings/attach_admins.py +++ b/handlers/admins/admin_settings/attach_admins.py @@ -23,7 +23,7 @@ async def attach_admins(call: types.CallbackQuery, callback_data: AdminSetting, - state (FSMContext): The FSM context for managing the bot's conversation state. Functionality: - - Extracts the admin's ID (`user_ud`), message ID (`mid`), language code (`lang`), and the target admin ID (`admin_user_ud`). + - Extracts the admin's ID (`user_ud`), message ID (`mid`), language_codeuage code (`language_code`), and the target admin ID (`admin_user_ud`). - Checks if the current admin has the right to modify admin settings. - If permitted, fetches the target admin's data and checks the permissions of the current admin. - Constructs a response message detailing the target admin's rights. @@ -39,18 +39,18 @@ async def attach_admins(call: types.CallbackQuery, callback_data: AdminSetting, try: user_ud = call.from_user.id # Current admin's ID mid = call.message.message_id # Message ID to be updated - lang = call.from_user.language_code # Admin's language preference - admin_user_ud = callback_data.user_ud # ID of the admin to be modified + language_code = call.from_user.language_code # Admin's language_codeuage preference + admin_user_id = callback_data.user_id # ID of the admin to be modified data = SelectAdmin(user_ud=user_ud) # Fetches the current admin's data btn = close_btn() # Default button to close the operation # Check if the admin has rights to add another admin if data.add_admin(): - admin_data = db.select_admin(user_ud=admin_user_ud) # Fetch data for the target admin + admin_data = db.select_admin(user_ud=admin_user_id) # Fetch data for the target admin if admin_data[2] == user_ud or user_ud == ADMIN: # If the current admin added the target admin or is the primary admin - btn = attach_admin_btn(user_ud=admin_user_ud, lang=lang) # Buttons for setting admin rights - is_admin = SelectAdmin(user_ud=admin_user_ud) # Check target admin's permissions + btn = attach_admin_btn(user_ud=admin_user_id, language_code=language_code) # Buttons for setting admin rights + is_admin = SelectAdmin(user_ud=admin_user_id) # Check target admin's permissions # Format the text showing current permissions of the target admin send_message_tx = x_or_y(is_admin.send_message()) @@ -70,10 +70,10 @@ async def attach_admins(call: types.CallbackQuery, callback_data: AdminSetting, f'Date added: ' else: # If the current admin does not have the right to modify the target admin - text = translator(text='😪You can only change the admin rights you added!', dest=lang) + text = translator(text='😪You can only change the admin rights you added!', dest=language_code) else: # If the current admin does not have the necessary rights - text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) + text = translator(text='❌ Unfortunately, you do not have this right!', dest=language_code) # Update the message with the admin rights information or error message await bot.edit_message_text(chat_id=user_ud, message_id=mid, text=f'{text}', reply_markup=btn) diff --git a/keyboards/inline/admin_btn.py b/keyboards/inline/admin_btn.py index 25066ee..11b76b1 100644 --- a/keyboards/inline/admin_btn.py +++ b/keyboards/inline/admin_btn.py @@ -103,7 +103,7 @@ async def admin_setting(user_ud, lang): data = db.select_add_admin(user_ud=user_ud) if data is not None: for x in data: - info = await bot.get_chat(chat_id=x[1]) + info = await bot.get_chat(chat_id=x['user_ud']) btn.button(text=f"👮‍♂️ @{info.username}: {info.full_name}!", callback_data=AdminSetting(action="attach_admin", user_ud=x[1]).pack()) btn.button(text=translator(text=f"👮‍♂️ ADD Admin!", @@ -304,7 +304,7 @@ def block_user(user_ud, lang, user_id): dest=lang), callback_data=BlockUser(action="block", user_ud=user_id).pack()) else: - if data[2] == user_ud or user_ud == ADMIN: + if (data['initiator_user_id'] == user_ud or data['updater_user_id'] == user_ud) or user_ud == ADMIN: btn.button(text=translator(text=f"✅Unblock user!", dest=lang), callback_data=BlockUser(action="block", user_ud=user_id).pack()) diff --git a/keyboards/inline/button.py b/keyboards/inline/button.py index 1695f9b..3786ad8 100644 --- a/keyboards/inline/button.py +++ b/keyboards/inline/button.py @@ -44,7 +44,7 @@ class AdminSetting(CallbackData, prefix="admin_setting"): user_ud (int): The ID of the admin or user related to the setting. """ action: str - user_ud: int + user_id: int class BlockUser(CallbackData, prefix="block_user"): """ From db6d93760cdca01878e6e30d13b484207dbae63a Mon Sep 17 00:00:00 2001 From: UznetDev Date: Fri, 28 Feb 2025 10:26:46 +0500 Subject: [PATCH 20/71] Refactor users table: change status field to ENUM, add ban_time column, and implement ban_user_for_one_hour method for temporary bans --- db/database.py | 40 +++++++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/db/database.py b/db/database.py index c5c48f2..3731cc6 100755 --- a/db/database.py +++ b/db/database.py @@ -85,13 +85,14 @@ def create_table_users(self): sql = """ CREATE TABLE IF NOT EXISTS `users` ( `id` INT AUTO_INCREMENT PRIMARY KEY, - `user_id` bigint(200) NOT NULL UNIQUE, - `status` VARCHAR(255) IN ('remove', 'active', 'blocked', 'ban', 'unban', 'sleep', 'active') DEFAULT 'active', - `initiator_user_id` bigint(200), - `updater_user_id` bigint(200), + `user_id` BIGINT NOT NULL UNIQUE, + `status` ENUM('remove', 'active', 'blocked', 'ban', 'unban', 'sleep') DEFAULT 'active', + `initiator_user_id` BIGINT, + `updater_user_id` BIGINT, + `ban_time` TIMESTAMP NULL DEFAULT NULL, `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - `language_code` varchar(5) + `language_code` VARCHAR(5) ) """ self.cursor.execute(sql) @@ -183,6 +184,35 @@ def create_table_settings(self): logging.error(err) + ## ---------------- Scheduler --------------------- + def ban_user_for_one_hour(self, user_id): + try: + sql_update = """ + UPDATE users + SET status = 'ban', ban_time = NOW() + WHERE user_id = %s + """ + self.cursor.execute(sql_update, (user_id,)) + self.connection.commit() + event_name = f"unban_user_{user_id}" + sql_event = f""" + CREATE EVENT IF NOT EXISTS {event_name} + ON SCHEDULE AT DATE_ADD(NOW(), INTERVAL 1 HOUR) + DO + UPDATE users + SET status = 'active', ban_time = NULL + WHERE user_id = {user_id}; + """ + self.cursor.execute(sql_event) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(f"MySQL error: {err}") + self.reconnect() + except Exception as err: + logging.error(f"General error: {err}") + + + ## ------------------ Insert data ------------------ ## def insert_settings(self, initiator_user_id, key, value): From d1b8b35bd842219d93674e241f44ce3f33214564 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Fri, 28 Feb 2025 10:33:26 +0500 Subject: [PATCH 21/71] Refactor user handling: rename variables for clarity, fix SQL syntax, and improve parameter naming in various modules --- db/database.py | 2 +- filters/ban.py | 8 ++++---- handlers/users/start.py | 4 ++-- keyboards/inline/user.py | 4 ++-- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/db/database.py b/db/database.py index 3731cc6..60d7c70 100755 --- a/db/database.py +++ b/db/database.py @@ -405,7 +405,7 @@ def select_all_users_ban(self): """ try: sql = """ - SELECT * FROM `users` WHERE `status`='ban'` + SELECT * FROM `users` WHERE `status`='ban' """ self.cursor.execute(sql) result = self.cursor.fetchall() diff --git a/filters/ban.py b/filters/ban.py index 1fd1eb7..41fa753 100644 --- a/filters/ban.py +++ b/filters/ban.py @@ -27,12 +27,12 @@ async def __call__(self, message: Message) -> bool: bool: True if the user is banned, False otherwise. """ try: - self.user_ud = message.from_user.id - self.dada = db.select_admin(user_ud=self.user_ud) - check_ban = db.check_user_ban(user_ud=self.user_ud) + self.user_id = message.from_user.id + self.dada = db.select_admin(user_id=self.user_id) + check_ban = db.check_user_ban(user_id=self.user_id) # If the user is the super admin, they are not banned - if self.user_ud == self.super_admin: + if self.user_id == self.super_admin: return False # If the user is an admin, they are not banned elif self.dada is not None: diff --git a/handlers/users/start.py b/handlers/users/start.py index 411e9a1..9e492cf 100755 --- a/handlers/users/start.py +++ b/handlers/users/start.py @@ -44,7 +44,7 @@ async def start_handler(msg: types.Message): # Check and log the user if not already in the database if db.check_user(user_id) is None: - db.insert_user(user_id==user_id, - lang=user_language) + db.insert_user(user_id=user_id, + language_code=user_language) except Exception as err: logging.error(f"Error handling /start command: {err}") diff --git a/keyboards/inline/user.py b/keyboards/inline/user.py index 9a7a77e..10d3a06 100644 --- a/keyboards/inline/user.py +++ b/keyboards/inline/user.py @@ -3,7 +3,7 @@ from function.translator import translator -def send_url(url, lang): +def send_url(language_code, url): """ Creates an inline keyboard with a button to share a URL. @@ -18,7 +18,7 @@ def send_url(url, lang): try: btn = InlineKeyboardBuilder() btn.button( - text=translator(text='➕Share to friend', dest=lang), + text=translator(text='➕Share to friend', dest=language_code), url=f'https://t.me/share/url?url={url}' ) btn.adjust(1) From f8d871c8d2569d7bf6051bf43378d8e937527640 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Fri, 28 Feb 2025 10:37:16 +0500 Subject: [PATCH 22/71] Refactor admin handling: rename user_ud to user_id for consistency and clarity, update file handling to use FSInputFile for Excel and log files, and improve inline keyboard function parameter naming --- .gitignore | 3 ++- handlers/admins/main_panel.py | 8 ++++---- handlers/admins/super_admin.py | 26 +++++++++++++++----------- keyboards/inline/admin_btn.py | 4 ++-- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 96b745d..9bc3142 100755 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ __pycache__/* *.json /logs/* /logs/ -*.log \ No newline at end of file +*.log +*.xls \ No newline at end of file diff --git a/handlers/admins/main_panel.py b/handlers/admins/main_panel.py index 23b4163..2d22d34 100755 --- a/handlers/admins/main_panel.py +++ b/handlers/admins/main_panel.py @@ -27,7 +27,7 @@ async def main_panel(msg: types.Message, state: FSMContext): Exception: Logs any errors encountered during the process. """ try: - user_ud = msg.from_user.id + user_id = msg.from_user.id message_id = msg.message_id lang = msg.from_user.language_code @@ -35,13 +35,13 @@ async def main_panel(msg: types.Message, state: FSMContext): welcome_text = translator(text=f'👩‍💻Hello, dear admin, welcome to the main panel!', dest=lang) response_msg = await msg.answer(text=f'{welcome_text}', - reply_markup=main_admin_panel_btn(user_ud=user_ud, lang=lang)) + reply_markup=main_admin_panel_btn(user_id=user_id, lang=lang)) # Manage previous message state_data = await state.get_data() try: if 'message_id' in state_data and state_data['message_id'] > 1: - await bot.delete_message(chat_id=user_ud, message_id=state_data['message_id']) + await bot.delete_message(chat_id=user_id, message_id=state_data['message_id']) except Exception as err: logging.error(f"Error deleting previous message: {err}") @@ -51,7 +51,7 @@ async def main_panel(msg: types.Message, state: FSMContext): }) # Delete the original command message - await bot.delete_message(chat_id=user_ud, message_id=message_id) + await bot.delete_message(chat_id=user_id, message_id=message_id) except Exception as err: logging.error(f"Unhandled error: {err}") diff --git a/handlers/admins/super_admin.py b/handlers/admins/super_admin.py index 5ef361a..671f756 100755 --- a/handlers/admins/super_admin.py +++ b/handlers/admins/super_admin.py @@ -6,6 +6,7 @@ from data.config import log_file_name from filters.admin import IsSuperAdmin from loader import dp, bot, db +from aiogram.types import FSInputFile @dp.message(IsSuperAdmin(), Command(commands='stat')) @@ -70,11 +71,13 @@ async def super_admin(msg: types.Message): excel_path = 'data/ban.xlsx' df.to_excel(excel_path, index=False) - # Sending the generated Excel file - document = types.InputFile(excel_path) - await bot.send_document(chat_id=user_ud, - document=document, - caption='Ban list') + # Sending the generated Excel file using FSInputFile + document = FSInputFile(excel_path) + await bot.send_document( + chat_id=user_ud, + document=document, + caption='Ban list' + ) os.remove(excel_path) except Exception as err: @@ -83,10 +86,12 @@ async def super_admin(msg: types.Message): try: # Sending the log file if it exists if os.path.exists(log_file_name) and os.path.getsize(log_file_name) > 0: - document2 = types.InputFile(log_file_name) - await bot.send_document(chat_id=user_ud, - document=document2, - caption='Update log') + document2 = FSInputFile(log_file_name) + await bot.send_document( + chat_id=user_ud, + document=document2, + caption='Update log' + ) except Exception as err: logging.error(f"Error sending log file: {err}") @@ -94,5 +99,4 @@ async def super_admin(msg: types.Message): await bot.delete_message(chat_id=user_ud, message_id=mid) except Exception as err: - logging.error(f"Unhandled error: {err}") - + logging.error(f"Unhandled error: {err}") \ No newline at end of file diff --git a/keyboards/inline/admin_btn.py b/keyboards/inline/admin_btn.py index 11b76b1..e1c0fbd 100644 --- a/keyboards/inline/admin_btn.py +++ b/keyboards/inline/admin_btn.py @@ -30,7 +30,7 @@ def main_btn(): return False -def main_admin_panel_btn(user_ud, lang): +def main_admin_panel_btn(user_id, lang): """ Creates the inline keyboard for the main admin panel. @@ -50,7 +50,7 @@ def main_admin_panel_btn(user_ud, lang): btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = SelectAdmin(user_ud=user_ud) + is_admin = SelectAdmin(user_id=user_id) if is_admin.add_admin(): btn.button(text=translator(text=f"👮‍♂️ Admins settings!", dest=lang), From 3491aeb5956db78ef5225de47783027e32c42632 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Fri, 28 Feb 2025 10:40:45 +0500 Subject: [PATCH 23/71] Refactor super_admin and check_usr handlers: rename user_ud to user_id for consistency and clarity in user identification --- handlers/admins/super_admin.py | 8 ++++---- handlers/users/check_usr.py | 5 ++--- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/handlers/admins/super_admin.py b/handlers/admins/super_admin.py index 671f756..b32cc0e 100755 --- a/handlers/admins/super_admin.py +++ b/handlers/admins/super_admin.py @@ -37,7 +37,7 @@ async def super_admin(msg: types.Message): """ try: logging.info('Generating stats report') - user_ud = msg.from_user.id + user_id = msg.from_user.id mid = msg.message_id data = db.select_all_users_ban() @@ -74,7 +74,7 @@ async def super_admin(msg: types.Message): # Sending the generated Excel file using FSInputFile document = FSInputFile(excel_path) await bot.send_document( - chat_id=user_ud, + chat_id=user_id, document=document, caption='Ban list' ) @@ -88,7 +88,7 @@ async def super_admin(msg: types.Message): if os.path.exists(log_file_name) and os.path.getsize(log_file_name) > 0: document2 = FSInputFile(log_file_name) await bot.send_document( - chat_id=user_ud, + chat_id=user_id, document=document2, caption='Update log' ) @@ -96,7 +96,7 @@ async def super_admin(msg: types.Message): logging.error(f"Error sending log file: {err}") # Deleting the original message - await bot.delete_message(chat_id=user_ud, message_id=mid) + await bot.delete_message(chat_id=user_id, message_id=mid) except Exception as err: logging.error(f"Unhandled error: {err}") \ No newline at end of file diff --git a/handlers/users/check_usr.py b/handlers/users/check_usr.py index 6d27eb3..6da05bf 100755 --- a/handlers/users/check_usr.py +++ b/handlers/users/check_usr.py @@ -59,9 +59,8 @@ async def start_handler(msg: types.Message): await msg.answer(text=f"{message_text}", reply_markup=keyboard.as_markup()) # Add user to the database if not already present - if db.check_user(user_ud=user_id) is None: - db.insert_user(user_ud=user_id, - date=f"{date_day_month} / {time_hour_minute_second}") + if db.check_user(user_id=user_id) is None: + db.insert_user(user_id=user_id, language_code=language_code) except Exception as err: logging.error(f"Error in start_handler: {err}") From 804c82f112ea144f8621a8431f0ca15dd946e791 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Fri, 28 Feb 2025 10:52:20 +0500 Subject: [PATCH 24/71] Refactor user identification: rename user_ud to user_id for consistency across admin handling and related modules --- handlers/admins/check_usr/attach_usr.py | 24 ++++++------- handlers/admins/check_usr/block_users.py | 34 +++++++++++-------- handlers/admins/check_usr/check_usr.py | 2 +- handlers/admins/check_usr/send_ads_message.py | 2 +- handlers/admins/check_usr/send_message.py | 4 +-- keyboards/inline/admin_btn.py | 12 +++---- keyboards/inline/button.py | 4 +-- 7 files changed, 43 insertions(+), 39 deletions(-) diff --git a/handlers/admins/check_usr/attach_usr.py b/handlers/admins/check_usr/attach_usr.py index 17f50eb..17d562a 100755 --- a/handlers/admins/check_usr/attach_usr.py +++ b/handlers/admins/check_usr/attach_usr.py @@ -31,26 +31,26 @@ async def attach_user(msg: types.Message, state: FSMContext): None """ try: - user_ud = msg.from_user.id # Chat ID of the admin + user_id = msg.from_user.id # Chat ID of the admin mid = msg.message_id # Message ID of the current message lang = msg.from_user.language_code # Language code of the admin - is_admin = SelectAdmin(user_ud=user_ud) # Check admin permissions - user_id = int(msg.text) # Extract user ID from the message + is_admin = SelectAdmin(user_id=user_id) # Check admin permissions + attention_user_id = int(msg.text) # Extract user ID from the message btn = close_btn() # Initialize the close button text = translator(text="🔴 Something went wrong!\n", dest=lang) # Default error message if is_admin.block_user(): data_state = await state.get_data() # Get the current state data try: - user = await bot.get_chat(chat_id=user_id) # Get user information - check = db.check_user_ban(user_ud=user_id) # Check if the user is banned - check1 = db.check_user(user_ud=user_id) # Check if the user exists in the bot's list + user = await bot.get_chat(chat_id=attention_user_id) # Get user information + check = db.check_user_ban(user_id=attention_user_id) # Check if the user is banned + check1 = db.check_user(user_id=attention_user_id) # Check if the user exists in the bot's list if check1 is not None: - btn = block_user(user_ud=user_ud, user_id=user_id, lang=lang) # Button for blocking/unblocking user + btn = block_user(attention_user_id=attention_user_id, user_id=user_id, lang=lang) # Button for blocking/unblocking user if check is None: - check2 = db.select_admin(user_ud=user_id) # Check if the user is an admin - select_user = db.check_user(user_ud) # Get information about the user + check2 = db.select_admin(user_ud=attention_user_id) # Check if the user is an admin + select_user = db.check_user(user_id) # Get information about the user if check2 is None: # User is successfully unblocked @@ -74,7 +74,7 @@ async def attach_user(msg: types.Message, state: FSMContext): text = translator(text="🔴 User not found!\nThe bot may not have found the user..", dest=lang) finally: # Update the message with the result and provide the close button - await bot.edit_message_text(chat_id=user_ud, + await bot.edit_message_text(chat_id=user_id, message_id=data_state['message_id'], text=f'{text}', reply_markup=btn) @@ -83,12 +83,12 @@ async def attach_user(msg: types.Message, state: FSMContext): text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) # Edit the original message to reflect the result - await bot.edit_message_text(chat_id=user_ud, + await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f'{text}', reply_markup=btn) await state.update_data({"message_id": mid}) # Update state data - await bot.delete_message(chat_id=user_ud, message_id=mid) # Delete the original message + await bot.delete_message(chat_id=user_id, message_id=mid) # Delete the original message except Exception as err: # Log any exceptions that occur logging.error(err) diff --git a/handlers/admins/check_usr/block_users.py b/handlers/admins/check_usr/block_users.py index 756a84b..afd33a9 100755 --- a/handlers/admins/check_usr/block_users.py +++ b/handlers/admins/check_usr/block_users.py @@ -35,33 +35,35 @@ async def block_users(call: types.CallbackQuery, callback_data: BlockUser, state - This function is asynchronous and does not return a value but performs actions such as sending messages and updating states. """ try: - user_id = callback_data.user_ud # The ID of the user to be blocked/unblocked - user_ud = call.from_user.id # The ID of the admin issuing the block/unblock command + attention_user_id = callback_data.user_id # The ID of the user to be blocked/unblocked + user_id = call.from_user.id # The ID of the admin issuing the block/unblock command mid = call.message.message_id # The ID of the message triggering the callback lang = call.from_user.language_code # The language code of the admin for message translation - data = SelectAdmin(user_ud=user_ud) # Check if the admin is authorized to perform the action + data = SelectAdmin(user_id=user_id) # Check if the admin is authorized to perform the action btn = close_btn() # Inline button to close the message if data.block_user(): - check1 = db.select_admin(user_ud=user_id) # Check if the user is an admin + check1 = db.select_admin(user_id=attention_user_id) # Check if the user is an admin if check1 is None: - check = db.check_user_ban(user_ud=user_id) # Check if the user is already banned - user = await bot.get_chat(chat_id=user_id) # Get user details + check = db.check_user_ban(user_id=attention_user_id) # Check if the user is already banned + user = await bot.get_chat(chat_id=attention_user_id) # Get user details if check is None: - db.insert_user_ban(user_ud=user_id, - admin_user_ud=user_ud, - date=f'{yil_oy_kun} / {soat_minut_sekund}') # Add user to ban list + db.update_user_status(user_id=attention_user_id, + status='blocked', + updater_user_id=user_id) # Update user status to blocked text = translator(text='⛔ User blocked\n\n Username: @', dest=lang) text += str(user.username) - await bot.send_message(chat_id=user_id, + await bot.send_message(chat_id=attention_user_id, text='🚫 You are blocked! If you think this is a mistake, contact the admin.', reply_markup=close_btn()) # Notify the user of the block else: - if check[2] == user_ud or user_ud == ADMIN: # Check if the unblocking is authorized - db.delete_user_ban(user_ud=user_id) # Remove user from ban list + if check['initiator_user_id'] == user_id or check['updater_user_id'] == user_id or user_id == ADMIN: # Check if the unblocking is authorized + db.update_user_status(user_id=attention_user_id, + status='active', + updater_user_id=user_id) # Update user status to active text = translator(text='✅ User unblocked!\n\n Username: @', dest=lang) text += str(user.username) - await bot.send_message(chat_id=user_id, + await bot.send_message(chat_id=attention_user_id, text='😊 You are unblocked! Contact the admin.', reply_markup=close_btn()) # Notify the user of the unblock else: @@ -70,13 +72,15 @@ async def block_users(call: types.CallbackQuery, callback_data: BlockUser, state else: text = translator(text='🚫 I cannot block an admin.', dest=lang) try: - db.delete_user_ban(user_ud=user_id) # Ensure user is not mistakenly banned + db.update_user_status(user_id=attention_user_id, + status='active', + updater_user_id=user_id) # Ensure user is not mistakenly blocked except Exception as err: logging.error(err) # Log any errors encountered await state.set_state(AdminState.check_user) # Update the FSM state else: text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) - await bot.edit_message_text(chat_id=user_ud, + await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f'{text}', reply_markup=btn) # Edit the original message with the result diff --git a/handlers/admins/check_usr/check_usr.py b/handlers/admins/check_usr/check_usr.py index 8cacf0a..c426b1c 100755 --- a/handlers/admins/check_usr/check_usr.py +++ b/handlers/admins/check_usr/check_usr.py @@ -33,7 +33,7 @@ async def check_user(call: types.CallbackQuery, state: FSMContext): user_id = call.from_user.id # The ID of the admin initiating the check message_id = call.message.message_id # The ID of the message triggering the callback language = call.from_user.language_code # The language code of the admin for message translation - data = SelectAdmin(user_ud=user_id) # Check if the admin is authorized to perform the action + data = SelectAdmin(user_id=user_id) # Check if the admin is authorized to perform the action button = close_btn() # Inline button to close the message if data.block_user(): diff --git a/handlers/admins/check_usr/send_ads_message.py b/handlers/admins/check_usr/send_ads_message.py index 110d954..c05c312 100755 --- a/handlers/admins/check_usr/send_ads_message.py +++ b/handlers/admins/check_usr/send_ads_message.py @@ -32,7 +32,7 @@ async def send_ads_message(msg: types.Message, state: FSMContext): language = msg.from_user.language_code # The language code of the admin for message translation data_state = await state.get_data() # Retrieve data from the FSM context target_user_id = data_state['user_id'] # The ID of the target user who will receive the message - is_admin = SelectAdmin(user_ud=user_id) # Check if the admin is authorized to send messages + is_admin = SelectAdmin(user_id=user_id) # Check if the admin is authorized to send messages button = close_btn() # Inline button to close the message if is_admin.send_message(): diff --git a/handlers/admins/check_usr/send_message.py b/handlers/admins/check_usr/send_message.py index 7ae12c6..6cf0309 100755 --- a/handlers/admins/check_usr/send_message.py +++ b/handlers/admins/check_usr/send_message.py @@ -31,11 +31,11 @@ async def send_message(call: types.CallbackQuery, callback_data: BlockUser, stat - This function is asynchronous and does not return a value but performs actions such as sending messages and updating states. """ try: - target_user_id = callback_data.user_ud # The ID of the user to whom the message will be sent + target_user_id = callback_data.user_id # The ID of the user to whom the message will be sent user_id = call.from_user.id # The ID of the admin initiating the message send action message_id = call.message.message_id # The ID of the message triggering the callback language = call.from_user.language_code # The language code of the admin for message translation - admin_check = SelectAdmin(user_ud=user_id) # Check if the admin has permission to send messages + admin_check = SelectAdmin(user_id=user_id) # Check if the admin has permission to send messages button = close_btn() # Inline button to close the message if admin_check.send_message(): diff --git a/keyboards/inline/admin_btn.py b/keyboards/inline/admin_btn.py index e1c0fbd..67bfe75 100644 --- a/keyboards/inline/admin_btn.py +++ b/keyboards/inline/admin_btn.py @@ -275,7 +275,7 @@ def channel_settings(lang): return False -def block_user(user_ud, lang, user_id): +def block_user(attention_user_id, lang, user_id): """ Creates the inline keyboard for blocking or unblocking a user. @@ -296,18 +296,18 @@ def block_user(user_ud, lang, user_id): btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = SelectAdmin(user_ud=user_ud) + is_admin = SelectAdmin(user_id=user_id) if is_admin.block_user(): - data = db.check_user_ban(user_ud=user_id) + data = db.check_user_ban(user_id=attention_user_id) if data is None: btn.button(text=translator(text=f"🚫Userni bloklash!", dest=lang), - callback_data=BlockUser(action="block", user_ud=user_id).pack()) + callback_data=BlockUser(action="block", user_id=attention_user_id).pack()) else: - if (data['initiator_user_id'] == user_ud or data['updater_user_id'] == user_ud) or user_ud == ADMIN: + if (data['initiator_user_id'] == user_id or data['updater_user_id'] == user_id) or user_id == ADMIN: btn.button(text=translator(text=f"✅Unblock user!", dest=lang), - callback_data=BlockUser(action="block", user_ud=user_id).pack()) + callback_data=BlockUser(action="block", user_id=user_id).pack()) btn.adjust(1, 2) btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) return btn.as_markup() diff --git a/keyboards/inline/button.py b/keyboards/inline/button.py index 3786ad8..1fc26dc 100644 --- a/keyboards/inline/button.py +++ b/keyboards/inline/button.py @@ -32,7 +32,7 @@ class EditAdminSetting(CallbackData, prefix="edit_setting"): data (str): The specific setting to be edited. """ action: str - user_ud: int + user_id: int data: str class AdminSetting(CallbackData, prefix="admin_setting"): @@ -55,4 +55,4 @@ class BlockUser(CallbackData, prefix="block_user"): user_ud (int): The ID of the user to be blocked or unblocked. """ action: str - user_ud: int + user_id: int From afce0587cd6ea836728bfa1d9801ec736ccc8647 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Fri, 28 Feb 2025 10:57:20 +0500 Subject: [PATCH 25/71] Refactor user identification: rename user_ud to user_id for consistency across admin handling in multiple modules --- handlers/admins/admin_settings/add_admin.py | 28 +++++++++---------- .../admin_settings/add_admin_first_step.py | 10 +++---- .../admins/admin_settings/admin_setting.py | 10 +++---- .../admins/admin_settings/attach_admins.py | 17 +++++------ .../admins/callback_query/main_admin_panel.py | 8 +++--- .../admins/channel_settings/add_channel.py | 14 +++++----- .../channel_settings/channel_setting.py | 12 ++++---- .../admins/channel_settings/delete_channel.py | 22 +++++++-------- handlers/admins/channel_settings/get_id.py | 10 +++---- .../channel_settings/mandatory_membership.py | 8 +++--- .../admins/channel_settings/remove_channel.py | 10 +++---- 11 files changed, 75 insertions(+), 74 deletions(-) diff --git a/handlers/admins/admin_settings/add_admin.py b/handlers/admins/admin_settings/add_admin.py index 98880e5..033ecb5 100755 --- a/handlers/admins/admin_settings/add_admin.py +++ b/handlers/admins/admin_settings/add_admin.py @@ -9,6 +9,7 @@ from states.admin_state import AdminState from data.config import yil_oy_kun, soat_minut_sekund + @dp.message(AdminState.add_admin, IsAdmin()) async def add_admin(msg: types.Message, state: FSMContext): """ @@ -19,7 +20,7 @@ async def add_admin(msg: types.Message, state: FSMContext): - state (FSMContext): The FSM context to manage the bot's state during the conversation. Functionality: - - Retrieves the admin's user ID (`user_ud`), the message ID (`mid`), and the language code (`lang`) from the message. + - Retrieves the admin's user ID (`user_id`), the message ID (`mid`), and the language code (`lang`) from the message. - Checks if the sender has the required permissions to add an admin. - Tries to add the new admin using the provided user ID: - If the admin is successfully added, sends a confirmation message to both the current admin and the newly added admin. @@ -33,36 +34,35 @@ async def add_admin(msg: types.Message, state: FSMContext): - Catches and logs any exceptions that occur during the addition of the new admin or message editing. """ try: - user_ud = msg.from_user.id # The ID of the admin who is performing the action + user_id = msg.from_user.id # The ID of the admin who is performing the action mid = msg.message_id # The ID of the message to be updated lang = msg.from_user.language_code # The language code for translation - data = SelectAdmin(user_ud=user_ud) # Retrieves admin settings for the current user + data = SelectAdmin(user_id=user_id) # Retrieves admin settings for the current user add_admin_db = data.add_admin() # Check if the user has the right to add an admin - user_id = int(msg.text) # The ID of the user to be added as an admin + target_user_id = int(msg.text) # The ID of the user to be added as an admin if add_admin_db: data_state = await state.get_data() # Get current state data - btn = await admin_setting(user_ud=user_ud, lang=lang) # Prepare admin settings buttons + btn = await admin_setting(user_id=user_id, lang=lang) # Prepare admin settings buttons text = "🔴 Admin failed because admin was not found!\n" try: - user = await bot.get_chat(chat_id=user_id) # Get user information - check = db.select_admin(user_ud=user_id) # Check if the user is already an admin + user = await bot.get_chat(chat_id=target_user_id) # Get user information + check = db.select_admin(user_id=target_user_id) # Check if the user is already an admin if check is None: # Add the new admin to the database - db.insert_admin(user_ud=user_id, - date=f"{yil_oy_kun} / {soat_minut_sekund}", - initiator_user_id=user_ud) + db.insert_admin(user_id=target_user_id, + initiator_user_id=user_id) text = translator(text="✅ Admin has been successfully added\n\nName: ", dest=lang) text += f"{user.full_name}\n" text += f'Username: @{user.username}\n' - await bot.send_message(chat_id=user_id, + await bot.send_message(chat_id=target_user_id, text=f'😊Hi @{user.username}, you have been made an admin\n' f'To open the panel, use /admin ', reply_markup=close_btn()) - btn = await admin_setting(user_ud=user_ud, lang=lang) # Prepare admin settings buttons + btn = await admin_setting(user_id=user_id, lang=lang) # Prepare admin settings buttons else: text = translator(text="✅ Admin was added before\n\nName: ", dest=lang) @@ -81,7 +81,7 @@ async def add_admin(msg: types.Message, state: FSMContext): finally: text = translator(text=text, dest=lang) - await bot.edit_message_text(chat_id=user_ud, + await bot.edit_message_text(chat_id=user_id, message_id=data_state['message_id'], text=text, reply_markup=btn) @@ -89,7 +89,7 @@ async def add_admin(msg: types.Message, state: FSMContext): text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) btn = close_btn() - await bot.edit_message_text(chat_id=user_ud, + await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f"{text}", reply_markup=btn) diff --git a/handlers/admins/admin_settings/add_admin_first_step.py b/handlers/admins/admin_settings/add_admin_first_step.py index 67e00c3..6da710d 100755 --- a/handlers/admins/admin_settings/add_admin_first_step.py +++ b/handlers/admins/admin_settings/add_admin_first_step.py @@ -19,7 +19,7 @@ async def add_admin_first(call: types.CallbackQuery, state: FSMContext): - state (FSMContext): The FSM context to manage the bot's state during the conversation. Functionality: - - Retrieves the ID of the admin who initiated the request (`user_ud`), the message ID (`mid`), and the language code (`lang`). + - Retrieves the ID of the admin who initiated the request (`user_id`), the message ID (`mid`), and the language code (`lang`). - Checks if the requesting admin has the rights to add a new admin. - If the requesting admin has the necessary permissions, prompts them to send the ID of the new admin to be added. - Sets the state to `AdminState.add_admin` to handle the next step of the process. @@ -33,16 +33,16 @@ async def add_admin_first(call: types.CallbackQuery, state: FSMContext): - Catches and logs any exceptions that occur during the process of handling the callback query or updating the message. """ try: - user_ud = call.from_user.id # ID of the admin initiating the request + user_id = call.from_user.id # ID of the admin initiating the request mid = call.message.message_id # ID of the message to be updated lang = call.from_user.language_code # Language code for translation - data = SelectAdmin(user_ud=user_ud) # Retrieves admin settings for the current user + data = SelectAdmin(user_id=user_id) # Retrieves admin settings for the current user add_admin = data.add_admin() # Checks if the user has the right to add an admin if add_admin: # Prompt the user to provide the ID of the new admin text = translator(text="🔰 Please send the admin ID number you want to add...", dest=lang) - btn = await admin_setting(user_ud=user_ud, lang=lang) # Prepare admin settings buttons + btn = await admin_setting(user_id=user_id, lang=lang) # Prepare admin settings buttons await state.set_state(AdminState.add_admin) # Set the FSM state for adding an admin else: # Inform the user that they do not have the necessary permissions @@ -50,7 +50,7 @@ async def add_admin_first(call: types.CallbackQuery, state: FSMContext): btn = close_btn() # Prepare close button # Update the message with the appropriate response and buttons - await bot.edit_message_text(chat_id=user_ud, + await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f'{text}', reply_markup=btn) diff --git a/handlers/admins/admin_settings/admin_setting.py b/handlers/admins/admin_settings/admin_setting.py index cb422a5..dc6686a 100755 --- a/handlers/admins/admin_settings/admin_setting.py +++ b/handlers/admins/admin_settings/admin_setting.py @@ -18,7 +18,7 @@ async def admin_settings(call: types.CallbackQuery, state: FSMContext): - state (FSMContext): The FSM context to manage the bot's state during the conversation. Functionality: - - Retrieves the ID of the admin (`user_ud`), the message ID (`mid`), and the language code (`lang`). + - Retrieves the ID of the admin (`user_id`), the message ID (`mid`), and the language code (`lang`). - Checks if the admin has the permissions to access the Admin settings. - If permissions are granted, presents the admin with the settings options. - If permissions are denied, informs the admin that they lack the necessary rights. @@ -31,23 +31,23 @@ async def admin_settings(call: types.CallbackQuery, state: FSMContext): - Catches and logs any exceptions that occur during the process of handling the callback query or updating the message. """ try: - user_ud = call.from_user.id # ID of the admin initiating the request + user_id = call.from_user.id # ID of the admin initiating the request mid = call.message.message_id # ID of the message to be updated lang = call.from_user.language_code # Language code for translation - data = SelectAdmin(user_ud=user_ud) # Retrieves admin settings for the current user + data = SelectAdmin(user_id=user_id) # Retrieves admin settings for the current user add_admin = data.add_admin() # Checks if the user has the right to access admin settings if add_admin: # The admin has the right to access settings text = translator(text="❗ You are in the Admin settings section!", dest=lang) - btn = await admin_setting(user_ud=user_ud, lang=lang) # Prepare admin settings buttons + btn = await admin_setting(user_id=user_id, lang=lang) # Prepare admin settings buttons else: # The admin does not have the necessary rights text = translator(text="❌ Unfortunately, you do not have this right!", dest=lang) btn = close_btn() # Prepare close button # Update the message with the appropriate response and buttons - await bot.edit_message_text(chat_id=user_ud, + await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f'{text}', reply_markup=btn) diff --git a/handlers/admins/admin_settings/attach_admins.py b/handlers/admins/admin_settings/attach_admins.py index 2266c06..fb03c68 100755 --- a/handlers/admins/admin_settings/attach_admins.py +++ b/handlers/admins/admin_settings/attach_admins.py @@ -23,7 +23,7 @@ async def attach_admins(call: types.CallbackQuery, callback_data: AdminSetting, - state (FSMContext): The FSM context for managing the bot's conversation state. Functionality: - - Extracts the admin's ID (`user_ud`), message ID (`mid`), language_codeuage code (`language_code`), and the target admin ID (`admin_user_ud`). + - Extracts the admin's ID (`user_id`), message ID (`mid`), language_codeuage code (`language_code`), and the target admin ID (`admin_user_id`). - Checks if the current admin has the right to modify admin settings. - If permitted, fetches the target admin's data and checks the permissions of the current admin. - Constructs a response message detailing the target admin's rights. @@ -37,20 +37,21 @@ async def attach_admins(call: types.CallbackQuery, callback_data: AdminSetting, - Catches and logs any exceptions that occur during the execution of the function. """ try: - user_ud = call.from_user.id # Current admin's ID + user_id = call.from_user.id # Current admin's ID mid = call.message.message_id # Message ID to be updated language_code = call.from_user.language_code # Admin's language_codeuage preference admin_user_id = callback_data.user_id # ID of the admin to be modified - data = SelectAdmin(user_ud=user_ud) # Fetches the current admin's data + data = SelectAdmin(user_id=user_id) # Fetches the current admin's data btn = close_btn() # Default button to close the operation # Check if the admin has rights to add another admin if data.add_admin(): - admin_data = db.select_admin(user_ud=admin_user_id) # Fetch data for the target admin - if admin_data[2] == user_ud or user_ud == ADMIN: + admin_data = db.select_admin(user_id=admin_user_id) # Fetch data for the target admin + if admin_data['initiator_user_id'] == user_id or user_id == ADMIN: # If the current admin added the target admin or is the primary admin - btn = attach_admin_btn(user_ud=admin_user_id, language_code=language_code) # Buttons for setting admin rights - is_admin = SelectAdmin(user_ud=admin_user_id) # Check target admin's permissions + btn = attach_admin_btn(user_id=admin_user_id, + language_code=language_code) # Buttons for setting admin rights + is_admin = SelectAdmin(user_id=admin_user_id) # Check target admin's permissions # Format the text showing current permissions of the target admin send_message_tx = x_or_y(is_admin.send_message()) @@ -76,7 +77,7 @@ async def attach_admins(call: types.CallbackQuery, callback_data: AdminSetting, text = translator(text='❌ Unfortunately, you do not have this right!', dest=language_code) # Update the message with the admin rights information or error message - await bot.edit_message_text(chat_id=user_ud, message_id=mid, text=f'{text}', reply_markup=btn) + await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f'{text}', reply_markup=btn) await state.set_state(AdminState.add_admin) # Set the state to add admin await state.update_data({"message_id": call.message.message_id}) # Update the state data with the message ID except Exception as err: diff --git a/handlers/admins/callback_query/main_admin_panel.py b/handlers/admins/callback_query/main_admin_panel.py index ac1b392..259f6a2 100755 --- a/handlers/admins/callback_query/main_admin_panel.py +++ b/handlers/admins/callback_query/main_admin_panel.py @@ -18,7 +18,7 @@ async def main_panel(call: types.CallbackQuery, state: FSMContext): - state (FSMContext): The FSM context to manage the bot's state during the conversation. Functionality: - - Retrieves the admin's user ID (`user_ud`), the message ID (`mid`), and the language code (`lang`) from the callback query. + - Retrieves the admin's user ID (`user_id`), the message ID (`mid`), and the language code (`lang`) from the callback query. - Translates a greeting message to the admin in their preferred language. - Edits the original message in the chat to display the translated greeting and the main admin panel buttons. - Updates the FSM state with the current message ID. @@ -30,7 +30,7 @@ async def main_panel(call: types.CallbackQuery, state: FSMContext): - Catches and logs any exceptions that occur during the execution, ensuring that errors are recorded for debugging. """ try: - user_ud = call.from_user.id # The ID of the admin who initiated the action + user_id = call.from_user.id # The ID of the admin who initiated the action mid = call.message.message_id # The ID of the message to be updated lang = call.from_user.language_code # The language code for translation @@ -38,10 +38,10 @@ async def main_panel(call: types.CallbackQuery, state: FSMContext): text = translator(text="👩‍💻Hello, dear admin, welcome to the main panel!", dest=lang) # Edit the message with the translated text and update it with the main admin panel buttons - await bot.edit_message_text(chat_id=user_ud, + await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f'{text}', - reply_markup=main_admin_panel_btn(user_ud=user_ud, lang=lang)) + reply_markup=main_admin_panel_btn(user_id=user_id, lang=lang)) # Update FSM state with the current message ID await state.update_data({"message_id": call.message.message_id}) diff --git a/handlers/admins/channel_settings/add_channel.py b/handlers/admins/channel_settings/add_channel.py index 3f05b92..ec882e0 100755 --- a/handlers/admins/channel_settings/add_channel.py +++ b/handlers/admins/channel_settings/add_channel.py @@ -18,7 +18,7 @@ async def add_channel(call: types.CallbackQuery, state: FSMContext): - state (FSMContext): Finite State Machine context used to manage the current state of the admin. Functionality: - - Retrieves the admin's ID, message ID, and language code from the callback query. + - Retrieves the admin's ID, message ID, and language_codeuage code from the callback query. - Checks if the admin has the necessary permissions to add a channel using the `SelectAdmin` filter. - If authorized, prompts the admin to send the channel ID and updates the admin's state to `AdminState.add_channel`. - If not authorized, sends a message indicating that the admin lacks the necessary permissions. @@ -29,23 +29,23 @@ async def add_channel(call: types.CallbackQuery, state: FSMContext): - This function is asynchronous and does not return a value but performs actions such as sending messages and updating states. """ try: - user_ud = call.from_user.id # The ID of the admin initiating the action + user_id = call.from_user.id # The ID of the admin initiating the action mid = call.message.message_id # The ID of the message triggering the callback - lang = call.from_user.language_code # The language code of the admin for message translation - data = SelectAdmin(user_ud=user_ud) # Check if the admin has permission to manage channel settings + language_code = call.from_user.language_code # The language_codeuage code of the admin for message translation + data = SelectAdmin(user_id=user_id) # Check if the admin has permission to manage channel settings btn = close_btn() # Inline button to close the message if data.channel_settings(): # If the admin is authorized, prompt for the channel ID await state.set_state(AdminState.add_channel) # Set the FSM state for adding a channel - text = translator(text="😊 Please send the channel id...", dest=lang) + text = translator(text="😊 Please send the channel id...", dest=language_code) await state.update_data({"message_id": call.message.message_id}) # Save the message ID in the FSM context else: # Inform the admin that they do not have the necessary permissions - text = translator(text="❌ Unfortunately, you do not have this right!", dest=lang) + text = translator(text="❌ Unfortunately, you do not have this right!", dest=language_code) await bot.edit_message_text( - chat_id=user_ud, + chat_id=user_id, message_id=mid, text=f'{text}', reply_markup=btn # Update the message with a translated response diff --git a/handlers/admins/channel_settings/channel_setting.py b/handlers/admins/channel_settings/channel_setting.py index e8a19f1..9dea8fb 100755 --- a/handlers/admins/channel_settings/channel_setting.py +++ b/handlers/admins/channel_settings/channel_setting.py @@ -32,19 +32,19 @@ async def channel_setting(call: types.CallbackQuery, state: FSMContext): - This function is asynchronous and does not return a value but performs actions such as sending messages and updating states. """ try: - user_ud = call.from_user.id # The ID of the admin initiating the action + user_id = call.from_user.id # The ID of the admin initiating the action mid = call.message.message_id # The ID of the message triggering the callback lang = call.from_user.language_code # The language code of the admin for message translation - data = SelectAdmin(user_ud=user_ud) # Check if the admin has permission to manage channel settings + data = SelectAdmin(user_id=user_id) # Check if the admin has permission to manage channel settings btn = close_btn() # Inline button to close the message if data.channel_settings(): - if user_ud == ADMIN: + if user_id == ADMIN: # Retrieve all channels if the admin is the main ADMIN data = db.select_channels() else: # Retrieve channels added by the current admin - data = db.select_channels_initiator_user_id(initiator_user_id=user_ud) + data = db.select_channels_initiator_user_id(initiator_user_id=user_id) if not data: # If no channels are found, indicate that the list is empty @@ -61,7 +61,7 @@ async def channel_setting(call: types.CallbackQuery, state: FSMContext): text += (f"{count}. Name: {channel.full_name}\n" f"Username: @{channel.username}\n" f"Added date: {x[2]}\n" - f"Added by user_ud: {x[3]}\n\n") + f"Added by user_id: {x[3]}\n\n") except Exception as err: logging.error(err) # Log any errors in retrieving channel details btn = channel_settings(lang=lang) # Button for channel settings @@ -70,7 +70,7 @@ async def channel_setting(call: types.CallbackQuery, state: FSMContext): text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) await bot.edit_message_text( - chat_id=user_ud, + chat_id=user_id, message_id=mid, text=f'{text}', reply_markup=btn # Update the message with a translated response and appropriate buttons diff --git a/handlers/admins/channel_settings/delete_channel.py b/handlers/admins/channel_settings/delete_channel.py index b797612..2671bd4 100755 --- a/handlers/admins/channel_settings/delete_channel.py +++ b/handlers/admins/channel_settings/delete_channel.py @@ -19,7 +19,7 @@ async def delete_channel(call: types.CallbackQuery, callback_data: AdminCallback - state (FSMContext): FSM context used to manage the bot's state for the current conversation. Functionality: - - Retrieves the admin's user ID (`user_ud`), the message ID (`mid`), and the language code (`lang`) from the callback query. + - Retrieves the admin's user ID (`user_id`), the message ID (`mid`), and the language code (`lang`) from the callback query. - Checks if the user has the necessary permissions to manage channel settings using the `SelectAdmin` filter. - If authorized, retrieves the channel ID from `callback_data`, formats it, and checks its existence in the database. - If the channel exists and the user is authorized, deletes the channel from the database and notifies the user. @@ -31,16 +31,16 @@ async def delete_channel(call: types.CallbackQuery, callback_data: AdminCallback - This function is asynchronous and does not return a value. It interacts with the Telegram API to send and edit messages. """ try: - user_ud = call.from_user.id # The ID of the admin making the request + user_id = call.from_user.id # The ID of the admin making the request mid = call.message.message_id # The ID of the message associated with the callback lang = call.from_user.language_code # The language code for translating responses - data = SelectAdmin(user_ud=user_ud) # Check if the user has admin permissions + data = SelectAdmin(user_id=user_id) # Check if the user has admin permissions btn = close_btn() # A button for closing the message if data.channel_settings(): - ch_user_ud = callback_data.data # Channel ID from the callback data - ch_user_ud100 = str(-100) + str(ch_user_ud) # Format channel ID for API - check = db.check_channel(user_ud=ch_user_ud) # Check if the channel exists in the database + ch_user_id = callback_data.data # Channel ID from the callback data + ch_user_id100 = str(-100) + str(ch_user_id) # Format channel ID for API + check = db.check_channel(user_id=ch_user_id) # Check if the channel exists in the database if not check: # Inform the user if the channel does not exist @@ -49,16 +49,16 @@ async def delete_channel(call: types.CallbackQuery, callback_data: AdminCallback dest=lang) else: # Get channel details using the Telegram API - channel = await bot.get_chat(chat_id=ch_user_ud100) + channel = await bot.get_chat(chat_id=ch_user_id100) - if check[3] == user_ud or user_ud == ADMIN: + if check[3] == user_id or user_id == ADMIN: # Delete the channel if the user is authorized - db.delete_channel(channel_id=ch_user_ud) + db.delete_channel(channel_id=ch_user_id) tx = translator(text='🚫 Channel removed...\n', dest=lang) text = (f"{tx}\n" f"Name: {channel.full_name}\n" f"Username: @{channel.username}\n" - f"ID: {ch_user_ud}\n\n") + f"ID: {ch_user_id}\n\n") else: # Inform the user if they do not have permission to delete the channel text = translator(text='⭕ Only an admin can delete this channel.', dest=lang) @@ -66,7 +66,7 @@ async def delete_channel(call: types.CallbackQuery, callback_data: AdminCallback # Inform the user if they lack the necessary permissions text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) - await bot.edit_message_text(chat_id=user_ud, + await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f'{text}', reply_markup=btn) # Send or edit the message with the result diff --git a/handlers/admins/channel_settings/get_id.py b/handlers/admins/channel_settings/get_id.py index c56157d..6c9f6b5 100755 --- a/handlers/admins/channel_settings/get_id.py +++ b/handlers/admins/channel_settings/get_id.py @@ -19,7 +19,7 @@ async def add_channel2(msg: types.Message, state: FSMContext): - state (FSMContext): FSM context used to manage the bot's state for the current conversation. Functionality: - - Retrieves the admin's user ID (`user_ud`), the message ID (`mid`), and the language code (`lang`) from the message. + - Retrieves the admin's user ID (`user_id`), the message ID (`mid`), and the language code (`lang`) from the message. - Checks if the user has the necessary permissions to manage channel settings using the `SelectAdmin` filter. - If authorized, attempts to convert the input text into a channel ID, checks if the channel is already in the database, and adds it if not. - If the channel is already in the database, provides details about the existing entry. @@ -31,10 +31,10 @@ async def add_channel2(msg: types.Message, state: FSMContext): - This function is asynchronous and does not return a value. It interacts with the Telegram API to send and edit messages. """ try: - user_ud = msg.from_user.id # The ID of the admin making the request + user_id = msg.from_user.id # The ID of the admin making the request mid = msg.message_id # The ID of the message associated with the request lang = msg.from_user.language_code # The language code for translating responses - data = SelectAdmin(user_ud=user_ud) # Check if the user has admin permissions + data = SelectAdmin(user_id=user_id) # Check if the user has admin permissions btn = close_btn() # A button for closing the message data_state = await state.get_data() # Get data stored in the FSM state @@ -48,7 +48,7 @@ async def add_channel2(msg: types.Message, state: FSMContext): if check is None: # Add the channel to the database if it doesn't exist db.insert_channel(channel_id=tx, - initiator_user_id=user_ud) + initiator_user_id=user_id) text = translator(text="✅ The channel was successfully added\n", dest=lang) text += f"Name: {channel.full_name}\n" \ f"Username: @{channel.username}" @@ -70,7 +70,7 @@ async def add_channel2(msg: types.Message, state: FSMContext): text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) # Update the message with the result and close button - await bot.edit_message_text(chat_id=user_ud, + await bot.edit_message_text(chat_id=user_id, message_id=data_state['message_id'], text=f'{text}', reply_markup=btn) diff --git a/handlers/admins/channel_settings/mandatory_membership.py b/handlers/admins/channel_settings/mandatory_membership.py index 788e657..484d674 100755 --- a/handlers/admins/channel_settings/mandatory_membership.py +++ b/handlers/admins/channel_settings/mandatory_membership.py @@ -18,7 +18,7 @@ async def mandatory_membership(call: types.CallbackQuery, state: FSMContext): - state (FSMContext): The FSM context to manage the bot's state during the conversation. Functionality: - - Retrieves the admin's user ID (`user_ud`), the message ID (`mid`), and the language code (`lang`) from the callback query. + - Retrieves the admin's user ID (`user_id`), the message ID (`mid`), and the language code (`lang`) from the callback query. - Checks if the user has the required permissions to modify channel settings using the `SelectAdmin` filter. - If authorized, reads the current mandatory membership status from the database. - Toggles the membership requirement status: @@ -32,10 +32,10 @@ async def mandatory_membership(call: types.CallbackQuery, state: FSMContext): - This function is asynchronous and does not return a value. It interacts with the Telegram API to update messages and with the database to modify settings. """ try: - user_ud = call.from_user.id # The ID of the admin who initiated the action + user_id = call.from_user.id # The ID of the admin who initiated the action mid = call.message.message_id # The ID of the message to be updated lang = call.from_user.language_code # The language code for translation - data = SelectAdmin(user_ud=user_ud) # Check if the user has admin permissions + data = SelectAdmin(user_id=user_id) # Check if the user has admin permissions btn = close_btn() # Create a button for closing the message if data.channel_settings(): @@ -57,7 +57,7 @@ async def mandatory_membership(call: types.CallbackQuery, state: FSMContext): text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) # Edit the message with the new status and close button - await bot.edit_message_text(chat_id=user_ud, + await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f'{text}', reply_markup=btn) diff --git a/handlers/admins/channel_settings/remove_channel.py b/handlers/admins/channel_settings/remove_channel.py index 70a9219..289d122 100755 --- a/handlers/admins/channel_settings/remove_channel.py +++ b/handlers/admins/channel_settings/remove_channel.py @@ -20,7 +20,7 @@ async def remove_channel(call: types.CallbackQuery, state: FSMContext): - state (FSMContext): The FSM context to manage the bot's state during the conversation. Functionality: - - Retrieves the admin's user ID (`user_ud`), the message ID (`mid`), and the language code (`lang`) from the callback query. + - Retrieves the admin's user ID (`user_id`), the message ID (`mid`), and the language code (`lang`) from the callback query. - Checks if the user has the necessary permissions to access channel settings using the `SelectAdmin` filter. - If authorized, retrieves the list of channels either for all admins (if the user is the main admin) or for channels added by the specific admin. - If the channel list is empty, informs the admin. If not, displays a list of channels with options to delete them. @@ -31,10 +31,10 @@ async def remove_channel(call: types.CallbackQuery, state: FSMContext): - This function is asynchronous and does not return a value. It interacts with the Telegram API to update messages and with the database to retrieve channel information. """ try: - user_ud = call.from_user.id # The ID of the admin who initiated the action + user_id = call.from_user.id # The ID of the admin who initiated the action mid = call.message.message_id # The ID of the message to be updated lang = call.from_user.language_code # The language code for translation - data = SelectAdmin(user_ud=user_ud) # Check if the user has admin permissions + data = SelectAdmin(user_id=user_id) # Check if the user has admin permissions btn = InlineKeyboardBuilder() # Create an instance of InlineKeyboardBuilder for the keyboard # Attach the main button to the keyboard @@ -42,10 +42,10 @@ async def remove_channel(call: types.CallbackQuery, state: FSMContext): if data.channel_settings(): # Retrieve the list of channels based on admin permissions - if user_ud == ADMIN: + if user_id == ADMIN: data = db.select_channels() else: - data = db.select_channels_initiator_user_id(initiator_user_id=user_ud) + data = db.select_channels_initiator_user_id(initiator_user_id=user_id) if not data: # Inform the admin if no channels are available From 7566a2247041d7e92f20096d8c7772b797fde1e8 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Fri, 28 Feb 2025 11:00:06 +0500 Subject: [PATCH 26/71] Refactor user identification: rename user_ud to user_id for consistency across admin handling in multiple modules --- handlers/admins/admin_settings/edit_admin.py | 30 ++++----- handlers/admins/check_usr/attach_usr.py | 2 +- handlers/admins/send_ads/get_message.py | 4 +- handlers/admins/send_ads/send_ads.py | 2 +- handlers/admins/send_ads/stop_ads.py | 2 +- .../admins/statistika/download_statistics.py | 8 +-- handlers/admins/statistika/staristika.py | 4 +- handlers/admins/super_admin.py | 12 ++-- keyboards/inline/admin_btn.py | 62 +++++++++---------- keyboards/inline/button.py | 6 +- middlewares/check_user.py | 8 +-- 11 files changed, 70 insertions(+), 70 deletions(-) diff --git a/handlers/admins/admin_settings/edit_admin.py b/handlers/admins/admin_settings/edit_admin.py index 518d17c..77c9f17 100755 --- a/handlers/admins/admin_settings/edit_admin.py +++ b/handlers/admins/admin_settings/edit_admin.py @@ -23,7 +23,7 @@ async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, - state (FSMContext): The FSM context for managing the bot's conversation state. Functionality: - - Extracts the current admin's ID (`user_ud`), message ID (`mid`), language code (`lang`), target admin ID (`admin_user_ud`), and the key to be edited (`edit_key`). + - Extracts the current admin's ID (`user_id`), message ID (`mid`), language code (`lang`), target admin ID (`admin_user_id`), and the key to be edited (`edit_key`). - Checks if the current admin has the right to modify admin settings. - If permitted, fetches the target admin's data. - Depending on the edit key, either deletes the target admin or updates a specific admin permission. @@ -38,35 +38,35 @@ async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, - Catches and logs any exceptions that occur during the execution of the function. """ try: - user_ud = call.from_user.id # Current admin's ID + user_id = call.from_user.id # Current admin's ID mid = call.message.message_id # Message ID to be updated lang = call.from_user.language_code # Admin's language preference - admin_user_ud = callback_data.user_ud # ID of the target admin to be modified + admin_user_id = callback_data.user_id # ID of the target admin to be modified edit_key = callback_data.data # The key indicating what action to perform - data = SelectAdmin(user_ud=user_ud) # Fetches the current admin's data + data = SelectAdmin(user_id=user_id) # Fetches the current admin's data add_admin = data.add_admin() # Checks if the current admin can add admins btn = close_btn() # Default button to close the operation # Check if the admin has rights to add another admin if add_admin: - admin_data = db.select_admin(user_ud=admin_user_ud) # Fetch data for the target admin + admin_data = db.select_admin(user_id=admin_user_id) # Fetch data for the target admin if admin_data is None: - text = f'⛔{admin_user_ud} {translator(text="😪 Not available in admin list!", dest=lang)}' + text = f'⛔{admin_user_id} {translator(text="😪 Not available in admin list!", dest=lang)}' else: - if admin_data[2] == user_ud or user_ud == ADMIN: + if admin_data[2] == user_id or user_id == ADMIN: if edit_key == "delete_admin": # If the edit action is to delete the admin - db.delete_admin(user_ud=admin_user_ud) - admin_info = await bot.get_chat(chat_id=admin_user_ud) + db.delete_admin(user_id=admin_user_id) + admin_info = await bot.get_chat(chat_id=admin_user_id) text = f'🔪 @{admin_info.username} {translator(text="✅ Removed from admin!", dest=lang)}' - await bot.send_message(chat_id=admin_user_ud, text='😪 Your admin rights have been revoked!') + await bot.send_message(chat_id=admin_user_id, text='😪 Your admin rights have been revoked!') else: # Update the specific admin permission - select_column = db.select_admin_column(user_ud=admin_user_ud, column=edit_key) + select_column = db.select_admin_column(user_id=admin_user_id, column=edit_key) new_value = 0 if select_column[0] == 1 else 1 - db.update_admin_data(user_ud=admin_user_ud, column=edit_key, value=new_value) - btn = attach_admin_btn(user_ud=admin_user_ud, lang=lang) - is_admin = SelectAdmin(user_ud=admin_user_ud) + db.update_admin_data(user_id=admin_user_id, column=edit_key, value=new_value) + btn = attach_admin_btn(user_id=admin_user_id, lang=lang) + is_admin = SelectAdmin(user_id=admin_user_id) send_message_tx = x_or_y(is_admin.send_message()) view_statistika_tx = x_or_y(is_admin.view_statistika()) download_statistika_tx = x_or_y(is_admin.download_statistika()) @@ -88,7 +88,7 @@ async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) # Update the message with the admin rights information or error message - await bot.edit_message_text(chat_id=user_ud, message_id=mid, text=f"{text}", reply_markup=btn) + await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f"{text}", reply_markup=btn) await state.set_state(AdminState.add_admin) # Set the state to add admin await state.update_data({"message_id": call.message.message_id}) # Update the state data with the message ID except Exception as err: diff --git a/handlers/admins/check_usr/attach_usr.py b/handlers/admins/check_usr/attach_usr.py index 17d562a..e3bf31e 100755 --- a/handlers/admins/check_usr/attach_usr.py +++ b/handlers/admins/check_usr/attach_usr.py @@ -49,7 +49,7 @@ async def attach_user(msg: types.Message, state: FSMContext): if check1 is not None: btn = block_user(attention_user_id=attention_user_id, user_id=user_id, lang=lang) # Button for blocking/unblocking user if check is None: - check2 = db.select_admin(user_ud=attention_user_id) # Check if the user is an admin + check2 = db.select_admin(user_id=attention_user_id) # Check if the user is an admin select_user = db.check_user(user_id) # Get information about the user if check2 is None: diff --git a/handlers/admins/send_ads/get_message.py b/handlers/admins/send_ads/get_message.py index 3ddbb39..f31e497 100755 --- a/handlers/admins/send_ads/get_message.py +++ b/handlers/admins/send_ads/get_message.py @@ -42,11 +42,11 @@ async def get_message(msg: types.Message, state: FSMContext): state_data = await state.get_data() # Check if the user has admin permissions - is_admin = SelectAdmin(user_ud=user_id) + is_admin = SelectAdmin(user_id=user_id) if is_admin.send_message(): # Prepare the admin panel button and fetch ads data - button_markup = main_admin_panel_btn(user_ud=user_id, lang=language_code) + button_markup = main_admin_panel_btn(user_id=user_id, lang=language_code) ads_data = file_db.reading_db().get('ads') if ads_data: diff --git a/handlers/admins/send_ads/send_ads.py b/handlers/admins/send_ads/send_ads.py index e13249a..6a0a0e7 100755 --- a/handlers/admins/send_ads/send_ads.py +++ b/handlers/admins/send_ads/send_ads.py @@ -43,7 +43,7 @@ async def send_ads(call: types.CallbackQuery, state: FSMContext): user_id = call.from_user.id message_id = call.message.message_id language_code = call.from_user.language_code - is_admin = SelectAdmin(user_ud=user_id) + is_admin = SelectAdmin(user_id=user_id) button_markup = close_btn() if is_admin.send_message(): diff --git a/handlers/admins/send_ads/stop_ads.py b/handlers/admins/send_ads/stop_ads.py index 15fd869..5279417 100644 --- a/handlers/admins/send_ads/stop_ads.py +++ b/handlers/admins/send_ads/stop_ads.py @@ -39,7 +39,7 @@ async def stop_ads(call: types.CallbackQuery, state: FSMContext): language_code = call.from_user.language_code # Check if the user has admin permissions - is_admin = SelectAdmin(user_ud=user_id) + is_admin = SelectAdmin(user_id=user_id) if is_admin.send_message(): # Fetch the current ads data diff --git a/handlers/admins/statistika/download_statistics.py b/handlers/admins/statistika/download_statistics.py index d64eca7..ec279e5 100755 --- a/handlers/admins/statistika/download_statistics.py +++ b/handlers/admins/statistika/download_statistics.py @@ -38,13 +38,13 @@ async def download_statistics(call: types.CallbackQuery, state: FSMContext): user_id = call.from_user.id message_id = call.message.message_id language = call.from_user.language_code - is_admin = SelectAdmin(user_ud=user_id) + is_admin = SelectAdmin(user_id=user_id) if is_admin.download_statistika(): # Retrieve user data from the database data = db.select_all_users() id_list = [] - user_ud_list = [] + user_id_list = [] date_list = [] usernames = [] langs = [] @@ -52,7 +52,7 @@ async def download_statistics(call: types.CallbackQuery, state: FSMContext): # Populate lists with user data for user in data: id_list.append(user['id']) - user_ud_list.append(user['user_id']) + user_id_list.append(user['user_id']) date_list.append(user['created_time']) langs.append(user['language_code']) user_info = await bot.get_chat(chat_id=user['user_id']) @@ -61,7 +61,7 @@ async def download_statistics(call: types.CallbackQuery, state: FSMContext): # Create a DataFrame and save it to an Excel file statistics_data = { "id": id_list, - "user_ud": user_ud_list, + "user_id": user_id_list, "date_add": date_list, "username": usernames, "lang": langs diff --git a/handlers/admins/statistika/staristika.py b/handlers/admins/statistika/staristika.py index 6e30737..7392815 100755 --- a/handlers/admins/statistika/staristika.py +++ b/handlers/admins/statistika/staristika.py @@ -36,7 +36,7 @@ async def statistika(call: types.CallbackQuery, state: FSMContext): user_id = call.from_user.id message_id = call.message.message_id language = call.from_user.language_code - is_admin = SelectAdmin(user_ud=user_id) + is_admin = SelectAdmin(user_id=user_id) if is_admin.view_statistika(): user_count = db.stat() @@ -46,7 +46,7 @@ async def statistika(call: types.CallbackQuery, state: FSMContext): f" {soat_minut_sekund}\n" + translator(text="📆 Date:", dest=language) + f' {yil_oy_kun}\n ' + translator(text="Number of bans: ", dest=language) + str( ban_count)) - button = download_statistika(user_ud=user_id, lang=language) + button = download_statistika(user_id=user_id, lang=language) await state.update_data({"message_id": call.message.message_id}) else: text = translator(text="❌ Unfortunately, you do not have this permission!", dest=language) diff --git a/handlers/admins/super_admin.py b/handlers/admins/super_admin.py index b32cc0e..c282154 100755 --- a/handlers/admins/super_admin.py +++ b/handlers/admins/super_admin.py @@ -42,17 +42,17 @@ async def super_admin(msg: types.Message): data = db.select_all_users_ban() id_list = [] - user_ud_list = [] + user_id_list = [] date_list = [] username_list = [] - admin_user_ud = [] + admin_user_id = [] try: # Collecting data for the DataFrame for x in data: id_list.append(x['id']) - user_ud_list.append(x['user_id']) - admin_user_ud.append(x['admin_user_id']) + user_id_list.append(x['user_id']) + admin_user_id.append(x['admin_user_id']) date_list.append(x['date']) # Fetching username from chat ID @@ -62,8 +62,8 @@ async def super_admin(msg: types.Message): # Creating and saving DataFrame to Excel x_data = { "id": id_list, - "user_ud": user_ud_list, - "admin_user_ud": admin_user_ud, + "user_id": user_id_list, + "admin_user_id": admin_user_id, "date_add": date_list, "username": username_list } diff --git a/keyboards/inline/admin_btn.py b/keyboards/inline/admin_btn.py index 67bfe75..336199e 100644 --- a/keyboards/inline/admin_btn.py +++ b/keyboards/inline/admin_btn.py @@ -35,7 +35,7 @@ def main_admin_panel_btn(user_id, lang): Creates the inline keyboard for the main admin panel. Parameters: - user_ud (int): The ID of the current user. + user_id (int): The ID of the current user. lang (str): The language code for translation. Returns: @@ -79,12 +79,12 @@ def main_admin_panel_btn(user_id, lang): return False -async def admin_setting(user_ud, lang): +async def admin_setting(user_id, lang): """ Creates the inline keyboard for admin settings. Parameters: - user_ud (int): The ID of the current user. + user_id (int): The ID of the current user. lang (str): The language code for translation. Returns: @@ -97,15 +97,15 @@ async def admin_setting(user_ud, lang): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - if user_ud == ADMIN: + if user_id == ADMIN: data = db.select_all_admins() else: - data = db.select_add_admin(user_ud=user_ud) + data = db.select_add_admin(user_id=user_id) if data is not None: for x in data: - info = await bot.get_chat(chat_id=x['user_ud']) + info = await bot.get_chat(chat_id=x['user_id']) btn.button(text=f"👮‍♂️ @{info.username}: {info.full_name}!", - callback_data=AdminSetting(action="attach_admin", user_ud=x[1]).pack()) + callback_data=AdminSetting(action="attach_admin", user_id=x[1]).pack()) btn.button(text=translator(text=f"👮‍♂️ ADD Admin!", dest=lang), callback_data=AdminCallback(action="add_admin", data="").pack()) @@ -117,12 +117,12 @@ async def admin_setting(user_ud, lang): return False -def attach_admin(user_ud, lang): +def attach_admin(user_id, lang): """ Creates the inline keyboard for managing admin settings. Parameters: - user_ud (int): The ID of the current user. + user_id (int): The ID of the current user. lang (str): The language code for translation. Returns: @@ -136,7 +136,7 @@ def attach_admin(user_ud, lang): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = SelectAdmin(user_ud=user_ud) + is_admin = SelectAdmin(user_id=user_id) send_message_tx = x_or_y(is_admin.send_message()) wiew_statistika_tx = x_or_y(is_admin.view_statistika()) download_statistika_tx = x_or_y(is_admin.download_statistika()) @@ -145,28 +145,28 @@ def attach_admin(user_ud, lang): add_admin_tx = x_or_y(is_admin.add_admin()) btn.button(text=translator(text=f"{send_message_tx} Send a message!", dest=lang), - callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='send_message').pack()) + callback_data=EditAdminSetting(action="edit", user_id=user_id, data='send_message').pack()) btn.button(text=translator(text=f"{wiew_statistika_tx} Wiew statistics!", dest=lang), - callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='statistika').pack()) + callback_data=EditAdminSetting(action="edit", user_id=user_id, data='statistika').pack()) btn.button(text=translator(text=f"{download_statistika_tx} Download statistics!", dest=lang), - callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='download_statistika').pack()) + callback_data=EditAdminSetting(action="edit", user_id=user_id, data='download_statistika').pack()) btn.button(text=translator(text=f"{block_user_tx} Block user!", dest=lang), - callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='block_user').pack()) + callback_data=EditAdminSetting(action="edit", user_id=user_id, data='block_user').pack()) btn.button(text=translator(text=f"{channel_settings_tx} Channel settings!", dest=lang), - callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='channel_settings').pack()) + callback_data=EditAdminSetting(action="edit", user_id=user_id, data='channel_settings').pack()) btn.button(text=translator(text=f"{add_admin_tx} Add a admin!", dest=lang), - callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='add_admin').pack()) + callback_data=EditAdminSetting(action="edit", user_id=user_id, data='add_admin').pack()) btn.button(text=translator(text=f"🔪Delete admin!", dest=lang), - callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='delete_admin').pack()) + callback_data=EditAdminSetting(action="edit", user_id=user_id, data='delete_admin').pack()) btn.adjust(1) btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) return btn.as_markup() @@ -175,12 +175,12 @@ def attach_admin(user_ud, lang): return False -def attach_admin_btn(user_ud, lang): +def attach_admin_btn(user_id, lang): """ Creates the inline keyboard for managing admin settings. Parameters: - user_ud (int): The ID of the current user. + user_id (int): The ID of the current user. lang (str): The language code for translation. Returns: @@ -195,7 +195,7 @@ def attach_admin_btn(user_ud, lang): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = SelectAdmin(user_ud=user_ud) + is_admin = SelectAdmin(user_id=user_id) send_message_tx = x_or_y(is_admin.send_message()) wiew_statistika_tx = x_or_y(is_admin.view_statistika()) download_statistika_tx = x_or_y(is_admin.download_statistika()) @@ -204,28 +204,28 @@ def attach_admin_btn(user_ud, lang): add_admin_tx = x_or_y(is_admin.add_admin()) btn.button(text=translator(text=f"{send_message_tx} Send a message!", dest=lang), - callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='send_message').pack()) + callback_data=EditAdminSetting(action="edit", user_id=user_id, data='send_message').pack()) btn.button(text=translator(text=f"{wiew_statistika_tx} Wiew statistics!", dest=lang), - callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='statistika').pack()) + callback_data=EditAdminSetting(action="edit", user_id=user_id, data='statistika').pack()) btn.button(text=translator(text=f"{download_statistika_tx} Download statistics!", dest=lang), - callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='download_statistika').pack()) + callback_data=EditAdminSetting(action="edit", user_id=user_id, data='download_statistika').pack()) btn.button(text=translator(text=f"{block_user_tx} Block user!", dest=lang), - callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='block_user').pack()) + callback_data=EditAdminSetting(action="edit", user_id=user_id, data='block_user').pack()) btn.button(text=translator(text=f"{channel_settings_tx} Channel settings!", dest=lang), - callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='channel_settings').pack()) + callback_data=EditAdminSetting(action="edit", user_id=user_id, data='channel_settings').pack()) btn.button(text=translator(text=f"{add_admin_tx} Add a admin!", dest=lang), - callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='add_admin').pack()) + callback_data=EditAdminSetting(action="edit", user_id=user_id, data='add_admin').pack()) btn.button(text=translator(text=f"🔪Delete admin!", dest=lang), - callback_data=EditAdminSetting(action="edit", user_ud=user_ud, data='delete_admin').pack()) + callback_data=EditAdminSetting(action="edit", user_id=user_id, data='delete_admin').pack()) btn.adjust(1) btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) return btn.as_markup() @@ -280,7 +280,7 @@ def block_user(attention_user_id, lang, user_id): Creates the inline keyboard for blocking or unblocking a user. Parameters: - user_ud (int): The ID of the current user. + user_id (int): The ID of the current user. lang (str): The language code for translation. user_id (int): The ID of the user to be blocked or unblocked. @@ -316,12 +316,12 @@ def block_user(attention_user_id, lang, user_id): return False -def download_statistika(user_ud, lang): +def download_statistika(user_id, lang): """ Creates the inline keyboard for downloading statistics. Parameters: - user_ud (int): The ID of the current user. + user_id (int): The ID of the current user. lang (str): The language code for translation. Returns: @@ -334,7 +334,7 @@ def download_statistika(user_ud, lang): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = SelectAdmin(user_ud=user_ud) + is_admin = SelectAdmin(user_id=user_id) if is_admin.download_statistika(): btn.button(text=translator(text=f"📜 Dowload statistika!", dest=lang), diff --git a/keyboards/inline/button.py b/keyboards/inline/button.py index 1fc26dc..f6f3c7a 100644 --- a/keyboards/inline/button.py +++ b/keyboards/inline/button.py @@ -28,7 +28,7 @@ class EditAdminSetting(CallbackData, prefix="edit_setting"): Attributes: action (str): The specific action to be performed on settings. - user_ud (int): The ID of the admin or user related to the setting. + user_id (int): The ID of the admin or user related to the setting. data (str): The specific setting to be edited. """ action: str @@ -41,7 +41,7 @@ class AdminSetting(CallbackData, prefix="admin_setting"): Attributes: action (str): The specific action related to admin settings. - user_ud (int): The ID of the admin or user related to the setting. + user_id (int): The ID of the admin or user related to the setting. """ action: str user_id: int @@ -52,7 +52,7 @@ class BlockUser(CallbackData, prefix="block_user"): Attributes: action (str): The specific action to be performed (block/unblock). - user_ud (int): The ID of the user to be blocked or unblocked. + user_id (int): The ID of the user to be blocked or unblocked. """ action: str user_id: int diff --git a/middlewares/check_user.py b/middlewares/check_user.py index 9c4817e..aeb4efd 100755 --- a/middlewares/check_user.py +++ b/middlewares/check_user.py @@ -47,14 +47,14 @@ # if data['join_channel']: # try: # # Try to get the user ID from the message object -# user_ud = message.from_user.id +# user_id = message.from_user.id # except Exception as err: # # If message object is not available, use callback query object -# user_ud = call.from_user.id +# user_id = call.from_user.id # logging.error(err) # # # If the user is not the admin, perform the channel check -# if user_ud != self.ADMIN: +# if user_id != self.ADMIN: # force = False # result = db.select_channels() # for x in result: @@ -64,7 +64,7 @@ # await bot.get_chat(ids) # try: # # Check the user's membership status in the channel -# res = await bot.get_chat_member(chat_id=ids, user_id=user_ud) +# res = await bot.get_chat_member(chat_id=ids, user_id=user_id) # except: # # Continue if unable to retrieve chat member information # continue From a7b30f56e6b9cb74e24ece6a91ee9823a04c1c3c Mon Sep 17 00:00:00 2001 From: UznetDev Date: Fri, 28 Feb 2025 11:17:38 +0500 Subject: [PATCH 27/71] Refactor database queries and admin handling: update SQL queries to use descriptive aliases, improve variable naming for clarity, and ensure consistency in language code usage across admin settings. --- db/database.py | 10 ++++----- handlers/admins/admin_settings/edit_admin.py | 23 +++++++++++--------- keyboards/inline/admin_btn.py | 18 +++++++-------- 3 files changed, 27 insertions(+), 24 deletions(-) diff --git a/db/database.py b/db/database.py index 60d7c70..d6105fc 100755 --- a/db/database.py +++ b/db/database.py @@ -425,10 +425,10 @@ def stat_ban(self): int: The total number of banned users. """ try: - sql = "SELECT COUNT(*) FROM `users` WHERE `status`='ban'`;" + sql = "SELECT COUNT(*) AS user_count FROM `users` WHERE `status`='ban';" self.cursor.execute(sql) result = self.cursor.fetchone() - return result[0] + return result['user_count'] except mysql.connector.Error as err: logging.error(err) self.reconnect() @@ -525,10 +525,10 @@ def stat(self): int: The total number of users. """ try: - sql = "SELECT COUNT(*) FROM `users`;" + sql = "SELECT COUNT(*) AS total_users FROM `users`;" self.cursor.execute(sql) result = self.cursor.fetchone() - return result[0] + return result['total_users'] except mysql.connector.Error as err: logging.error(err) self.reconnect() @@ -570,7 +570,7 @@ def select_admin_column(self, user_id, column): any: The value of the specified column for the admin. """ try: - self.cursor.execute(f"SELECT {column} FROM `admins` WHERE `user_id`=%s", (user_id,)) + self.cursor.execute(f"SELECT {column} AS result FROM `admins` WHERE `user_id`=%s", (user_id,)) result = self.cursor.fetchone() return result except mysql.connector.Error as err: diff --git a/handlers/admins/admin_settings/edit_admin.py b/handlers/admins/admin_settings/edit_admin.py index 77c9f17..985139a 100755 --- a/handlers/admins/admin_settings/edit_admin.py +++ b/handlers/admins/admin_settings/edit_admin.py @@ -40,7 +40,7 @@ async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, try: user_id = call.from_user.id # Current admin's ID mid = call.message.message_id # Message ID to be updated - lang = call.from_user.language_code # Admin's language preference + language_code = call.from_user.language_code # Admin's language preference admin_user_id = callback_data.user_id # ID of the target admin to be modified edit_key = callback_data.data # The key indicating what action to perform data = SelectAdmin(user_id=user_id) # Fetches the current admin's data @@ -51,21 +51,21 @@ async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, if add_admin: admin_data = db.select_admin(user_id=admin_user_id) # Fetch data for the target admin if admin_data is None: - text = f'⛔{admin_user_id} {translator(text="😪 Not available in admin list!", dest=lang)}' + text = f'⛔{admin_user_id} {translator(text="😪 Not available in admin list!", dest=language_code)}' else: - if admin_data[2] == user_id or user_id == ADMIN: + if admin_data['initiator_user_id'] == user_id or user_id == ADMIN: if edit_key == "delete_admin": # If the edit action is to delete the admin db.delete_admin(user_id=admin_user_id) admin_info = await bot.get_chat(chat_id=admin_user_id) - text = f'🔪 @{admin_info.username} {translator(text="✅ Removed from admin!", dest=lang)}' + text = f'🔪 @{admin_info.username} {translator(text="✅ Removed from admin!", dest=language_code)}' await bot.send_message(chat_id=admin_user_id, text='😪 Your admin rights have been revoked!') else: # Update the specific admin permission select_column = db.select_admin_column(user_id=admin_user_id, column=edit_key) - new_value = 0 if select_column[0] == 1 else 1 - db.update_admin_data(user_id=admin_user_id, column=edit_key, value=new_value) - btn = attach_admin_btn(user_id=admin_user_id, lang=lang) + new_value = 0 if select_column['result'] == 1 else 1 + db.update_admin_data(user_id=admin_user_id, column=edit_key, value=new_value, updater_user_id=user_id) + btn = attach_admin_btn(user_id=admin_user_id, language_code=language_code) is_admin = SelectAdmin(user_id=admin_user_id) send_message_tx = x_or_y(is_admin.send_message()) view_statistika_tx = x_or_y(is_admin.view_statistika()) @@ -81,11 +81,14 @@ async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, f'Channel settings: {channel_settings_tx}\n' \ f'Add admin: {add_admin_tx}\n' \ f'Date added: ' - text += str(admin_data[9]) + text += str(admin_data['created_time']) + text += f'\nUpdated added: ' + text += str(admin_data['updated_time']) + else: - text = translator(text='🛑 You can only change the admin rights you assigned!', dest=lang) + text = translator(text='🛑 You can only change the admin rights you assigned!', dest=language_code) else: - text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) + text = translator(text='❌ Unfortunately, you do not have this right!', dest=language_code) # Update the message with the admin rights information or error message await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f"{text}", reply_markup=btn) diff --git a/keyboards/inline/admin_btn.py b/keyboards/inline/admin_btn.py index 336199e..277dc12 100644 --- a/keyboards/inline/admin_btn.py +++ b/keyboards/inline/admin_btn.py @@ -105,7 +105,7 @@ async def admin_setting(user_id, lang): for x in data: info = await bot.get_chat(chat_id=x['user_id']) btn.button(text=f"👮‍♂️ @{info.username}: {info.full_name}!", - callback_data=AdminSetting(action="attach_admin", user_id=x[1]).pack()) + callback_data=AdminSetting(action="attach_admin", user_id=x['user_id']).pack()) btn.button(text=translator(text=f"👮‍♂️ ADD Admin!", dest=lang), callback_data=AdminCallback(action="add_admin", data="").pack()) @@ -175,7 +175,7 @@ def attach_admin(user_id, lang): return False -def attach_admin_btn(user_id, lang): +def attach_admin_btn(user_id, language_code): """ Creates the inline keyboard for managing admin settings. @@ -203,28 +203,28 @@ def attach_admin_btn(user_id, lang): channel_settings_tx = x_or_y(is_admin.channel_settings()) add_admin_tx = x_or_y(is_admin.add_admin()) btn.button(text=translator(text=f"{send_message_tx} Send a message!", - dest=lang), + dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='send_message').pack()) btn.button(text=translator(text=f"{wiew_statistika_tx} Wiew statistics!", - dest=lang), + dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='statistika').pack()) btn.button(text=translator(text=f"{download_statistika_tx} Download statistics!", - dest=lang), + dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='download_statistika').pack()) btn.button(text=translator(text=f"{block_user_tx} Block user!", - dest=lang), + dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='block_user').pack()) btn.button(text=translator(text=f"{channel_settings_tx} Channel settings!", - dest=lang), + dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='channel_settings').pack()) btn.button(text=translator(text=f"{add_admin_tx} Add a admin!", - dest=lang), + dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='add_admin').pack()) btn.button(text=translator(text=f"🔪Delete admin!", - dest=lang), + dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='delete_admin').pack()) btn.adjust(1) btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) From 2ba411405e32bcd413d449a2b99a42c4c1dd3906 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Fri, 28 Feb 2025 11:21:31 +0500 Subject: [PATCH 28/71] Refactor user identification in user_check: rename user_ud to user_id for consistency in user handling --- cython_code/user_check.pyx | 11 ++++++----- handlers/users/check_usr.py | 1 - 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/cython_code/user_check.pyx b/cython_code/user_check.pyx index e274fcc..8a47b81 100644 --- a/cython_code/user_check.pyx +++ b/cython_code/user_check.pyx @@ -6,6 +6,7 @@ from aiogram.filters import BaseFilter from aiogram.types import Message, CallbackQuery from aiogram import BaseMiddleware + class User_Check(BaseFilter, BaseMiddleware): """ Middleware and filter class to check if a user is a member of required channels. @@ -47,24 +48,24 @@ class User_Check(BaseFilter, BaseMiddleware): if data['join_channel']: try: # Try to get the user ID from the message object - user_ud = message.from_user.id + user_id = message.from_user.id except Exception as err: # If message object is not available, use callback query object - user_ud = call.from_user.id + user_id = call.from_user.id logging.error(err) # If the user is not the admin, perform the channel check - if user_ud != self.ADMIN: + if user_id != self.ADMIN: force = False result = db.select_channels() for x in result: try: # Construct the chat ID for the channel - ids = str(-100) + str(x[1]) + ids = str(-100) + str(x['channel_id']) await bot.get_chat(ids) try: # Check the user's membership status in the channel - res = await bot.get_chat_member(chat_id=ids, user_id=user_ud) + res = await bot.get_chat_member(chat_id=ids, user_id=user_id) except: # Continue if unable to retrieve chat member information continue diff --git a/handlers/users/check_usr.py b/handlers/users/check_usr.py index 6da05bf..a938fcd 100755 --- a/handlers/users/check_usr.py +++ b/handlers/users/check_usr.py @@ -5,7 +5,6 @@ from function.translator import translator from aiogram.utils.keyboard import InlineKeyboardBuilder from keyboards.inline.button import MainCallback -from data.config import date_day_month, time_hour_minute_second @dp.message(User_Check()) From a7141ab1c10100e51c4f10aeab166a39f21eaab0 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Fri, 28 Feb 2025 14:03:42 +0500 Subject: [PATCH 29/71] Refactor middleware imports and improve ban handling: update ThrottlingMiddleware to manage user bans and streamline imports for clarity --- cython_code/throttling_middleware.pyx | 83 +++++----- db/database.py | 9 +- filters/ban.py | 7 +- handlers/admins/check_usr/block_users.py | 5 +- handlers/users/check_ban.py | 20 ++- main.py | 3 +- middlewares/throttling.py | 196 +++++++++++++---------- 7 files changed, 181 insertions(+), 142 deletions(-) diff --git a/cython_code/throttling_middleware.pyx b/cython_code/throttling_middleware.pyx index c6fdf01..939385d 100644 --- a/cython_code/throttling_middleware.pyx +++ b/cython_code/throttling_middleware.pyx @@ -1,52 +1,38 @@ +# cython: language_level=3 import logging import time from keyboards.inline.close_btn import close_btn from aiogram import BaseMiddleware, types -from aiogram.dispatcher.event.handler import HandlerObject -from loader import bot +from loader import bot, db from function.translator import translator +# E'tibor bering: BaseMiddleware toza Python klassi, shuning uchun cdef class emas. class ThrottlingMiddleware(BaseMiddleware): """ - Middleware class to manage throttling of requests to prevent overloading. - - This middleware limits the rate of incoming requests from users. If a user exceeds the allowed - request rate, they will receive a message indicating that they are making too many requests. + So'rovlarni cheklash (throttling) orqali tizim yuklanishini kamaytiruvchi middleware. + Agar foydalanuvchi 1 daqiqa ichida 3 marta "Many requests have been made" xabarini olsa, + u 1 soatga ban qilinadi. """ - def __init__(self, default_rate: float = 0.5) -> None: """ - Initializes the ThrottlingMiddleware instance. - + Middleware'ni boshlang'ich sozlamalar bilan yaratadi. + Parameters: - - default_rate (float): The initial rate limit in seconds (default is 0.5 seconds). - - This constructor sets up the initial rate limit and other throttling parameters. + default_rate (float): So'rovlar oralig'idagi minimal vaqt (sekundlarda), default 0.5 sekund. """ - self.limiters = {} + self.limiters = {} # Foydalanuvchi ID bo'yicha throttling ma'lumotlari self.default_rate = default_rate - self.count_throttled = 1 - self.last_throttled = 0 async def __call__(self, handler, event: types.Message, data): """ - Processes incoming messages and enforces throttling rules. - - Parameters: - - handler (HandlerObject): The handler to call if throttling rules are not violated. - - event (types.Message): The incoming message or callback query. - - data (dict): Additional data associated with the event. - - This method checks if the incoming request exceeds the allowed rate limit. If the rate limit - is exceeded, the user will receive a message informing them of the throttling. If not, the - handler is called to process the request. - - Returns: - - None: The method does not return a value. It either processes the handler or sends a throttling message. + So'rovlarni qabul qilib, throttling qoidalarini bajarsa, keyingi handlerga o'tadi. + Agar foydalanuvchi 1 daqiqa ichida 3 marta throttlingga tushsa, u 1 soatga ban qilinadi. """ - real_handler: HandlerObject = data["handler"] + # real_handler-ni oddiy Python obyekti sifatida olamiz, uni C tip sifatida belgilashga hojat yo'q + real_handler = data["handler"] skip_pass = True + # Foydalanuvchi identifikatori va tilini aniqlaymiz if event.message: user_id = event.message.from_user.id lang = event.message.from_user.language_code @@ -55,26 +41,45 @@ class ThrottlingMiddleware(BaseMiddleware): lang = event.callback_query.from_user.language_code else: lang = 'en' + return await handler(event, data) if real_handler.flags.get("skip_pass") is not None: skip_pass = real_handler.flags.get("skip_pass") + now = time.time() + # Har bir foydalanuvchi uchun: "last": oxirgi so'rov vaqti, "count": throttled holatlar soni, "first": oynaning boshlanish vaqti + user_data = self.limiters.get(user_id, {"last": now, "count": 0, "first": now}) + if skip_pass: - if int(time.time()) - self.last_throttled >= self.default_rate: - self.last_throttled = int(time.time()) - self.default_rate = 0.5 - self.count_throttled = 0 + if now - user_data["last"] >= self.default_rate: + user_data["last"] = now + user_data["count"] = 0 # Hisobni tiklash + user_data["first"] = now + self.limiters[user_id] = user_data return await handler(event, data) else: - if self.count_throttled >= 2: - self.default_rate = 3 + if now - user_data["first"] > 60: + user_data["count"] = 0 + user_data["first"] = now + user_data["count"] += 1 + + if user_data["count"] >= 3: + try: + db.ban_user_for_one_hour(user_id) + tx = translator( + text='You have been banned for 1 hour due to too many requests.', + dest=lang + ) + await bot.send_message(chat_id=user_id, text=tx) + except Exception as err: + logging.error("Error banning user %d: %s", user_id, err) + user_data["count"] = 0 else: try: - self.count_throttled += 1 tx = translator(text='Many requests have been made', dest=lang) try: await event.callback_query.answer(tx) - except: + except Exception: await bot.send_message( chat_id=user_id, text=tx, @@ -83,6 +88,8 @@ class ThrottlingMiddleware(BaseMiddleware): except Exception as err: logging.error(err) - self.last_throttled = int(time.time()) + user_data["last"] = now + self.limiters[user_id] = user_data + return else: return await handler(event, data) diff --git a/db/database.py b/db/database.py index d6105fc..0e21e9d 100755 --- a/db/database.py +++ b/db/database.py @@ -89,6 +89,7 @@ def create_table_users(self): `status` ENUM('remove', 'active', 'blocked', 'ban', 'unban', 'sleep') DEFAULT 'active', `initiator_user_id` BIGINT, `updater_user_id` BIGINT, + `comment` TEXT, `ban_time` TIMESTAMP NULL DEFAULT NULL, `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, @@ -185,14 +186,14 @@ def create_table_settings(self): ## ---------------- Scheduler --------------------- - def ban_user_for_one_hour(self, user_id): + def ban_user_for_one_hour(self, user_id, comment=None): try: sql_update = """ UPDATE users - SET status = 'ban', ban_time = NOW() + SET status = 'ban', ban_time = NOW(), initiator_user_id = 1, updater_user_id = 1, `comment` = %s WHERE user_id = %s """ - self.cursor.execute(sql_update, (user_id,)) + self.cursor.execute(sql_update, (comment, user_id,)) self.connection.commit() event_name = f"unban_user_{user_id}" sql_event = f""" @@ -200,7 +201,7 @@ def ban_user_for_one_hour(self, user_id): ON SCHEDULE AT DATE_ADD(NOW(), INTERVAL 1 HOUR) DO UPDATE users - SET status = 'active', ban_time = NULL + SET status = 'active', ban_time = NULL, updater_user_id = 1 WHERE user_id = {user_id}; """ self.cursor.execute(sql_event) diff --git a/filters/ban.py b/filters/ban.py index 41fa753..59e7f6d 100644 --- a/filters/ban.py +++ b/filters/ban.py @@ -16,6 +16,7 @@ class IsBan(BaseFilter): def __init__(self): self.super_admin = ADMIN + async def __call__(self, message: Message) -> bool: """ Checks if the message sender is banned. @@ -28,15 +29,15 @@ async def __call__(self, message: Message) -> bool: """ try: self.user_id = message.from_user.id - self.dada = db.select_admin(user_id=self.user_id) + # self.dada = db.select_admin(user_id=self.user_id) check_ban = db.check_user_ban(user_id=self.user_id) # If the user is the super admin, they are not banned if self.user_id == self.super_admin: return False # If the user is an admin, they are not banned - elif self.dada is not None: - return False + # elif self.dada is not None: + # return False # If there is no ban record for the user, they are not banned elif check_ban is None: return False diff --git a/handlers/admins/check_usr/block_users.py b/handlers/admins/check_usr/block_users.py index afd33a9..aefecec 100755 --- a/handlers/admins/check_usr/block_users.py +++ b/handlers/admins/check_usr/block_users.py @@ -7,7 +7,8 @@ from aiogram.fsm.context import FSMContext from function.translator import translator from states.admin_state import AdminState -from data.config import yil_oy_kun, soat_minut_sekund, ADMIN +from data.config import ADMIN + @dp.callback_query(BlockUser.filter(F.action == "block"), IsAdmin()) async def block_users(call: types.CallbackQuery, callback_data: BlockUser, state: FSMContext): @@ -44,7 +45,7 @@ async def block_users(call: types.CallbackQuery, callback_data: BlockUser, state if data.block_user(): check1 = db.select_admin(user_id=attention_user_id) # Check if the user is an admin - if check1 is None: + if check1 is None or user_id == ADMIN: check = db.check_user_ban(user_id=attention_user_id) # Check if the user is already banned user = await bot.get_chat(chat_id=attention_user_id) # Get user details if check is None: diff --git a/handlers/users/check_ban.py b/handlers/users/check_ban.py index 520a619..38a4c5c 100755 --- a/handlers/users/check_ban.py +++ b/handlers/users/check_ban.py @@ -25,17 +25,25 @@ async def ban_handler(msg: types.Message): # Check if the user is banned and retrieve ban information info = db.check_user_ban(user_id=user_id) - logging.info(f"User ban info: {info}") # Retrieve admin information - admin_info = await bot.get_chat(chat_id=info['admin_user_id']) + text = translator(text="🛑 You are banned!:\n" + "⚠ If you think this is a mistake, contact the admin.", + dest=lang) + if info['initiator_user_id'] == 1 or info['initiator_user_id'] == 0: + text += f"\n\n👮‍♂️ Admin: Bot\n " + + else: + admin_info = await bot.get_chat(chat_id=info['updater_user_id']) + text += f"\n\n👮‍♂️ Admin @{admin_info.username}\n " + if info['comment'] is not None: + text += f"📝 Comment: {info['comment']}\n" + admins = await bot.get_chat(chat_id=ADMIN) # Create the response message - text = translator(text="🛑 You are banned!:\n" - "⚠ If you think this is a mistake, contact the admin.", - dest=lang) - text += f'\n\n👮‍♂️ Admin @{admin_info.username}\n 👩‍💻 Super admin @{admins.username}\n' + + text += f'👩‍💻 Super admin @{admins.username}\n' # Send the response message to the user await msg.answer(text=f"{text}", reply_markup=close_btn()) diff --git a/main.py b/main.py index 5d65005..5a971b5 100755 --- a/main.py +++ b/main.py @@ -6,7 +6,8 @@ import logging from utils.set_bot_commands import set_default_commands # Import the function to set default bot commands from loader import * # Import all from loader module -from middlewares import ThrottlingMiddleware # Import the ThrottlingMiddleware class +# from middlewares import ThrottlingMiddleware # Import the ThrottlingMiddleware class +from middlewares.throttling import ThrottlingMiddleware # Import the ThrottlingMiddleware class from data.config import log_file_name # Import the log file name from config diff --git a/middlewares/throttling.py b/middlewares/throttling.py index 56d2c67..1038e27 100755 --- a/middlewares/throttling.py +++ b/middlewares/throttling.py @@ -1,88 +1,108 @@ -# import logging -# import time -# from keyboards.inline.close_btn import close_btn -# from aiogram import BaseMiddleware, types -# from aiogram.dispatcher.event.handler import HandlerObject -# from loader import bot -# from function.translator import translator -# -# class ThrottlingMiddleware(BaseMiddleware): -# """ -# Middleware class to manage throttling of requests to prevent overloading. -# -# This middleware limits the rate of incoming requests from users. If a user exceeds the allowed -# request rate, they will receive a message indicating that they are making too many requests. -# """ -# -# def __init__(self, default_rate: int = 0.5) -> None: -# """ -# Initializes the ThrottlingMiddleware instance. -# -# Parameters: -# - default_rate (float): The initial rate limit in seconds (default is 0.5 seconds). -# -# This constructor sets up the initial rate limit and other throttling parameters. -# """ -# self.limiters = {} -# self.default_rate = default_rate -# self.count_throttled = 1 -# self.last_throttled = 0 -# -# async def __call__(self, handler, event: types.Message, data): -# """ -# Processes incoming messages and enforces throttling rules. -# -# Parameters: -# - handler (HandlerObject): The handler to call if throttling rules are not violated. -# - event (types.Message): The incoming message or callback query. -# - data (dict): Additional data associated with the event. -# -# This method checks if the incoming request exceeds the allowed rate limit. If the rate limit -# is exceeded, the user will receive a message informing them of the throttling. If not, the -# handler is called to process the request. -# -# Returns: -# - None: The method does not return a value. It either processes the handler or sends a throttling message. -# """ -# real_handler: HandlerObject = data["handler"] -# skip_pass = True -# -# if event.message: -# user_id = event.message.from_user.id -# lang = event.message.from_user.language_code -# elif event.callback_query: -# user_id = event.callback_query.from_user.id -# lang = event.callback_query.from_user.language_code -# else: -# lang = 'en' -# -# if real_handler.flags.get("skip_pass") is not None: -# skip_pass = real_handler.flags.get("skip_pass") -# -# if skip_pass: -# if int(time.time()) - self.last_throttled >= self.default_rate: -# self.last_throttled = int(time.time()) -# self.default_rate = 0.5 -# self.count_throttled = 0 -# return await handler(event, data) -# else: -# if self.count_throttled >= 2: -# self.default_rate = 3 -# else: -# try: -# self.count_throttled += 1 -# tx = translator(text='Many requests have been made', dest=lang) -# try: -# await event.callback_query.answer(tx) -# except: -# await bot.send_message( -# chat_id=user_id, -# text=tx, -# reply_markup=close_btn() -# ) -# except Exception as err: -# logging.error(err) -# -# self.last_throttled = int(time.time()) -# else: -# return await handler(event, data) +import logging +import time +from data.config import ADMIN +from keyboards.inline.close_btn import close_btn +from aiogram import BaseMiddleware, types +from aiogram.dispatcher.event.handler import HandlerObject +from loader import bot, db +from function.translator import translator + + +class ThrottlingMiddleware(BaseMiddleware): + """ + Middleware class to manage throttling of requests to prevent overloading. + This middleware limits the rate of incoming requests from users. + If a user exceeds the allowed request rate, they will receive a message indicating that they are making too many requests. + If a user receives the throttling warning 3 times within 1 minute, they are banned for 1 hour. + """ + + def __init__(self, default_rate: float = 0.5) -> None: + """ + Initializes the ThrottlingMiddleware instance. + + Parameters: + - default_rate (float): The minimal interval between allowed requests (in seconds), default is 0.5 seconds. + """ + self.limiters = {} # Dictionary to store per-user throttling data. + self.default_rate = default_rate + + + async def __call__(self, handler, event: types.Message, data): + """ + Processes incoming messages and enforces throttling rules. + If a user triggers throttling 3 times in 1 minute, they will be banned for 1 hour. + """ + real_handler = data["handler"] + skip_pass = True + + # Determine user id and language code. + if event.message: + user_id = event.message.from_user.id + lang = event.message.from_user.language_code + elif event.callback_query: + user_id = event.callback_query.from_user.id + lang = event.callback_query.from_user.language_code + else: + lang = 'en' + return await handler(event, data) + + if user_id == ADMIN: + return await handler(event, data) + + if real_handler.flags.get("skip_pass") is not None: + skip_pass = real_handler.flags.get("skip_pass") + + now = time.time() + # For each user we track: + # "last": timestamp of the last request, + # "count": number of throttled events in the current window, + # "first": start timestamp of the current 1-minute window. + user_data = self.limiters.get(user_id, {"last": now, "count": 0, "first": now}) + + if skip_pass: + # If enough time has passed since the last request, reset the throttling counter. + if now - user_data["last"] >= self.default_rate: + user_data["last"] = now + user_data["count"] = 0 # Reset counter. + user_data["first"] = now + self.limiters[user_id] = user_data + return await handler(event, data) + else: + # Update the throttling counter. If the current window is over 60 seconds, reset it. + if now - user_data["first"] > 60: + user_data["count"] = 0 + user_data["first"] = now + user_data["count"] += 1 + + # Agar throttling hisobi 3 yoki undan ko'p bo'lsa, foydalanuvchini ban qilamiz. + if user_data["count"] >= 3: + try: + db.ban_user_for_one_hour(user_id, comment="Too many requests") + tx = translator( + text='You have been banned for 1 hour due to too many requests.', + dest=lang + ) + await bot.send_message(chat_id=user_id, text=tx) + except Exception as err: + logging.error(f"Error banning user {user_id}: {err}") + # Reset the counter to oldindan qayta-ban qilishdan saqlanish uchun. + user_data["count"] = 0 + else: + try: + tx = translator(text='Many requests have been made', dest=lang) + try: + await event.callback_query.answer(tx) + except Exception: + await bot.send_message( + chat_id=user_id, + text=tx, + reply_markup=close_btn() + ) + except Exception as err: + logging.error(err) + + user_data["last"] = now + self.limiters[user_id] = user_data + return + else: + return await handler(event, data) From 3eebb3849583c1cca71082907c443969dd5a8c4a Mon Sep 17 00:00:00 2001 From: UznetDev Date: Fri, 28 Feb 2025 17:55:07 +0500 Subject: [PATCH 30/71] Enhance ban handling and user management: add ban time display in ban notifications, streamline user insertion in throttling middleware, and improve ban check logic. --- filters/ban.py | 50 ------- handlers/__init__.py | 1 - handlers/users/check_ban.py | 57 -------- handlers/users/start.py | 4 - middlewares/throttling.py | 284 +++++++++++++++++++++++++++++------- 5 files changed, 230 insertions(+), 166 deletions(-) delete mode 100644 filters/ban.py delete mode 100755 handlers/users/check_ban.py diff --git a/filters/ban.py b/filters/ban.py deleted file mode 100644 index 59e7f6d..0000000 --- a/filters/ban.py +++ /dev/null @@ -1,50 +0,0 @@ -import logging -from aiogram.filters import BaseFilter -from aiogram.types import Message -from data.config import ADMIN -from loader import db - - -class IsBan(BaseFilter): - """ - Filter to check if the user is banned. - - Attributes: - super_admin (int): The ID of the super admin. - """ - - def __init__(self): - self.super_admin = ADMIN - - - async def __call__(self, message: Message) -> bool: - """ - Checks if the message sender is banned. - - Args: - message (Message): The message object from the user. - - Returns: - bool: True if the user is banned, False otherwise. - """ - try: - self.user_id = message.from_user.id - # self.dada = db.select_admin(user_id=self.user_id) - check_ban = db.check_user_ban(user_id=self.user_id) - - # If the user is the super admin, they are not banned - if self.user_id == self.super_admin: - return False - # If the user is an admin, they are not banned - # elif self.dada is not None: - # return False - # If there is no ban record for the user, they are not banned - elif check_ban is None: - return False - # If the user is found in the ban list, they are banned - else: - return True - except Exception as err: - # Log any exceptions that occur and return False - logging.error(err) - return False diff --git a/handlers/__init__.py b/handlers/__init__.py index 72de50d..657e643 100755 --- a/handlers/__init__.py +++ b/handlers/__init__.py @@ -1,5 +1,4 @@ from .errors import error_handler -from .users import check_ban from .users import check_usr diff --git a/handlers/users/check_ban.py b/handlers/users/check_ban.py deleted file mode 100755 index 38a4c5c..0000000 --- a/handlers/users/check_ban.py +++ /dev/null @@ -1,57 +0,0 @@ -import logging -from loader import dp, bot, db -from aiogram import types -from function.translator import translator -from keyboards.inline.close_btn import close_btn -from data.config import yil_oy_kun, soat_minut_sekund, ADMIN -from filters.ban import IsBan - -@dp.message(IsBan()) -async def ban_handler(msg: types.Message): - """ - Handles incoming messages from banned users. Sends a message informing them of their ban status and provides - contact information for admins. Adds the user to the database if they are not already present. - - Args: - msg (types.Message): The incoming message from the user. - - Returns: - None - """ - try: - # Get the user's language code and ID - lang = msg.from_user.language_code - user_id = msg.from_user.id - - # Check if the user is banned and retrieve ban information - info = db.check_user_ban(user_id=user_id) - - # Retrieve admin information - text = translator(text="🛑 You are banned!:\n" - "⚠ If you think this is a mistake, contact the admin.", - dest=lang) - if info['initiator_user_id'] == 1 or info['initiator_user_id'] == 0: - text += f"\n\n👮‍♂️ Admin: Bot\n " - - else: - admin_info = await bot.get_chat(chat_id=info['updater_user_id']) - text += f"\n\n👮‍♂️ Admin @{admin_info.username}\n " - if info['comment'] is not None: - text += f"📝 Comment: {info['comment']}\n" - - admins = await bot.get_chat(chat_id=ADMIN) - - # Create the response message - - text += f'👩‍💻 Super admin @{admins.username}\n' - - # Send the response message to the user - await msg.answer(text=f"{text}", reply_markup=close_btn()) - - # Add the user to the database if they are not already present - if db.check_user(user_id=user_id) is None: - db.insert_user(user_id=user_id, - date=f"{yil_oy_kun} / {soat_minut_sekund}") - - except Exception as err: - logging.error(f"Error in start_handler: {err}") diff --git a/handlers/users/start.py b/handlers/users/start.py index 9e492cf..8e58532 100755 --- a/handlers/users/start.py +++ b/handlers/users/start.py @@ -42,9 +42,5 @@ async def start_handler(msg: types.Message): # Send the greeting and share button await msg.answer(translated_greeting, reply_markup=share_button) - # Check and log the user if not already in the database - if db.check_user(user_id) is None: - db.insert_user(user_id=user_id, - language_code=user_language) except Exception as err: logging.error(f"Error handling /start command: {err}") diff --git a/middlewares/throttling.py b/middlewares/throttling.py index 1038e27..436e998 100755 --- a/middlewares/throttling.py +++ b/middlewares/throttling.py @@ -3,7 +3,10 @@ from data.config import ADMIN from keyboards.inline.close_btn import close_btn from aiogram import BaseMiddleware, types -from aiogram.dispatcher.event.handler import HandlerObject +from aiogram.filters import BaseFilter +from aiogram.utils.keyboard import InlineKeyboardBuilder +from aiogram.types import Message, CallbackQuery +from keyboards.inline.button import MainCallback from loader import bot, db from function.translator import translator @@ -38,71 +41,244 @@ async def __call__(self, handler, event: types.Message, data): # Determine user id and language code. if event.message: user_id = event.message.from_user.id - lang = event.message.from_user.language_code + language_code = event.message.from_user.language_code elif event.callback_query: user_id = event.callback_query.from_user.id - lang = event.callback_query.from_user.language_code + language_code = event.callback_query.from_user.language_code else: - lang = 'en' + language_code = 'en' return await handler(event, data) + if user_id == ADMIN: return await handler(event, data) - if real_handler.flags.get("skip_pass") is not None: - skip_pass = real_handler.flags.get("skip_pass") - - now = time.time() - # For each user we track: - # "last": timestamp of the last request, - # "count": number of throttled events in the current window, - # "first": start timestamp of the current 1-minute window. - user_data = self.limiters.get(user_id, {"last": now, "count": 0, "first": now}) - - if skip_pass: - # If enough time has passed since the last request, reset the throttling counter. - if now - user_data["last"] >= self.default_rate: - user_data["last"] = now - user_data["count"] = 0 # Reset counter. - user_data["first"] = now - self.limiters[user_id] = user_data - return await handler(event, data) - else: - # Update the throttling counter. If the current window is over 60 seconds, reset it. - if now - user_data["first"] > 60: - user_data["count"] = 0 - user_data["first"] = now - user_data["count"] += 1 + user_data = db.check_user(user_id=user_id) + if user_data: + is_ban = await self.check_ban(user_data) + if is_ban: + return - # Agar throttling hisobi 3 yoki undan ko'p bo'lsa, foydalanuvchini ban qilamiz. - if user_data["count"] >= 3: - try: - db.ban_user_for_one_hour(user_id, comment="Too many requests") - tx = translator( - text='You have been banned for 1 hour due to too many requests.', - dest=lang - ) - await bot.send_message(chat_id=user_id, text=tx) - except Exception as err: - logging.error(f"Error banning user {user_id}: {err}") - # Reset the counter to oldindan qayta-ban qilishdan saqlanish uchun. - user_data["count"] = 0 + if real_handler.flags.get("skip_pass") is not None: + skip_pass = real_handler.flags.get("skip_pass") + + now = time.time() + # For each user we track: + # "last": timestamp of the last request, + # "count": number of throttled events in the current window, + # "first": start timestamp of the current 1-minute window. + user_data = self.limiters.get(user_id, {"last": now, "count": 0, "first": now}) + + if skip_pass: + # If enough time has passed since the last request, reset the throttling counter. + if now - user_data["last"] >= self.default_rate: + user_data["last"] = now + user_data["count"] = 0 # Reset counter. + user_data["first"] = now + self.limiters[user_id] = user_data + return await handler(event, data) else: - try: - tx = translator(text='Many requests have been made', dest=lang) + # Update the throttling counter. If the current window is over 60 seconds, reset it. + if now - user_data["first"] > 60: + user_data["count"] = 0 + user_data["first"] = now + user_data["count"] += 1 + + # Agar throttling hisobi 3 yoki undan ko'p bo'lsa, foydalanuvchini ban qilamiz. + if user_data["count"] >= 3: try: - await event.callback_query.answer(tx) - except Exception: - await bot.send_message( - chat_id=user_id, - text=tx, - reply_markup=close_btn() + db.ban_user_for_one_hour(user_id, comment="1 hour due to too many requests.") + tx = translator( + text='You have been banned for 1 hour due to too many requests.', + dest=language_code ) - except Exception as err: - logging.error(err) + await bot.send_message(chat_id=user_id, text=tx) + except Exception as err: + logging.error(f"Error banning user {user_id}: {err}") + # Reset the counter to oldindan qayta-ban qilishdan saqlanish uchun. + user_data["count"] = 0 + else: + try: + tx = translator(text='Many requests have been made', dest=language_code) + try: + await event.callback_query.answer(tx) + except Exception: + await bot.send_message( + chat_id=user_id, + text=tx, + reply_markup=close_btn() + ) + except Exception as err: + logging.error(err) - user_data["last"] = now - self.limiters[user_id] = user_data - return + user_data["last"] = now + self.limiters[user_id] = user_data + return + else: + return await handler(event, data) else: + db.insert_user(user_id=user_id, + language_code=language_code) return await handler(event, data) + + + + + + + async def check_ban(self, user_data): + try: + + if user_data['status'] == 'ban': + text = translator(text="🛑 You are banned!:\n" + "⚠ If you think this is a mistake, contact the admin.", + dest=user_data['language_code']) + if user_data['initiator_user_id'] == 1 or user_data['initiator_user_id'] == 0: + text += f"\n\n👮‍♂️ Admin: Bot\n " + elif user_data['initiator_user_id'] is not None: + admin_info = await bot.get_chat(chat_id=user_data['updater_user_id']) + text += f"\n\n👮‍♂️ Admin @{admin_info.username}\n " + if user_data['comment'] is not None: + text += f"\n📝 Comment: {user_data['comment']}\n" + + if user_data['ban_time'] is not None: + text += f"\n📅 Ban time: {user_data['ban_time']}\n" + + admins = await bot.get_chat(chat_id=ADMIN) + + text += f'👩‍💻 Super admin @{admins.username}\n' + + await bot.send_message(chat_id=user_data['user_id'], + text=f"{text}", + reply_markup=close_btn()) + return True + else: + return False + except Exception as err: + logging.error(err) + return False + + async def check_member(self, user_id): + try: + is_mandatory = await db.select_setting('mandatory_membership') + if is_mandatory is None: + db.update_settings_key(updater_user_id=1, key='mandatory_membership', value=False) + return False + elif is_mandatory == 'False': + return False + elif is_mandatory == 'True': + try: + channels = db.select_channels() + except Exception as err: + logging.error(f"Error selecting channels: {err}") + return False + + for channel in channels: + try: + chat_id = int("-100" + str(channel.get('channel_id'))) + res = await bot.get_chat_member(chat_id=chat_id, user_id=user_id) + + if res.status not in ('member', 'administrator', 'creator'): + count = 0 + + keyboard = InlineKeyboardBuilder() + message_text = translator(text="🛑 You have not joined the channel(s)!:\n\n", dest=language_code) + + for x in channels: + channel_id = str(-100) + str(x['channel_id']) + channel = await bot.get_chat(channel_id) + + try: + chat_member_status = await bot.get_chat_member(chat_id=channel_id, user_id=user_id) + except Exception as e: + logging.error(f"Error getting chat member status: {e}") + continue + + # Check if the user is a member of the channel + if chat_member_status.status not in ('member', 'administrator', 'creator'): + count += 1 + message_text += f"\n{count}. ⭕ {channel.full_name} @{channel.username} ❓\n" + keyboard.button(text='➕ ' + channel.title, + url=f"{await channel.export_invite_link()}") + + # Add a button to check again + keyboard.button(text=translator(text='♻ Check!', dest=language_code), + callback_data=MainCallback(action="check_join", q='').pack()) + keyboard.adjust(1) + + # Send the message to the user + await msg.answer(text=f"{message_text}", reply_markup=keyboard.as_markup()) + return True + except Exception as err: + logging.error(f"Error checking membership for channel {channel.get('channel_id')}: {err}") + continue + + # If all channels checked and no problems found, return False. + return False + + + except Exception as err: + logging.error(err) + return False + + + + + + + +class UserCheck(BaseFilter, BaseMiddleware): + """ + Middleware and filter class to check if a user is a member of required channels. + Ensures that users are members of specified channels before they can access certain bot features. + """ + + def __init__(self): + self.ADMIN = ADMIN + + async def __call__(self, message: Message = None, call: CallbackQuery = None) -> bool: + # Check if channel joining is required + try: + data = DB.reading_db() + except Exception as err: + logging.error(f"Error reading DB: {err}") + return False + + if not data.get('join_channel'): + return False + + # Extract user_id and language from message or callback query. + if message is not None: + user_id = message.from_user.id + lang = message.from_user.language_code + elif call is not None: + user_id = call.from_user.id + lang = call.from_user.language_code + else: + return False + + # Bypass the check for the admin user. + if user_id == self.ADMIN: + return False + + # Check each channel's membership. + try: + channels = db.select_channels() + except Exception as err: + logging.error(f"Error selecting channels: {err}") + return False + + # For each required channel, check if the user is a member. + for channel in channels: + try: + chat_id = int("-100" + str(channel.get('channel_id'))) + res = await bot.get_chat_member(chat_id=chat_id, user_id=user_id) + if res.status not in ('member', 'administrator', 'creator'): + # If the user is not a member in any one channel, force is True. + return True + except Exception as err: + logging.error(f"Error checking membership for channel {channel.get('channel_id')}: {err}") + continue + + # If all channels checked and no problems found, return False. + return False From 32b7004b96e2643e2f5040c8f76da25b27297dec Mon Sep 17 00:00:00 2001 From: UznetDev Date: Sat, 1 Mar 2025 09:09:44 +0500 Subject: [PATCH 31/71] Refactor ThrottlingMiddleware: enhance member check logic and streamline message sending for channel membership verification --- middlewares/throttling.py | 88 +++++++-------------------------------- 1 file changed, 14 insertions(+), 74 deletions(-) diff --git a/middlewares/throttling.py b/middlewares/throttling.py index 436e998..7b83068 100755 --- a/middlewares/throttling.py +++ b/middlewares/throttling.py @@ -58,6 +58,9 @@ async def __call__(self, handler, event: types.Message, data): is_ban = await self.check_ban(user_data) if is_ban: return + is_member = await self.check_member(user_data) + if is_member: + return if real_handler.flags.get("skip_pass") is not None: skip_pass = real_handler.flags.get("skip_pass") @@ -122,10 +125,6 @@ async def __call__(self, handler, event: types.Message, data): return await handler(event, data) - - - - async def check_ban(self, user_data): try: @@ -158,7 +157,8 @@ async def check_ban(self, user_data): logging.error(err) return False - async def check_member(self, user_id): + + async def check_member(self, user_id, language_code): try: is_mandatory = await db.select_setting('mandatory_membership') if is_mandatory is None: @@ -201,13 +201,15 @@ async def check_member(self, user_id): keyboard.button(text='➕ ' + channel.title, url=f"{await channel.export_invite_link()}") - # Add a button to check again - keyboard.button(text=translator(text='♻ Check!', dest=language_code), - callback_data=MainCallback(action="check_join", q='').pack()) - keyboard.adjust(1) + # Add a button to check again + keyboard.button(text=translator(text='♻ Check!', dest=language_code), + callback_data=MainCallback(action="check_join", q='').pack()) + keyboard.adjust(1) - # Send the message to the user - await msg.answer(text=f"{message_text}", reply_markup=keyboard.as_markup()) + # Send the message to the user + await bot.send_message(chat_id=user_id, + text=f"{message_text}", + reply_markup=keyboard.as_markup()) return True except Exception as err: logging.error(f"Error checking membership for channel {channel.get('channel_id')}: {err}") @@ -219,66 +221,4 @@ async def check_member(self, user_id): except Exception as err: logging.error(err) - return False - - - - - - - -class UserCheck(BaseFilter, BaseMiddleware): - """ - Middleware and filter class to check if a user is a member of required channels. - Ensures that users are members of specified channels before they can access certain bot features. - """ - - def __init__(self): - self.ADMIN = ADMIN - - async def __call__(self, message: Message = None, call: CallbackQuery = None) -> bool: - # Check if channel joining is required - try: - data = DB.reading_db() - except Exception as err: - logging.error(f"Error reading DB: {err}") - return False - - if not data.get('join_channel'): - return False - - # Extract user_id and language from message or callback query. - if message is not None: - user_id = message.from_user.id - lang = message.from_user.language_code - elif call is not None: - user_id = call.from_user.id - lang = call.from_user.language_code - else: - return False - - # Bypass the check for the admin user. - if user_id == self.ADMIN: - return False - - # Check each channel's membership. - try: - channels = db.select_channels() - except Exception as err: - logging.error(f"Error selecting channels: {err}") - return False - - # For each required channel, check if the user is a member. - for channel in channels: - try: - chat_id = int("-100" + str(channel.get('channel_id'))) - res = await bot.get_chat_member(chat_id=chat_id, user_id=user_id) - if res.status not in ('member', 'administrator', 'creator'): - # If the user is not a member in any one channel, force is True. - return True - except Exception as err: - logging.error(f"Error checking membership for channel {channel.get('channel_id')}: {err}") - continue - - # If all channels checked and no problems found, return False. - return False + return False \ No newline at end of file From 452608512f201975a9c7c0cf7767c9a3ac97697f Mon Sep 17 00:00:00 2001 From: UznetDev Date: Sat, 1 Mar 2025 10:05:59 +0500 Subject: [PATCH 32/71] Refactor language code handling: standardize variable naming for language code across multiple handlers and improve clarity in admin settings and message responses. --- db/database.py | 21 +-- handlers/__init__.py | 10 +- handlers/admins/admin_settings/add_admin.py | 20 +-- .../admin_settings/add_admin_first_step.py | 8 +- .../admins/admin_settings/admin_setting.py | 8 +- .../admins/callback_query/main_admin_panel.py | 6 +- .../channel_settings/channel_setting.py | 10 +- .../admins/channel_settings/delete_channel.py | 10 +- handlers/admins/channel_settings/get_id.py | 12 +- .../channel_settings/mandatory_membership.py | 25 ++-- .../admins/channel_settings/remove_channel.py | 8 +- handlers/admins/check_usr/attach_usr.py | 22 ++-- handlers/admins/check_usr/block_users.py | 12 +- handlers/admins/main_panel.py | 6 +- handlers/admins/send_ads/get_message.py | 2 +- handlers/admins/statistika/staristika.py | 2 +- handlers/admins/super_admin.py | 4 +- handlers/users/check_usr.py | 121 ------------------ handlers/users/help.py | 2 +- keyboards/inline/admin_btn.py | 72 +++++------ keyboards/inline/user.py | 8 +- loader.py | 7 +- main.py | 6 +- middlewares/throttling.py | 1 - 24 files changed, 141 insertions(+), 262 deletions(-) delete mode 100755 handlers/users/check_usr.py diff --git a/db/database.py b/db/database.py index 0e21e9d..23c97a9 100755 --- a/db/database.py +++ b/db/database.py @@ -113,9 +113,9 @@ def create_table_channel(self): sql = """ CREATE TABLE IF NOT EXISTS `channels` ( `id` INT AUTO_INCREMENT PRIMARY KEY, - `channel_id` bigint(200), - `initiator_user_id` bigint(200), - `updater_user_id` bigint(200), + `channel_id` BIGINT, + `initiator_user_id` BIGINT, + `updater_user_id` BIGINT, `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP @@ -138,9 +138,9 @@ def create_table_admins(self): sql = """ CREATE TABLE IF NOT EXISTS `admins` ( `id` INT AUTO_INCREMENT PRIMARY KEY, - `user_id` bigint(200) NOT NULL UNIQUE, - `initiator_user_id` bigint(200), - `updater_user_id` bigint(200), + `user_id` BIGINT NOT NULL UNIQUE, + `initiator_user_id` BIGINT, + `updater_user_id` BIGINT, `send_message` TINYINT(1) DEFAULT 0, `statistika` TINYINT(1) DEFAULT 0, `download_statistika` TINYINT(1) DEFAULT 0, @@ -168,8 +168,8 @@ def create_table_settings(self): sql = """ CREATE TABLE IF NOT EXISTS `settings` ( `id` INT AUTO_INCREMENT PRIMARY KEY, - `updater_user_id` bigint(200) NOT NULL UNIQUE, - `initiator_user_id` bigint(200), + `updater_user_id` BIGINT, + `initiator_user_id` BIGINT, `key` VARCHAR(255) NOT NULL, `value` VARCHAR(255) NOT NULL, `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, @@ -388,7 +388,10 @@ def select_setting(self, key: str): values = (key,) self.cursor.execute(sql, values) result = self.cursor.fetchone() - return result[0] + if result is None: + return None + else: + return result['value'] except mysql.connector.Error as err: logging.error(err) self.reconnect() diff --git a/handlers/__init__.py b/handlers/__init__.py index 657e643..8e14b20 100755 --- a/handlers/__init__.py +++ b/handlers/__init__.py @@ -1,15 +1,13 @@ from .errors import error_handler -from .users import check_usr - from .users import start from .admins import main_panel from .admins.admin_settings import add_admin from .admins.channel_settings import get_id from .admins.check_usr import attach_usr -from .admins.check_usr import send_ads_message -from .admins.send_ads import get_message +# from .admins.check_usr import send_ads_message +# from .admins.send_ads import get_message from .admins import super_admin from .users import help @@ -34,8 +32,8 @@ from .admins.check_usr import block_users from .admins.check_usr import send_message -from .admins.send_ads import send_ads -from .admins.send_ads import stop_ads +# from .admins.send_ads import send_ads +# from .admins.send_ads import stop_ads from .admins.statistika import staristika from .admins.statistika import download_statistics diff --git a/handlers/admins/admin_settings/add_admin.py b/handlers/admins/admin_settings/add_admin.py index 033ecb5..641137c 100755 --- a/handlers/admins/admin_settings/add_admin.py +++ b/handlers/admins/admin_settings/add_admin.py @@ -36,14 +36,14 @@ async def add_admin(msg: types.Message, state: FSMContext): try: user_id = msg.from_user.id # The ID of the admin who is performing the action mid = msg.message_id # The ID of the message to be updated - lang = msg.from_user.language_code # The language code for translation + language_code = msg.from_user.language_code # The language code for translation data = SelectAdmin(user_id=user_id) # Retrieves admin settings for the current user add_admin_db = data.add_admin() # Check if the user has the right to add an admin target_user_id = int(msg.text) # The ID of the user to be added as an admin if add_admin_db: data_state = await state.get_data() # Get current state data - btn = await admin_setting(user_id=user_id, lang=lang) # Prepare admin settings buttons + btn = await admin_setting(user_id=user_id, language_code=language_code) # Prepare admin settings buttons text = "🔴 Admin failed because admin was not found!\n" try: @@ -55,39 +55,39 @@ async def add_admin(msg: types.Message, state: FSMContext): db.insert_admin(user_id=target_user_id, initiator_user_id=user_id) text = translator(text="✅ Admin has been successfully added\n\nName: ", - dest=lang) + dest=language_code) text += f"{user.full_name}\n" text += f'Username: @{user.username}\n' await bot.send_message(chat_id=target_user_id, text=f'😊Hi @{user.username}, you have been made an admin\n' f'To open the panel, use /admin ', reply_markup=close_btn()) - btn = await admin_setting(user_id=user_id, lang=lang) # Prepare admin settings buttons + btn = await admin_setting(user_id=user_id, language_code=language_code) # Prepare admin settings buttons else: text = translator(text="✅ Admin was added before\n\nName: ", - dest=lang) + dest=language_code) text += f"{user.full_name}\n" text += f'Username: @{user.username}\n' text += translator(text="Add date: ", - dest=lang) + dest=language_code) text += f'{check[9]}\n{check[2]}' text += translator(text="Added by", - dest=lang) + dest=language_code) except Exception as err: logging.error(err) # Log any errors that occur text = translator(text="🔴 Admin failed because admin was not found!\n" "The bot may not have found the admin..", - dest=lang) + dest=language_code) finally: text = translator(text=text, - dest=lang) + dest=language_code) await bot.edit_message_text(chat_id=user_id, message_id=data_state['message_id'], text=text, reply_markup=btn) else: text = translator(text='❌ Unfortunately, you do not have this right!', - dest=lang) + dest=language_code) btn = close_btn() await bot.edit_message_text(chat_id=user_id, message_id=mid, diff --git a/handlers/admins/admin_settings/add_admin_first_step.py b/handlers/admins/admin_settings/add_admin_first_step.py index 6da710d..b362506 100755 --- a/handlers/admins/admin_settings/add_admin_first_step.py +++ b/handlers/admins/admin_settings/add_admin_first_step.py @@ -35,18 +35,18 @@ async def add_admin_first(call: types.CallbackQuery, state: FSMContext): try: user_id = call.from_user.id # ID of the admin initiating the request mid = call.message.message_id # ID of the message to be updated - lang = call.from_user.language_code # Language code for translation + language_code = call.from_user.language_code # Language code for translation data = SelectAdmin(user_id=user_id) # Retrieves admin settings for the current user add_admin = data.add_admin() # Checks if the user has the right to add an admin if add_admin: # Prompt the user to provide the ID of the new admin - text = translator(text="🔰 Please send the admin ID number you want to add...", dest=lang) - btn = await admin_setting(user_id=user_id, lang=lang) # Prepare admin settings buttons + text = translator(text="🔰 Please send the admin ID number you want to add...", dest=language_code) + btn = await admin_setting(user_id=user_id, language_code=language_code) # Prepare admin settings buttons await state.set_state(AdminState.add_admin) # Set the FSM state for adding an admin else: # Inform the user that they do not have the necessary permissions - text = translator(text="❌ Unfortunately, you do not have this right!", dest=lang) + text = translator(text="❌ Unfortunately, you do not have this right!", dest=language_code) btn = close_btn() # Prepare close button # Update the message with the appropriate response and buttons diff --git a/handlers/admins/admin_settings/admin_setting.py b/handlers/admins/admin_settings/admin_setting.py index dc6686a..83a9b3e 100755 --- a/handlers/admins/admin_settings/admin_setting.py +++ b/handlers/admins/admin_settings/admin_setting.py @@ -33,17 +33,17 @@ async def admin_settings(call: types.CallbackQuery, state: FSMContext): try: user_id = call.from_user.id # ID of the admin initiating the request mid = call.message.message_id # ID of the message to be updated - lang = call.from_user.language_code # Language code for translation + language_code = call.from_user.language_code # Language code for translation data = SelectAdmin(user_id=user_id) # Retrieves admin settings for the current user add_admin = data.add_admin() # Checks if the user has the right to access admin settings if add_admin: # The admin has the right to access settings - text = translator(text="❗ You are in the Admin settings section!", dest=lang) - btn = await admin_setting(user_id=user_id, lang=lang) # Prepare admin settings buttons + text = translator(text="❗ You are in the Admin settings section!", dest=language_code) + btn = await admin_setting(user_id=user_id, language_code=language_code) # Prepare admin settings buttons else: # The admin does not have the necessary rights - text = translator(text="❌ Unfortunately, you do not have this right!", dest=lang) + text = translator(text="❌ Unfortunately, you do not have this right!", dest=language_code) btn = close_btn() # Prepare close button # Update the message with the appropriate response and buttons diff --git a/handlers/admins/callback_query/main_admin_panel.py b/handlers/admins/callback_query/main_admin_panel.py index 259f6a2..42571f1 100755 --- a/handlers/admins/callback_query/main_admin_panel.py +++ b/handlers/admins/callback_query/main_admin_panel.py @@ -32,16 +32,16 @@ async def main_panel(call: types.CallbackQuery, state: FSMContext): try: user_id = call.from_user.id # The ID of the admin who initiated the action mid = call.message.message_id # The ID of the message to be updated - lang = call.from_user.language_code # The language code for translation + language_code = call.from_user.language_code # The language code for translation # Translate the greeting message - text = translator(text="👩‍💻Hello, dear admin, welcome to the main panel!", dest=lang) + text = translator(text="👩‍💻Hello, dear admin, welcome to the main panel!", dest=language_code) # Edit the message with the translated text and update it with the main admin panel buttons await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f'{text}', - reply_markup=main_admin_panel_btn(user_id=user_id, lang=lang)) + reply_markup=main_admin_panel_btn(user_id=user_id, language_code=language_code)) # Update FSM state with the current message ID await state.update_data({"message_id": call.message.message_id}) diff --git a/handlers/admins/channel_settings/channel_setting.py b/handlers/admins/channel_settings/channel_setting.py index 9dea8fb..7763846 100755 --- a/handlers/admins/channel_settings/channel_setting.py +++ b/handlers/admins/channel_settings/channel_setting.py @@ -34,7 +34,7 @@ async def channel_setting(call: types.CallbackQuery, state: FSMContext): try: user_id = call.from_user.id # The ID of the admin initiating the action mid = call.message.message_id # The ID of the message triggering the callback - lang = call.from_user.language_code # The language code of the admin for message translation + language_code = call.from_user.language_code # The language code of the admin for message translation data = SelectAdmin(user_id=user_id) # Check if the admin has permission to manage channel settings btn = close_btn() # Inline button to close the message @@ -48,10 +48,10 @@ async def channel_setting(call: types.CallbackQuery, state: FSMContext): if not data: # If no channels are found, indicate that the list is empty - text = translator(text="❔ The channel list is empty!\n\n", dest=lang) + text = translator(text="❔ The channel list is empty!\n\n", dest=language_code) else: # Construct a message listing the channels - text = translator(text="🔰 List of channels:\n\n", dest=lang) + text = translator(text="🔰 List of channels:\n\n", dest=language_code) count = 0 for x in data: try: @@ -64,10 +64,10 @@ async def channel_setting(call: types.CallbackQuery, state: FSMContext): f"Added by user_id: {x[3]}\n\n") except Exception as err: logging.error(err) # Log any errors in retrieving channel details - btn = channel_settings(lang=lang) # Button for channel settings + btn = channel_settings(language_code=language_code) # Button for channel settings else: # Inform the admin that they do not have the necessary permissions - text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) + text = translator(text='❌ Unfortunately, you do not have this right!', dest=language_code) await bot.edit_message_text( chat_id=user_id, diff --git a/handlers/admins/channel_settings/delete_channel.py b/handlers/admins/channel_settings/delete_channel.py index 2671bd4..802f9f2 100755 --- a/handlers/admins/channel_settings/delete_channel.py +++ b/handlers/admins/channel_settings/delete_channel.py @@ -33,7 +33,7 @@ async def delete_channel(call: types.CallbackQuery, callback_data: AdminCallback try: user_id = call.from_user.id # The ID of the admin making the request mid = call.message.message_id # The ID of the message associated with the callback - lang = call.from_user.language_code # The language code for translating responses + language_code = call.from_user.language_code # The language code for translating responses data = SelectAdmin(user_id=user_id) # Check if the user has admin permissions btn = close_btn() # A button for closing the message @@ -46,7 +46,7 @@ async def delete_channel(call: types.CallbackQuery, callback_data: AdminCallback # Inform the user if the channel does not exist text = translator( text='⭕ Channel not found!\nThe channel seems to have been deleted previously!', - dest=lang) + dest=language_code) else: # Get channel details using the Telegram API channel = await bot.get_chat(chat_id=ch_user_id100) @@ -54,17 +54,17 @@ async def delete_channel(call: types.CallbackQuery, callback_data: AdminCallback if check[3] == user_id or user_id == ADMIN: # Delete the channel if the user is authorized db.delete_channel(channel_id=ch_user_id) - tx = translator(text='🚫 Channel removed...\n', dest=lang) + tx = translator(text='🚫 Channel removed...\n', dest=language_code) text = (f"{tx}\n" f"Name: {channel.full_name}\n" f"Username: @{channel.username}\n" f"ID: {ch_user_id}\n\n") else: # Inform the user if they do not have permission to delete the channel - text = translator(text='⭕ Only an admin can delete this channel.', dest=lang) + text = translator(text='⭕ Only an admin can delete this channel.', dest=language_code) else: # Inform the user if they lack the necessary permissions - text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) + text = translator(text='❌ Unfortunately, you do not have this right!', dest=language_code) await bot.edit_message_text(chat_id=user_id, message_id=mid, diff --git a/handlers/admins/channel_settings/get_id.py b/handlers/admins/channel_settings/get_id.py index 6c9f6b5..e21017b 100755 --- a/handlers/admins/channel_settings/get_id.py +++ b/handlers/admins/channel_settings/get_id.py @@ -33,7 +33,7 @@ async def add_channel2(msg: types.Message, state: FSMContext): try: user_id = msg.from_user.id # The ID of the admin making the request mid = msg.message_id # The ID of the message associated with the request - lang = msg.from_user.language_code # The language code for translating responses + language_code = msg.from_user.language_code # The language code for translating responses data = SelectAdmin(user_id=user_id) # Check if the user has admin permissions btn = close_btn() # A button for closing the message data_state = await state.get_data() # Get data stored in the FSM state @@ -49,25 +49,25 @@ async def add_channel2(msg: types.Message, state: FSMContext): # Add the channel to the database if it doesn't exist db.insert_channel(channel_id=tx, initiator_user_id=user_id) - text = translator(text="✅ The channel was successfully added\n", dest=lang) + text = translator(text="✅ The channel was successfully added\n", dest=language_code) text += f"Name: {channel.full_name}\n" \ f"Username: @{channel.username}" else: # Inform the user if the channel is already in the database - text = translator(text="✅ The channel was previously added\n", dest=lang) + text = translator(text="✅ The channel was previously added\n", dest=language_code) text += f"Name: {channel.full_name}\n" \ f"Username: @{channel.username}\n" \ f"Added date: {check[3]}" - btn = channel_settings(lang=lang) # Update the button for channel settings + btn = channel_settings(language_code=language_code) # Update the button for channel settings except Exception as err: # Handle exceptions such as the bot not being an admin in the channel text = translator(text="🔴 The channel could not be added because the channel was not found!\n" - "The bot is not an admin on the channel.", dest=lang) + "The bot is not an admin on the channel.", dest=language_code) logging.error(err) await state.clear() # Clear the FSM state else: - text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) + text = translator(text='❌ Unfortunately, you do not have this right!', dest=language_code) # Update the message with the result and close button await bot.edit_message_text(chat_id=user_id, diff --git a/handlers/admins/channel_settings/mandatory_membership.py b/handlers/admins/channel_settings/mandatory_membership.py index 484d674..ea3a9a8 100755 --- a/handlers/admins/channel_settings/mandatory_membership.py +++ b/handlers/admins/channel_settings/mandatory_membership.py @@ -1,5 +1,5 @@ import logging -from loader import dp, bot, DB +from loader import dp, bot, db from aiogram import types, F from keyboards.inline.button import AdminCallback from keyboards.inline.admin_btn import channel_settings @@ -8,6 +8,7 @@ from aiogram.fsm.context import FSMContext from function.translator import translator + @dp.callback_query(AdminCallback.filter(F.action == "mandatory_membership"), IsAdmin()) async def mandatory_membership(call: types.CallbackQuery, state: FSMContext): """ @@ -18,7 +19,7 @@ async def mandatory_membership(call: types.CallbackQuery, state: FSMContext): - state (FSMContext): The FSM context to manage the bot's state during the conversation. Functionality: - - Retrieves the admin's user ID (`user_id`), the message ID (`mid`), and the language code (`lang`) from the callback query. + - Retrieves the admin's user ID (`user_id`), the message ID (`mid`), and the language_codeuage code (`language_code`) from the callback query. - Checks if the user has the required permissions to modify channel settings using the `SelectAdmin` filter. - If authorized, reads the current mandatory membership status from the database. - Toggles the membership requirement status: @@ -34,27 +35,27 @@ async def mandatory_membership(call: types.CallbackQuery, state: FSMContext): try: user_id = call.from_user.id # The ID of the admin who initiated the action mid = call.message.message_id # The ID of the message to be updated - lang = call.from_user.language_code # The language code for translation + language_code = call.from_user.language_code # The language_codeuage code for translation data = SelectAdmin(user_id=user_id) # Check if the user has admin permissions btn = close_btn() # Create a button for closing the message if data.channel_settings(): # Read the current setting for mandatory membership from the database - data = DB.reading_db() - if data['join_channel']: + join_channel = db.select_setting('join_channel') + if join_channel: # If mandatory membership is enabled, disable it - text = translator(text='☑️ Forced membership disabled!', dest=lang) - join_channel = False + text = translator(text='☑️ Forced membership disabled!', dest=language_code) + nex_join_channel = False else: # If mandatory membership is disabled, enable it - text = translator(text='✅ Mandatory membership enabled!', dest=lang) - join_channel = True + text = translator(text='✅ Mandatory membership enabled!', dest=language_code) + nex_join_channel = True # Update the database with the new membership status - DB.change_data(join_channel=join_channel) - btn = channel_settings(lang=lang) # Update the button to reflect the new settings + db.update_settings_key('join_channel', nex_join_channel) + btn = channel_settings(language_code=language_code) # Update the button to reflect the new settings else: - text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) + text = translator(text='❌ Unfortunately, you do not have this right!', dest=language_code) # Edit the message with the new status and close button await bot.edit_message_text(chat_id=user_id, diff --git a/handlers/admins/channel_settings/remove_channel.py b/handlers/admins/channel_settings/remove_channel.py index 289d122..4604e07 100755 --- a/handlers/admins/channel_settings/remove_channel.py +++ b/handlers/admins/channel_settings/remove_channel.py @@ -33,7 +33,7 @@ async def remove_channel(call: types.CallbackQuery, state: FSMContext): try: user_id = call.from_user.id # The ID of the admin who initiated the action mid = call.message.message_id # The ID of the message to be updated - lang = call.from_user.language_code # The language code for translation + language_code = call.from_user.language_code # The language code for translation data = SelectAdmin(user_id=user_id) # Check if the user has admin permissions btn = InlineKeyboardBuilder() # Create an instance of InlineKeyboardBuilder for the keyboard @@ -49,10 +49,10 @@ async def remove_channel(call: types.CallbackQuery, state: FSMContext): if not data: # Inform the admin if no channels are available - text = translator(text="❔ The channel list is empty!\n\n", dest=lang) + text = translator(text="❔ The channel list is empty!\n\n", dest=language_code) else: # Display the list of channels with options to delete them - text = translator(text="🔰 Choose a channel:\n\n", dest=lang) + text = translator(text="🔰 Choose a channel:\n\n", dest=language_code) count = 0 for x in data: @@ -74,7 +74,7 @@ async def remove_channel(call: types.CallbackQuery, state: FSMContext): btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) else: # Inform the admin if they do not have the right to access channel settings - text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) + text = translator(text='❌ Unfortunately, you do not have this right!', dest=language_code) # Edit the message with the updated text and keyboard await bot.edit_message_text(chat_id=call.from_user.id, diff --git a/handlers/admins/check_usr/attach_usr.py b/handlers/admins/check_usr/attach_usr.py index e3bf31e..1228915 100755 --- a/handlers/admins/check_usr/attach_usr.py +++ b/handlers/admins/check_usr/attach_usr.py @@ -33,11 +33,11 @@ async def attach_user(msg: types.Message, state: FSMContext): try: user_id = msg.from_user.id # Chat ID of the admin mid = msg.message_id # Message ID of the current message - lang = msg.from_user.language_code # Language code of the admin + language_code = msg.from_user.language_code # Language code of the admin is_admin = SelectAdmin(user_id=user_id) # Check admin permissions attention_user_id = int(msg.text) # Extract user ID from the message btn = close_btn() # Initialize the close button - text = translator(text="🔴 Something went wrong!\n", dest=lang) # Default error message + text = translator(text="🔴 Something went wrong!\n", dest=language_code) # Default error message if is_admin.block_user(): data_state = await state.get_data() # Get the current state data @@ -47,7 +47,7 @@ async def attach_user(msg: types.Message, state: FSMContext): check1 = db.check_user(user_id=attention_user_id) # Check if the user exists in the bot's list if check1 is not None: - btn = block_user(attention_user_id=attention_user_id, user_id=user_id, lang=lang) # Button for blocking/unblocking user + btn = block_user(attention_user_id=attention_user_id, user_id=user_id, language_code=language_code) # Button for blocking/unblocking user if check is None: check2 = db.select_admin(user_id=attention_user_id) # Check if the user is an admin select_user = db.check_user(user_id) # Get information about the user @@ -55,23 +55,23 @@ async def attach_user(msg: types.Message, state: FSMContext): if check2 is None: # User is successfully unblocked text = "✅ User unblocked!" - text += translator(text=f'\n\nUsername: @', dest=lang) + user.username - text += translator(text='\nLanguage code: ', dest=lang) + f'{select_user[3]}' + text += translator(text=f'\n\nUsername: @', dest=language_code) + user.username + text += translator(text='\nLanguage code: ', dest=language_code) + f'{select_user[3]}' else: # User is blocked but is an admin tx = "✅ User blocked!\n👮‍♂️ User is in the list of admins!" - text = translator(text=f'{tx}\n\nUsername: @', dest=lang) + user.username - text += translator(text='\nLanguage code: ', dest=lang) + f'{select_user[3]}' + text = translator(text=f'{tx}\n\nUsername: @', dest=language_code) + user.username + text += translator(text='\nLanguage code: ', dest=language_code) + f'{select_user[3]}' else: # User is already blocked tx = "✅ User blocked!\n Date:" - text = translator(text=f'{tx} {check[3]}\n\nUsername: @', dest=lang) + user.username + text = translator(text=f'{tx} {check[3]}\n\nUsername: @', dest=language_code) + user.username else: # User not found in the bot's list - text = translator(text="🔴 User not found!\nThe user may not be in the bot's list..", dest=lang) + text = translator(text="🔴 User not found!\nThe user may not be in the bot's list..", dest=language_code) except Exception as err: logging.error(err) - text = translator(text="🔴 User not found!\nThe bot may not have found the user..", dest=lang) + text = translator(text="🔴 User not found!\nThe bot may not have found the user..", dest=language_code) finally: # Update the message with the result and provide the close button await bot.edit_message_text(chat_id=user_id, @@ -80,7 +80,7 @@ async def attach_user(msg: types.Message, state: FSMContext): reply_markup=btn) else: # User does not have permission to block/unblock users - text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) + text = translator(text='❌ Unfortunately, you do not have this right!', dest=language_code) # Edit the original message to reflect the result await bot.edit_message_text(chat_id=user_id, diff --git a/handlers/admins/check_usr/block_users.py b/handlers/admins/check_usr/block_users.py index aefecec..aba2c40 100755 --- a/handlers/admins/check_usr/block_users.py +++ b/handlers/admins/check_usr/block_users.py @@ -39,7 +39,7 @@ async def block_users(call: types.CallbackQuery, callback_data: BlockUser, state attention_user_id = callback_data.user_id # The ID of the user to be blocked/unblocked user_id = call.from_user.id # The ID of the admin issuing the block/unblock command mid = call.message.message_id # The ID of the message triggering the callback - lang = call.from_user.language_code # The language code of the admin for message translation + language_code = call.from_user.language_code # The language code of the admin for message translation data = SelectAdmin(user_id=user_id) # Check if the admin is authorized to perform the action btn = close_btn() # Inline button to close the message @@ -52,7 +52,7 @@ async def block_users(call: types.CallbackQuery, callback_data: BlockUser, state db.update_user_status(user_id=attention_user_id, status='blocked', updater_user_id=user_id) # Update user status to blocked - text = translator(text='⛔ User blocked\n\n Username: @', dest=lang) + text = translator(text='⛔ User blocked\n\n Username: @', dest=language_code) text += str(user.username) await bot.send_message(chat_id=attention_user_id, text='🚫 You are blocked! If you think this is a mistake, contact the admin.', @@ -62,16 +62,16 @@ async def block_users(call: types.CallbackQuery, callback_data: BlockUser, state db.update_user_status(user_id=attention_user_id, status='active', updater_user_id=user_id) # Update user status to active - text = translator(text='✅ User unblocked!\n\n Username: @', dest=lang) + text = translator(text='✅ User unblocked!\n\n Username: @', dest=language_code) text += str(user.username) await bot.send_message(chat_id=attention_user_id, text='😊 You are unblocked! Contact the admin.', reply_markup=close_btn()) # Notify the user of the unblock else: - text = translator(text='⭕ Only the person who blocked the user can unblock them!\n\n Username: @', dest=lang) + text = translator(text='⭕ Only the person who blocked the user can unblock them!\n\n Username: @', dest=language_code) text += str(user.username) # Inform that only the original admin can unblock else: - text = translator(text='🚫 I cannot block an admin.', dest=lang) + text = translator(text='🚫 I cannot block an admin.', dest=language_code) try: db.update_user_status(user_id=attention_user_id, status='active', @@ -80,7 +80,7 @@ async def block_users(call: types.CallbackQuery, callback_data: BlockUser, state logging.error(err) # Log any errors encountered await state.set_state(AdminState.check_user) # Update the FSM state else: - text = translator(text='❌ Unfortunately, you do not have this right!', dest=lang) + text = translator(text='❌ Unfortunately, you do not have this right!', dest=language_code) await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f'{text}', diff --git a/handlers/admins/main_panel.py b/handlers/admins/main_panel.py index 2d22d34..a5924eb 100755 --- a/handlers/admins/main_panel.py +++ b/handlers/admins/main_panel.py @@ -29,13 +29,13 @@ async def main_panel(msg: types.Message, state: FSMContext): try: user_id = msg.from_user.id message_id = msg.message_id - lang = msg.from_user.language_code + language_code = msg.from_user.language_code # Translate and send the welcome message with admin panel buttons welcome_text = translator(text=f'👩‍💻Hello, dear admin, welcome to the main panel!', - dest=lang) + dest=language_code) response_msg = await msg.answer(text=f'{welcome_text}', - reply_markup=main_admin_panel_btn(user_id=user_id, lang=lang)) + reply_markup=main_admin_panel_btn(user_id=user_id, language_code=language_code)) # Manage previous message state_data = await state.get_data() diff --git a/handlers/admins/send_ads/get_message.py b/handlers/admins/send_ads/get_message.py index f31e497..3a312aa 100755 --- a/handlers/admins/send_ads/get_message.py +++ b/handlers/admins/send_ads/get_message.py @@ -46,7 +46,7 @@ async def get_message(msg: types.Message, state: FSMContext): if is_admin.send_message(): # Prepare the admin panel button and fetch ads data - button_markup = main_admin_panel_btn(user_id=user_id, lang=language_code) + button_markup = main_admin_panel_btn(user_id=user_id, language_code=language_code) ads_data = file_db.reading_db().get('ads') if ads_data: diff --git a/handlers/admins/statistika/staristika.py b/handlers/admins/statistika/staristika.py index 7392815..e21e651 100755 --- a/handlers/admins/statistika/staristika.py +++ b/handlers/admins/statistika/staristika.py @@ -46,7 +46,7 @@ async def statistika(call: types.CallbackQuery, state: FSMContext): f" {soat_minut_sekund}\n" + translator(text="📆 Date:", dest=language) + f' {yil_oy_kun}\n ' + translator(text="Number of bans: ", dest=language) + str( ban_count)) - button = download_statistika(user_id=user_id, lang=language) + button = download_statistika(user_id=user_id, language_code=language) await state.update_data({"message_id": call.message.message_id}) else: text = translator(text="❌ Unfortunately, you do not have this permission!", dest=language) diff --git a/handlers/admins/super_admin.py b/handlers/admins/super_admin.py index c282154..497a515 100755 --- a/handlers/admins/super_admin.py +++ b/handlers/admins/super_admin.py @@ -52,8 +52,8 @@ async def super_admin(msg: types.Message): for x in data: id_list.append(x['id']) user_id_list.append(x['user_id']) - admin_user_id.append(x['admin_user_id']) - date_list.append(x['date']) + admin_user_id.append(x['initiator_user_id']) + date_list.append(x['ban_time']) # Fetching username from chat ID chat = await bot.get_chat(chat_id=x['user_id']) diff --git a/handlers/users/check_usr.py b/handlers/users/check_usr.py deleted file mode 100755 index a938fcd..0000000 --- a/handlers/users/check_usr.py +++ /dev/null @@ -1,121 +0,0 @@ -import logging -from loader import dp, bot, db -from aiogram import types -from cython_code.user_check import User_Check -from function.translator import translator -from aiogram.utils.keyboard import InlineKeyboardBuilder -from keyboards.inline.button import MainCallback - - -@dp.message(User_Check()) -async def start_handler(msg: types.Message): - """ - Handles the text to check if the user has joined the required channels. - If the user has not joined, provides a list of channels and their invitation links. - - Args: - msg (types.Message): The message from the user. - - Returns: - None - """ - try: - user_id = msg.from_user.id - language_code = msg.from_user.language_code - - # Retrieve the list of channels from the database - channels_list = db.select_channels() - - # Initialize the keyboard and message text - keyboard = InlineKeyboardBuilder() - message_text = translator(text="🛑 You have not joined the channel(s)!:\n\n", dest=language_code) - count = 0 - - # Iterate through the channels - for x in channels_list: - channel_id = str(-100) + str(x['channel_id']) - channel = await bot.get_chat(channel_id) - - try: - chat_member_status = await bot.get_chat_member(chat_id=channel_id, user_id=user_id) - except Exception as e: - logging.error(f"Error getting chat member status: {e}") - continue - - # Check if the user is a member of the channel - if chat_member_status.status not in ('member', 'administrator', 'creator'): - count += 1 - message_text += f"\n{count}. ⭕ {channel.full_name} @{channel.username} ❓\n" - keyboard.button(text='➕ ' + channel.title, - url=f"{await channel.export_invite_link()}") - - # Add a button to check again - keyboard.button(text=translator(text='♻ Check!', dest=language_code), - callback_data=MainCallback(action="check_join", q='').pack()) - keyboard.adjust(1) - - # Send the message to the user - await msg.answer(text=f"{message_text}", reply_markup=keyboard.as_markup()) - - # Add user to the database if not already present - if db.check_user(user_id=user_id) is None: - db.insert_user(user_id=user_id, language_code=language_code) - except Exception as err: - logging.error(f"Error in start_handler: {err}") - - -@dp.callback_query(User_Check()) -async def start_callback_query(call: types.CallbackQuery): - """ - Handles callback queries to check if the user has joined the required channels. - Provides a list of channels and their invitation links if the user has not joined. - - Args: - call (types.CallbackQuery): The callback query from the user. - - Returns: - None - """ - try: - user_id = call.from_user.id - language_code = call.from_user.language_code - - # Retrieve the list of channels from the database - channels_list = db.select_channels() - - # Initialize the keyboard and message text - keyboard = InlineKeyboardBuilder() - message_text = translator(text="🛑 You have not joined the channel(s)!:\n\n", dest=language_code) - message_text1 = translator(text="🛑 You have not joined the channel(s)!:\n\n", dest=language_code) - count = 0 - - # Iterate through the channels - for x in channels_list: - channel_id = str(-100) + str(x['channel_id']) - channel = await bot.get_chat(channel_id) - - try: - chat_member_status = await bot.get_chat_member(chat_id=channel_id, user_id=user_id) - except Exception as e: - logging.error(f"Error getting chat member status: {e}") - continue - - # Check if the user is a member of the channel - if chat_member_status.status not in ('member', 'administrator', 'creator'): - count += 1 - message_text += f"\n{count}. ⭕ {channel.full_name} @{channel.username} ❓\n" - keyboard.button(text='➕ ' + channel.title, - url=f"{await channel.export_invite_link()}") - - # Add a button to check again - keyboard.button(text=translator(text='♻ Check!', dest=language_code), - callback_data=MainCallback(action="check_join", q='').pack()) - keyboard.adjust(1) - - # Send the message to the user - await call.answer(text=message_text1, reply_markup=keyboard.as_markup()) - await bot.send_message(chat_id=user_id, text=f"{message_text}", reply_markup=keyboard.as_markup()) - await call.answer('You have not joined the channel(s).') - except Exception as err: - logging.error(f"Error in start_callback_query: {err}") - diff --git a/handlers/users/help.py b/handlers/users/help.py index ac59900..5c7e413 100755 --- a/handlers/users/help.py +++ b/handlers/users/help.py @@ -35,7 +35,7 @@ async def help_handler(msg: types.Message): # Create a URL button for sharing the bot share_button = send_url(url=f'{sharing_message} https://t.me/{bot_info.username}?start', - lang=user_language) + language_code=user_language) # Translate the help text translated_help_text = translator(text=help_text, dest=user_language) diff --git a/keyboards/inline/admin_btn.py b/keyboards/inline/admin_btn.py index 277dc12..5ac23f7 100644 --- a/keyboards/inline/admin_btn.py +++ b/keyboards/inline/admin_btn.py @@ -5,7 +5,7 @@ from function.translator import translator from filters.admin import SelectAdmin from data.config import ADMIN -from loader import db, bot, DB +from loader import db, bot from function.function import x_or_y @@ -30,13 +30,13 @@ def main_btn(): return False -def main_admin_panel_btn(user_id, lang): +def main_admin_panel_btn(user_id, language_code): """ Creates the inline keyboard for the main admin panel. Parameters: user_id (int): The ID of the current user. - lang (str): The language code for translation. + language_code (str): The language code for translation. Returns: InlineKeyboardMarkup: The markup for the main admin panel buttons. @@ -53,23 +53,23 @@ def main_admin_panel_btn(user_id, lang): is_admin = SelectAdmin(user_id=user_id) if is_admin.add_admin(): btn.button(text=translator(text=f"👮‍♂️ Admins settings!", - dest=lang), + dest=language_code), callback_data=AdminCallback(action="admin_settings", data="").pack()) if is_admin.send_message(): btn.button(text=translator(text=f"✈Send advertisement!", - dest=lang), + dest=language_code), callback_data=AdminCallback(action="send_advertisement", data="").pack()) if is_admin.view_statistika(): btn.button(text=translator(text=f"📜Statistika!", - dest=lang), + dest=language_code), callback_data=AdminCallback(action="statistika", data="").pack()) if is_admin.block_user(): btn.button(text=translator(text=f"👁‍🗨Check user!", - dest=lang), + dest=language_code), callback_data=AdminCallback(action="check_user", data="").pack()) if is_admin.channel_settings(): btn.button(text=translator(text=f"🔰Channel setting!", - dest=lang), + dest=language_code), callback_data=AdminCallback(action="channel_setting", data="").pack()) btn.adjust(1, 2) btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) @@ -79,13 +79,13 @@ def main_admin_panel_btn(user_id, lang): return False -async def admin_setting(user_id, lang): +async def admin_setting(user_id, language_code): """ Creates the inline keyboard for admin settings. Parameters: user_id (int): The ID of the current user. - lang (str): The language code for translation. + language_code (str): The language code for translation. Returns: InlineKeyboardMarkup: The markup for admin settings buttons. @@ -107,7 +107,7 @@ async def admin_setting(user_id, lang): btn.button(text=f"👮‍♂️ @{info.username}: {info.full_name}!", callback_data=AdminSetting(action="attach_admin", user_id=x['user_id']).pack()) btn.button(text=translator(text=f"👮‍♂️ ADD Admin!", - dest=lang), + dest=language_code), callback_data=AdminCallback(action="add_admin", data="").pack()) btn.adjust(1) btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) @@ -117,13 +117,13 @@ async def admin_setting(user_id, lang): return False -def attach_admin(user_id, lang): +def attach_admin(user_id, language_code): """ Creates the inline keyboard for managing admin settings. Parameters: user_id (int): The ID of the current user. - lang (str): The language code for translation. + language_code (str): The language code for translation. Returns: InlineKeyboardMarkup: The markup for admin settings management buttons. @@ -144,28 +144,28 @@ def attach_admin(user_id, lang): channel_settings_tx = x_or_y(is_admin.channel_settings()) add_admin_tx = x_or_y(is_admin.add_admin()) btn.button(text=translator(text=f"{send_message_tx} Send a message!", - dest=lang), + dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='send_message').pack()) btn.button(text=translator(text=f"{wiew_statistika_tx} Wiew statistics!", - dest=lang), + dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='statistika').pack()) btn.button(text=translator(text=f"{download_statistika_tx} Download statistics!", - dest=lang), + dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='download_statistika').pack()) btn.button(text=translator(text=f"{block_user_tx} Block user!", - dest=lang), + dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='block_user').pack()) btn.button(text=translator(text=f"{channel_settings_tx} Channel settings!", - dest=lang), + dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='channel_settings').pack()) btn.button(text=translator(text=f"{add_admin_tx} Add a admin!", - dest=lang), + dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='add_admin').pack()) btn.button(text=translator(text=f"🔪Delete admin!", - dest=lang), + dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='delete_admin').pack()) btn.adjust(1) btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) @@ -181,7 +181,7 @@ def attach_admin_btn(user_id, language_code): Parameters: user_id (int): The ID of the current user. - lang (str): The language code for translation. + language_code (str): The language code for translation. Returns: InlineKeyboardMarkup: The markup for admin settings management buttons. @@ -234,12 +234,12 @@ def attach_admin_btn(user_id, language_code): return False -def channel_settings(lang): +def channel_settings(language_code): """ Creates the inline keyboard for channel settings. Parameters: - lang (str): The language code for translation. + language_code (str): The language code for translation. Returns: InlineKeyboardMarkup: The markup for channel settings buttons. @@ -251,21 +251,21 @@ def channel_settings(lang): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - data = DB.reading_db() - if data['join_channel']: + join_channel = db.select_setting('join_channel') + if join_channel: text = translator(text=f'✅ Mandatory membership of', - dest=lang) + dest=language_code) else: text = translator(text=f'☑️ Mandatory membership on', - dest=lang) + dest=language_code) btn.button(text=text, callback_data=AdminCallback(action="mandatory_membership", data="").pack()) btn.button(text=translator(text=f"➕ Add channel!", - dest=lang), + dest=language_code), callback_data=AdminCallback(action="add_channel", data="").pack()) btn.button(text=translator(text=f"➖ Remove Channel", - dest=lang), + dest=language_code), callback_data=AdminCallback(action="remove_channel", data="").pack()) btn.adjust(1) btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) @@ -275,13 +275,13 @@ def channel_settings(lang): return False -def block_user(attention_user_id, lang, user_id): +def block_user(attention_user_id, language_code, user_id): """ Creates the inline keyboard for blocking or unblocking a user. Parameters: user_id (int): The ID of the current user. - lang (str): The language code for translation. + language_code (str): The language code for translation. user_id (int): The ID of the user to be blocked or unblocked. Returns: @@ -301,12 +301,12 @@ def block_user(attention_user_id, lang, user_id): data = db.check_user_ban(user_id=attention_user_id) if data is None: btn.button(text=translator(text=f"🚫Userni bloklash!", - dest=lang), + dest=language_code), callback_data=BlockUser(action="block", user_id=attention_user_id).pack()) else: if (data['initiator_user_id'] == user_id or data['updater_user_id'] == user_id) or user_id == ADMIN: btn.button(text=translator(text=f"✅Unblock user!", - dest=lang), + dest=language_code), callback_data=BlockUser(action="block", user_id=user_id).pack()) btn.adjust(1, 2) btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) @@ -316,13 +316,13 @@ def block_user(attention_user_id, lang, user_id): return False -def download_statistika(user_id, lang): +def download_statistika(user_id, language_code): """ Creates the inline keyboard for downloading statistics. Parameters: user_id (int): The ID of the current user. - lang (str): The language code for translation. + lalanguage_codeng (str): The language code for translation. Returns: InlineKeyboardMarkup: The markup for download statistics button. @@ -337,7 +337,7 @@ def download_statistika(user_id, lang): is_admin = SelectAdmin(user_id=user_id) if is_admin.download_statistika(): btn.button(text=translator(text=f"📜 Dowload statistika!", - dest=lang), + dest=language_code), callback_data=AdminCallback(action="download_statistika", data="").pack()) btn.adjust(1, 2) btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) diff --git a/keyboards/inline/user.py b/keyboards/inline/user.py index 10d3a06..56aef34 100644 --- a/keyboards/inline/user.py +++ b/keyboards/inline/user.py @@ -9,7 +9,7 @@ def send_url(language_code, url): Args: url (str): The URL to be shared. - lang (str): The language code for translation. + language_code (str): The language code for translation. Returns: aiogram.types.InlineKeyboardMarkup: The markup for the inline keyboard with the share button, @@ -28,13 +28,13 @@ def send_url(language_code, url): return False -def share_audio(text: str, lang): +def share_audio(text: str, language_code): """ Creates an inline keyboard with a button to share audio content via an inline query. Args: text (str): The text to be shared in the inline query. - lang (str): The language code for translation. + language_code (str): The language code for translation. Returns: aiogram.types.InlineKeyboardMarkup: The markup for the inline keyboard with the share button, @@ -44,7 +44,7 @@ def share_audio(text: str, lang): btn = InlineKeyboardBuilder() text = text.strip() btn.button( - text=translator(text='➕Share to friend', dest=lang), + text=translator(text='➕Share to friend', dest=language_code), switch_inline_query=text ) btn.adjust(1) diff --git a/loader.py b/loader.py index b4dfdb5..330c961 100755 --- a/loader.py +++ b/loader.py @@ -4,7 +4,6 @@ from aiogram.client.bot import DefaultBotProperties # Yangi versiyadagi default sozlamalar uchun from data.config import * # Konfiguratsiyalarni import qilamiz from db.database import Database -from cython_code.file_db import BotDb, FileDB # Botni token va default parametr orqali yaratamiz bot = Bot(token=BOT_TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML)) @@ -16,8 +15,4 @@ dp = Dispatcher(bot=bot, storage=storage) # MySQL ma'lumotlar bazasi ulanishini yaratamiz -db = Database(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) - -# JSON fayllar bilan ishlash uchun obyektlar -DB = BotDb(file='data/db.json') -file_db = FileDB(file='data/file_db.json') +db = Database(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) \ No newline at end of file diff --git a/main.py b/main.py index 5a971b5..e92d847 100755 --- a/main.py +++ b/main.py @@ -22,10 +22,14 @@ async def main(): try: # Try to create necessary database tables try: - file_db.add_data(False, key='ads') db.create_table_admins() # Create the admins table db.create_table_users() # Create the users table db.create_table_channel() # Create the channel table + db.create_table_settings() # Create the settings table + join_channel = db.select_setting('join_channel') + if join_channel is None: + db.insert_settings(initiator_user_id=1, key='join_channel', value='False') + except Exception as err: logging.error(err) # Log any errors that occur during table creation diff --git a/middlewares/throttling.py b/middlewares/throttling.py index 7b83068..0c897e9 100755 --- a/middlewares/throttling.py +++ b/middlewares/throttling.py @@ -218,7 +218,6 @@ async def check_member(self, user_id, language_code): # If all channels checked and no problems found, return False. return False - except Exception as err: logging.error(err) return False \ No newline at end of file From a91838b8b851ee35ecbcb4965e0a2a046b1d0c02 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Sat, 1 Mar 2025 11:13:56 +0500 Subject: [PATCH 33/71] Refactor date handling: update variable names from 'created_time' to 'created_at' for consistency across various handlers and improve clarity in user management processes. --- db/database.py | 367 +++++------------- handlers/admins/admin_settings/edit_admin.py | 4 +- .../channel_settings/channel_setting.py | 6 +- handlers/admins/channel_settings/get_id.py | 2 +- .../channel_settings/mandatory_membership.py | 10 +- handlers/admins/check_usr/attach_usr.py | 23 +- handlers/admins/check_usr/block_users.py | 2 +- .../admins/statistika/download_statistics.py | 2 +- handlers/admins/super_admin.py | 57 +-- handlers/errors/error_handler.py | 136 +++---- keyboards/inline/admin_btn.py | 8 +- loader.py | 15 +- main.py | 15 +- middlewares/check_user.py | 87 ----- middlewares/throttling.py | 4 +- utils/db_api/bot_db.py | 132 ------- 16 files changed, 241 insertions(+), 629 deletions(-) delete mode 100755 middlewares/check_user.py delete mode 100755 utils/db_api/bot_db.py diff --git a/db/database.py b/db/database.py index 23c97a9..f883a83 100755 --- a/db/database.py +++ b/db/database.py @@ -1,18 +1,11 @@ import logging import mysql.connector - class Database: def __init__(self, host, user, password, database): """ Initialize the Database object with connection parameters. - - Parameters: - host (str): The hostname of the MySQL server. - user (str): The username to connect to the MySQL server. - password (str): The password to connect to the MySQL server. - database (str): The name of the database to connect to. """ self.host = host self.user = user @@ -20,31 +13,9 @@ def __init__(self, host, user, password, database): self.database = database self.reconnect() - def reconnect(self): """ Reconnect to the MySQL database. - - This method initializes or re-initializes the database connection and cursor - objects. It is generally called: - - Right after the object is created (inside __init__). - - After a failed connection or if a connection error occurs. - - If the connection is successful, `self.connection` and `self.cursor` are - reset. If it fails, an error is logged and re-raised. - - Returns: - None - - Raises: - mysql.connector.Error: - If connecting to the database fails due to invalid credentials, - unreachable host, etc. - - Example: - >>> db = Database("root", "secret", "my_database") - >>> # If for some reason the connection is lost, you can manually reconnect: - >>> db.reconnect() """ try: self.connection = mysql.connector.connect( @@ -60,23 +31,20 @@ def reconnect(self): logging.error(f"Database connection error: {err}") raise - def __del__(self): """ Close the database connection when the Database object is deleted. """ try: - self.connection.close() + if hasattr(self, 'connection') and self.connection.is_connected(): + self.connection.close() except mysql.connector.Error as err: - logging.error(f"MySQL Error: {err}") - self.reconnect() + logging.error(f"MySQL Error in __del__: {err}") except Exception as err: - logging.error(f"General Error: {err}") - + logging.error(f"General Error in __del__: {err}") ## --------------------- Create table ------------------## - def create_table_users(self): """ Create the 'users' table if it does not already exist. @@ -91,8 +59,8 @@ def create_table_users(self): `updater_user_id` BIGINT, `comment` TEXT, `ban_time` TIMESTAMP NULL DEFAULT NULL, - `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, `language_code` VARCHAR(5) ) """ @@ -104,7 +72,6 @@ def create_table_users(self): except Exception as err: logging.error(err) - def create_table_channel(self): """ Create the 'channels' table if it does not already exist. @@ -116,9 +83,8 @@ def create_table_channel(self): `channel_id` BIGINT, `initiator_user_id` BIGINT, `updater_user_id` BIGINT, - `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP - + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); """ self.cursor.execute(sql) @@ -129,7 +95,6 @@ def create_table_channel(self): except Exception as err: logging.error(err) - def create_table_admins(self): """ Create the 'admins' table if it does not already exist. @@ -147,8 +112,8 @@ def create_table_admins(self): `block_user` TINYINT(1) DEFAULT 0, `channel_settings` TINYINT(1) DEFAULT 0, `add_admin` TINYINT(1) DEFAULT 0, - `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); """ self.cursor.execute(sql) @@ -159,7 +124,6 @@ def create_table_admins(self): except Exception as err: logging.error(err) - def create_table_settings(self): """ Create the 'settings' table if it does not already exist. @@ -172,8 +136,8 @@ def create_table_settings(self): `initiator_user_id` BIGINT, `key` VARCHAR(255) NOT NULL, `value` VARCHAR(255) NOT NULL, - `updated_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `created_time` TIMESTAMP DEFAULT CURRENT_TIMESTAMP + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ) """ self.cursor.execute(sql) @@ -184,27 +148,31 @@ def create_table_settings(self): except Exception as err: logging.error(err) - ## ---------------- Scheduler --------------------- def ban_user_for_one_hour(self, user_id, comment=None): + """ + Ban a user for one hour and create an event to unban them. + """ try: sql_update = """ UPDATE users - SET status = 'ban', ban_time = NOW(), initiator_user_id = 1, updater_user_id = 1, `comment` = %s + SET status = 'ban', ban_time = NOW(), initiator_user_id = 1, updater_user_id = 1, comment = %s WHERE user_id = %s """ - self.cursor.execute(sql_update, (comment, user_id,)) + self.cursor.execute(sql_update, (comment, user_id)) self.connection.commit() + event_name = f"unban_user_{user_id}" + # Wrap the event name in backticks in case of naming issues sql_event = f""" - CREATE EVENT IF NOT EXISTS {event_name} + CREATE EVENT IF NOT EXISTS `{event_name}` ON SCHEDULE AT DATE_ADD(NOW(), INTERVAL 1 HOUR) DO UPDATE users SET status = 'active', ban_time = NULL, updater_user_id = 1 - WHERE user_id = {user_id}; + WHERE user_id = %s; """ - self.cursor.execute(sql_event) + self.cursor.execute(sql_event, (user_id,)) self.connection.commit() except mysql.connector.Error as err: logging.error(f"MySQL error: {err}") @@ -212,8 +180,6 @@ def ban_user_for_one_hour(self, user_id, comment=None): except Exception as err: logging.error(f"General error: {err}") - - ## ------------------ Insert data ------------------ ## def insert_settings(self, initiator_user_id, key, value): @@ -221,9 +187,7 @@ def insert_settings(self, initiator_user_id, key, value): Add a setting to the 'settings' table. """ try: - sql = """ - INSERT INTO `settings` (`updater_user_id`, `initiator_user_id`, `key`, `value`) VALUES (%s, %s, %s, %s) - """ + sql = "INSERT INTO `settings` (`updater_user_id`, `initiator_user_id`, `key`, `value`) VALUES (%s, %s, %s, %s)" values = (initiator_user_id, initiator_user_id, key, value) self.cursor.execute(sql, values) self.connection.commit() @@ -233,40 +197,30 @@ def insert_settings(self, initiator_user_id, key, value): except Exception as err: logging.error(err) - def insert_user(self, user_id, language_code): + """ + Add a user to the 'users' table. + """ + try: + sql = """ + INSERT INTO users (user_id, language_code) VALUES (%s, %s) """ - Add a user to the 'users' table. - - Parameters: - user_id (int): The user's chat ID. - language_code (str): The user's language_codeuage preference. - """ - try: - sql = """ - INSERT INTO `users` (`user_id`,`language_code`) VALUES (%s,%s) - """ - values = (user_id, language_code) - self.cursor.execute(sql, values) - self.connection.commit() - except mysql.connector.Error as err: - logging.error(err) - self.reconnect() - except Exception as err: - logging.error(err) - + values = (user_id, language_code) + self.cursor.execute(sql, values) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) def insert_channel(self, channel_id, initiator_user_id): """ Add a channel to the 'channels' table. - - Parameters: - channel_id (int): The channel's ID. - initiator_user_id (int): The chat ID of the admin who added the channel. """ try: sql = """ - INSERT INTO `channels` (`channel_id`, `initiator_user_id`) VALUES (%s,%s) + INSERT INTO channels (channel_id, initiator_user_id) VALUES (%s, %s) """ values = (channel_id, initiator_user_id) self.cursor.execute(sql, values) @@ -277,18 +231,13 @@ def insert_channel(self, channel_id, initiator_user_id): except Exception as err: logging.error(err) - def insert_admin(self, user_id, initiator_user_id): """ Add an admin to the 'admins' table. - - Parameters: - user_id (int): The admin's chat ID. - initiator_user_id (int): The chat ID of the admin who added this admin. """ try: sql = """ - INSERT INTO `admins` (`user_id`,`initiator_user_id`) VALUES (%s,%s) + INSERT INTO admins (user_id, initiator_user_id) VALUES (%s, %s) """ values = (user_id, initiator_user_id) self.cursor.execute(sql, values) @@ -299,22 +248,16 @@ def insert_admin(self, user_id, initiator_user_id): except Exception as err: logging.error(err) - - ## ------------------ Update ------------------ ## def update_settings_key(self, updater_user_id, key, value): """ Update a setting in the 'settings' table. - Parameters: - updater_user_id (int): The chat ID of the admin who updated the setting. - initiator_user_id (int): The chat ID of the admin who initiated the update. - key (str): The key of the setting to be updated. - value (str): The new value for the setting. """ try: + # Removed the extra comma before WHERE clause sql = """ - UPDATE `settings` SET `value`=%s, `updater_user_id`=%s, WHERE `key`=%s + UPDATE settings SET `value` = %s, `updater_user_id` = %s WHERE `key` = %s """ values = (value, updater_user_id, key) self.cursor.execute(sql, values) @@ -325,23 +268,18 @@ def update_settings_key(self, updater_user_id, key, value): except Exception as err: logging.error(err) - def update_admin_data(self, user_id, column, value, updater_user_id): """ Update an admin's data in the 'admins' table. - - Parameters: - user_id (int): The admin's chat ID. - column (str): The column to be updated. - value (str): The new value for the specified column. - updater_user_id (int): The chat ID of the admin who updated the data. - Returns: - None - + Only allowed columns may be updated. """ + allowed_columns = {'send_message', 'statistika', 'download_statistika', 'block_user', 'channel_settings', 'add_admin'} + if column not in allowed_columns: + logging.error(f"Invalid column '{column}' specified for update_admin_data") + return try: - sql = f"""UPDATE `admins` SET `{column}` = '{value}', `updater_user_id` = '{updater_user_id}' WHERE `user_id`=%s""" - values = (user_id,) + sql = f"UPDATE admins SET {column} = %s, updater_user_id = %s WHERE user_id = %s" + values = (value, updater_user_id, user_id) self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: @@ -350,19 +288,13 @@ def update_admin_data(self, user_id, column, value, updater_user_id): except Exception as err: logging.error(err) - def update_user_status(self, user_id, status, updater_user_id): """ Update a user's status in the 'users' table. - Parameters: - user_id (int): The user's chat ID. - status (str): The new status for the user. - Returns: - None - """ - try: - sql = f"""UPDATE `users` SET `status` = '{status}', `updater_user_id` = '{updater_user_id}' WHERE `user_id`=%s""" - values = (user_id,) + """ + try: + sql = "UPDATE users SET status = %s, updater_user_id = %s WHERE user_id = %s" + values = (status, updater_user_id, user_id) self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: @@ -371,46 +303,30 @@ def update_user_status(self, user_id, status, updater_user_id): except Exception as err: logging.error(err) - ## ------------------ Select ------------------ ## - # Select a setting from the 'settings' table. def select_setting(self, key: str): """ Select a setting from the 'settings' table. - Parameters: - key (str): The key of the setting to retrieve. - Returns: - str: The value of the setting. """ try: - sql = "SELECT `value` FROM `settings` WHERE `key`=%s" + sql = "SELECT `value` FROM `settings` WHERE `key` = %s" values = (key,) self.cursor.execute(sql, values) result = self.cursor.fetchone() - if result is None: - return None - else: - return result['value'] + return None if result is None else result['value'] except mysql.connector.Error as err: logging.error(err) self.reconnect() except Exception as err: logging.error(err) - - # Select all users from the 'ban' table. def select_all_users_ban(self): """ - Select all users from the 'users' table. - - Returns: - list: A list of tuples containing all banned users. + Select all banned users from the 'users' table. """ try: - sql = """ - SELECT * FROM `users` WHERE `status`='ban' - """ + sql = "SELECT * FROM users WHERE status = 'ban'" self.cursor.execute(sql) result = self.cursor.fetchall() return result @@ -419,17 +335,13 @@ def select_all_users_ban(self): self.reconnect() except Exception as err: logging.error(err) - def stat_ban(self): """ Get the total number of banned users. - - Returns: - int: The total number of banned users. """ try: - sql = "SELECT COUNT(*) AS user_count FROM `users` WHERE `status`='ban';" + sql = "SELECT COUNT(*) AS user_count FROM users WHERE status = 'ban';" self.cursor.execute(sql) result = self.cursor.fetchone() return result['user_count'] @@ -439,19 +351,13 @@ def stat_ban(self): except Exception as err: logging.error(err) - def check_user_ban(self, user_id): """ Check if a user is banned. - - Parameters: - user_id (int): The user's chat ID. - - Returns: - tuple: The user's ban information if they are banned, None otherwise. """ try: - self.cursor.execute("SELECT * FROM `users` WHERE `status`='ban' AND `user_id`=%s", (user_id,)) + sql = "SELECT * FROM users WHERE status = 'ban' AND user_id = %s" + self.cursor.execute(sql, (user_id,)) result = self.cursor.fetchone() return result except mysql.connector.Error as err: @@ -460,35 +366,26 @@ def check_user_ban(self, user_id): except Exception as err: logging.error(err) - def delete_user_ban(self, user_id): """ - Delete a user from the 'ban' table. - - Parameters: - user_id (int): The user's chat ID. + Delete a banned user from the 'users' table. """ try: - self.cursor.execute("DELETE FROM `ban` WHERE `user_id`=%s", (user_id,)) + sql = "DELETE FROM users WHERE user_id = %s AND status = 'ban'" + self.cursor.execute(sql, (user_id,)) + self.connection.commit() except mysql.connector.Error as err: logging.error(err) self.reconnect() except Exception as err: logging.error(err) - - # Select all users from the 'users' table. def select_all_users(self): """ Select all users from the 'users' table. - - Returns: - list: A list of tuples containing all users. """ try: - sql = """ - SELECT * FROM `users` - """ + sql = "SELECT * FROM users" self.cursor.execute(sql) result = self.cursor.fetchall() return result @@ -498,20 +395,14 @@ def select_all_users(self): except Exception as err: logging.error(err) - def select_users_by_id(self, start_id: int, end_id: int) -> list: """ - Select user from the 'users' table on id. - - :param start_id: The start ID (integer). - :param end_id: The end ID (integer). - - :return list: A list of tuples containing all users. + Select users from the 'users' table within a specific ID range. """ try: - sql = "SELECT * FROM `users` WHERE `id` >= %s AND `id` < %s;" - value = (start_id, end_id) - self.cursor.execute(sql, value) + sql = "SELECT * FROM users WHERE id >= %s AND id < %s;" + values = (start_id, end_id) + self.cursor.execute(sql, values) result = self.cursor.fetchall() return result except mysql.connector.Error as err: @@ -520,16 +411,12 @@ def select_users_by_id(self, start_id: int, end_id: int) -> list: except Exception as err: logging.error(err) - def stat(self): """ Get the total number of users. - - Returns: - int: The total number of users. """ try: - sql = "SELECT COUNT(*) AS total_users FROM `users`;" + sql = "SELECT COUNT(*) AS total_users FROM users;" self.cursor.execute(sql) result = self.cursor.fetchone() return result['total_users'] @@ -539,19 +426,13 @@ def stat(self): except Exception as err: logging.error(err) - def check_user(self, user_id): """ Check if a user exists in the 'users' table. - - Parameters: - user_id (int): The user's chat ID. - - Returns: - tuple: The user's information if they exist, None otherwise. """ try: - self.cursor.execute("SELECT * FROM `users` WHERE `user_id`=%s", (user_id,)) + sql = "SELECT * FROM users WHERE user_id = %s" + self.cursor.execute(sql, (user_id,)) result = self.cursor.fetchone() return result except mysql.connector.Error as err: @@ -560,21 +441,13 @@ def check_user(self, user_id): except Exception as err: logging.error(err) - - # Select admin from admins table def select_admin_column(self, user_id, column): """ Select a specific column for an admin from the 'admins' table. - - Parameters: - user_id (int): The admin's chat ID. - column (str): The column to be selected. - - Returns: - any: The value of the specified column for the admin. """ try: - self.cursor.execute(f"SELECT {column} AS result FROM `admins` WHERE `user_id`=%s", (user_id,)) + sql = f"SELECT {column} AS result FROM admins WHERE user_id = %s" + self.cursor.execute(sql, (user_id,)) result = self.cursor.fetchone() return result except mysql.connector.Error as err: @@ -583,19 +456,13 @@ def select_admin_column(self, user_id, column): except Exception as err: logging.error(err) - def select_admin(self, user_id): """ Select an admin from the 'admins' table. - - Parameters: - user_id (int): The admin's chat ID. - - Returns: - tuple: The admin's information if they exist, None otherwise. """ try: - self.cursor.execute("SELECT * FROM `admins` WHERE `user_id`=%s LIMIT 1", (user_id,)) + sql = "SELECT * FROM admins WHERE user_id = %s LIMIT 1" + self.cursor.execute(sql, (user_id,)) result = self.cursor.fetchone() return result except mysql.connector.Error as err: @@ -604,19 +471,13 @@ def select_admin(self, user_id): except Exception as err: logging.error(err) - def select_add_admin(self, user_id): """ - Select all admins added by a specific admin from the 'admins' table. - - Parameters: - user_id (int): The chat ID of the admin who added other admins. - - Returns: - list: A list of tuples containing the added admins' information. + Select all admins added by a specific admin. """ try: - self.cursor.execute("SELECT * FROM `admins` WHERE `initiator_user_id`=%s", (user_id,)) + sql = "SELECT * FROM admins WHERE initiator_user_id = %s" + self.cursor.execute(sql, (user_id,)) result = self.cursor.fetchall() return result except mysql.connector.Error as err: @@ -625,18 +486,12 @@ def select_add_admin(self, user_id): except Exception as err: logging.error(err) - def select_all_admins(self): """ Select all admins from the 'admins' table. - - Returns: - list: A list of tuples containing all admins' information. """ try: - sql = """ - SELECT * FROM `admins` - """ + sql = "SELECT * FROM admins" self.cursor.execute(sql) result = self.cursor.fetchall() return result @@ -646,52 +501,42 @@ def select_all_admins(self): except Exception as err: logging.error(err) - def stat_admins(self): """ Get the total number of admins. - - Returns: - int: The total number of admins. """ try: - sql = "SELECT COUNT(*) FROM `admins`" + sql = "SELECT COUNT(*) FROM admins" self.cursor.execute(sql) result = self.cursor.fetchone() - return result[0] + return result[list(result.keys())[0]] except mysql.connector.Error as err: logging.error(err) self.reconnect() except Exception as err: logging.error(err) - def delete_admin(self, user_id): """ Delete an admin from the 'admins' table. - - Parameters: - user_id (int): The admin's chat ID. """ try: - self.cursor.execute("DELETE FROM `admins` WHERE `user_id`=%s", (user_id,)) + sql = "DELETE FROM admins WHERE user_id = %s" + self.cursor.execute(sql, (user_id,)) + self.connection.commit() except mysql.connector.Error as err: logging.error(err) self.reconnect() except Exception as err: logging.error(err) - - # Select channels from the 'channels' table def select_channels(self): """ Select all channels from the 'channels' table. - - Returns: - list: A list of tuples containing all channels' information. """ try: - self.cursor.execute("SELECT * FROM `channels`") + sql = "SELECT * FROM channels" + self.cursor.execute(sql) results = self.cursor.fetchall() return results except mysql.connector.Error as err: @@ -700,19 +545,13 @@ def select_channels(self): except Exception as err: logging.error(err) - def select_channels_initiator_user_id(self, initiator_user_id): """ - Select all channels added by a specific admin from the 'channels' table. - - Parameters: - initiator_user_id (int): The chat ID of the admin who added the channels. - - Returns: - list: A list of tuples containing the added channels' information. + Select all channels added by a specific admin. """ try: - self.cursor.execute("SELECT * FROM `channels` WHERE `initiator_user_id`=%s", (initiator_user_id,)) + sql = "SELECT * FROM channels WHERE initiator_user_id = %s" + self.cursor.execute(sql, (initiator_user_id,)) result = self.cursor.fetchall() return result except mysql.connector.Error as err: @@ -721,19 +560,13 @@ def select_channels_initiator_user_id(self, initiator_user_id): except Exception as err: logging.error(err) - def check_channel(self, channel_id): """ Check if a channel exists in the 'channels' table. - - Parameters: - user_id (int): The channel's ID. - - Returns: - tuple: The channel's information if it exists, None otherwise. """ try: - self.cursor.execute("SELECT * FROM `channels` WHERE `channel_id`=%s", (channel_id,)) + sql = "SELECT * FROM channels WHERE channel_id = %s" + self.cursor.execute(sql, (channel_id,)) result = self.cursor.fetchone() return result except mysql.connector.Error as err: @@ -742,18 +575,12 @@ def check_channel(self, channel_id): except Exception as err: logging.error(err) - def select_all_channel(self): """ Select all channels from the 'channels' table. - - Returns: - list: A list of tuples containing all channels' information. """ try: - sql = """ - SELECT * FROM `channels` - """ + sql = "SELECT * FROM channels" self.cursor.execute(sql) result = self.cursor.fetchall() return result @@ -763,18 +590,14 @@ def select_all_channel(self): except Exception as err: logging.error(err) - - ## -------------- Delete -------------- ## - def delete_channel(self, channel_id): """ Delete a channel from the 'channels' table. - - Parameters: - user_id (int): The channel's ID. """ try: - self.cursor.execute("DELETE FROM `channels` WHERE `channel_id`=%s", (channel_id,)) + sql = "DELETE FROM channels WHERE channel_id = %s" + self.cursor.execute(sql, (channel_id,)) + self.connection.commit() except mysql.connector.Error as err: logging.error(err) self.reconnect() diff --git a/handlers/admins/admin_settings/edit_admin.py b/handlers/admins/admin_settings/edit_admin.py index 985139a..0e66be4 100755 --- a/handlers/admins/admin_settings/edit_admin.py +++ b/handlers/admins/admin_settings/edit_admin.py @@ -81,9 +81,9 @@ async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, f'Channel settings: {channel_settings_tx}\n' \ f'Add admin: {add_admin_tx}\n' \ f'Date added: ' - text += str(admin_data['created_time']) + text += str(admin_data['created_at']) text += f'\nUpdated added: ' - text += str(admin_data['updated_time']) + text += str(admin_data['updated_at']) else: text = translator(text='🛑 You can only change the admin rights you assigned!', dest=language_code) diff --git a/handlers/admins/channel_settings/channel_setting.py b/handlers/admins/channel_settings/channel_setting.py index 7763846..cc91e49 100755 --- a/handlers/admins/channel_settings/channel_setting.py +++ b/handlers/admins/channel_settings/channel_setting.py @@ -56,12 +56,12 @@ async def channel_setting(call: types.CallbackQuery, state: FSMContext): for x in data: try: count += 1 - chat_id = str(-100) + str(x[1]) # Telegram channel ID + chat_id = str(-100) + str(x['channel_id']) # Telegram channel ID channel = await bot.get_chat(chat_id=chat_id) # Get channel details text += (f"{count}. Name: {channel.full_name}\n" f"Username: @{channel.username}\n" - f"Added date: {x[2]}\n" - f"Added by user_id: {x[3]}\n\n") + f"Added date: {x['created_at']}\n" + f"Added by user_id: {x['initiator_user_id']}\n\n") except Exception as err: logging.error(err) # Log any errors in retrieving channel details btn = channel_settings(language_code=language_code) # Button for channel settings diff --git a/handlers/admins/channel_settings/get_id.py b/handlers/admins/channel_settings/get_id.py index e21017b..c3ab59f 100755 --- a/handlers/admins/channel_settings/get_id.py +++ b/handlers/admins/channel_settings/get_id.py @@ -57,7 +57,7 @@ async def add_channel2(msg: types.Message, state: FSMContext): text = translator(text="✅ The channel was previously added\n", dest=language_code) text += f"Name: {channel.full_name}\n" \ f"Username: @{channel.username}\n" \ - f"Added date: {check[3]}" + f"Added date: {check['created_at']}" btn = channel_settings(language_code=language_code) # Update the button for channel settings except Exception as err: diff --git a/handlers/admins/channel_settings/mandatory_membership.py b/handlers/admins/channel_settings/mandatory_membership.py index ea3a9a8..45e1444 100755 --- a/handlers/admins/channel_settings/mandatory_membership.py +++ b/handlers/admins/channel_settings/mandatory_membership.py @@ -41,18 +41,18 @@ async def mandatory_membership(call: types.CallbackQuery, state: FSMContext): if data.channel_settings(): # Read the current setting for mandatory membership from the database - join_channel = db.select_setting('join_channel') - if join_channel: + mandatory_membership = db.select_setting('mandatory_membership') + if mandatory_membership == 'True': # If mandatory membership is enabled, disable it text = translator(text='☑️ Forced membership disabled!', dest=language_code) - nex_join_channel = False + nex_mandatory_membership = 'False' else: # If mandatory membership is disabled, enable it text = translator(text='✅ Mandatory membership enabled!', dest=language_code) - nex_join_channel = True + nex_mandatory_membership = 'True' # Update the database with the new membership status - db.update_settings_key('join_channel', nex_join_channel) + db.update_settings_key(updater_user_id=user_id, key='mandatory_membership', value=nex_mandatory_membership) btn = channel_settings(language_code=language_code) # Update the button to reflect the new settings else: text = translator(text='❌ Unfortunately, you do not have this right!', dest=language_code) diff --git a/handlers/admins/check_usr/attach_usr.py b/handlers/admins/check_usr/attach_usr.py index 1228915..398c0ef 100755 --- a/handlers/admins/check_usr/attach_usr.py +++ b/handlers/admins/check_usr/attach_usr.py @@ -43,29 +43,28 @@ async def attach_user(msg: types.Message, state: FSMContext): data_state = await state.get_data() # Get the current state data try: user = await bot.get_chat(chat_id=attention_user_id) # Get user information - check = db.check_user_ban(user_id=attention_user_id) # Check if the user is banned - check1 = db.check_user(user_id=attention_user_id) # Check if the user exists in the bot's list + user_data = db.check_user(user_id=attention_user_id) # Check if the user is banned + if user_data: + btn = block_user(attention_user_id=attention_user_id, + user_id=user_id, + language_code=language_code) # Button for blocking/unblocking user + if user_data['status'] != 'ban': + check_admin = db.select_admin(user_id=attention_user_id) # Check if the user is an admin - if check1 is not None: - btn = block_user(attention_user_id=attention_user_id, user_id=user_id, language_code=language_code) # Button for blocking/unblocking user - if check is None: - check2 = db.select_admin(user_id=attention_user_id) # Check if the user is an admin - select_user = db.check_user(user_id) # Get information about the user - - if check2 is None: + if check_admin is None: # User is successfully unblocked text = "✅ User unblocked!" text += translator(text=f'\n\nUsername: @', dest=language_code) + user.username - text += translator(text='\nLanguage code: ', dest=language_code) + f'{select_user[3]}' + text += translator(text='\nLanguage code: ', dest=language_code) + f'{user_data['language_code']}' else: # User is blocked but is an admin tx = "✅ User blocked!\n👮‍♂️ User is in the list of admins!" text = translator(text=f'{tx}\n\nUsername: @', dest=language_code) + user.username - text += translator(text='\nLanguage code: ', dest=language_code) + f'{select_user[3]}' + text += translator(text='\nLanguage code: ', dest=language_code) + f'{user_data['language_code']}' else: # User is already blocked tx = "✅ User blocked!\n Date:" - text = translator(text=f'{tx} {check[3]}\n\nUsername: @', dest=language_code) + user.username + text = translator(text=f'{tx} {user_data['created_at']}\n\nUsername: @', dest=language_code) + user.username else: # User not found in the bot's list text = translator(text="🔴 User not found!\nThe user may not be in the bot's list..", dest=language_code) diff --git a/handlers/admins/check_usr/block_users.py b/handlers/admins/check_usr/block_users.py index aba2c40..3337428 100755 --- a/handlers/admins/check_usr/block_users.py +++ b/handlers/admins/check_usr/block_users.py @@ -50,7 +50,7 @@ async def block_users(call: types.CallbackQuery, callback_data: BlockUser, state user = await bot.get_chat(chat_id=attention_user_id) # Get user details if check is None: db.update_user_status(user_id=attention_user_id, - status='blocked', + status='ban', updater_user_id=user_id) # Update user status to blocked text = translator(text='⛔ User blocked\n\n Username: @', dest=language_code) text += str(user.username) diff --git a/handlers/admins/statistika/download_statistics.py b/handlers/admins/statistika/download_statistics.py index ec279e5..7b98810 100755 --- a/handlers/admins/statistika/download_statistics.py +++ b/handlers/admins/statistika/download_statistics.py @@ -53,7 +53,7 @@ async def download_statistics(call: types.CallbackQuery, state: FSMContext): for user in data: id_list.append(user['id']) user_id_list.append(user['user_id']) - date_list.append(user['created_time']) + date_list.append(user['created_at']) langs.append(user['language_code']) user_info = await bot.get_chat(chat_id=user['user_id']) usernames.append(f'@{user_info.username}') diff --git a/handlers/admins/super_admin.py b/handlers/admins/super_admin.py index 497a515..11ca596 100755 --- a/handlers/admins/super_admin.py +++ b/handlers/admins/super_admin.py @@ -48,37 +48,38 @@ async def super_admin(msg: types.Message): admin_user_id = [] try: - # Collecting data for the DataFrame - for x in data: - id_list.append(x['id']) - user_id_list.append(x['user_id']) - admin_user_id.append(x['initiator_user_id']) - date_list.append(x['ban_time']) + if data: + # Collecting data for the DataFrame + for x in data: + id_list.append(x['id']) + user_id_list.append(x['user_id']) + admin_user_id.append(x['initiator_user_id']) + date_list.append(x['ban_time']) - # Fetching username from chat ID - chat = await bot.get_chat(chat_id=x['user_id']) - username_list.append(f'@{chat.username}') + # Fetching username from chat ID + chat = await bot.get_chat(chat_id=x['user_id']) + username_list.append(f'@{chat.username}') - # Creating and saving DataFrame to Excel - x_data = { - "id": id_list, - "user_id": user_id_list, - "admin_user_id": admin_user_id, - "date_add": date_list, - "username": username_list - } - df = pd.DataFrame(x_data) - excel_path = 'data/ban.xlsx' - df.to_excel(excel_path, index=False) + # Creating and saving DataFrame to Excel + x_data = { + "id": id_list, + "user_id": user_id_list, + "admin_user_id": admin_user_id, + "date_add": date_list, + "username": username_list + } + df = pd.DataFrame(x_data) + excel_path = 'data/ban.xlsx' + df.to_excel(excel_path, index=False) - # Sending the generated Excel file using FSInputFile - document = FSInputFile(excel_path) - await bot.send_document( - chat_id=user_id, - document=document, - caption='Ban list' - ) - os.remove(excel_path) + # Sending the generated Excel file using FSInputFile + document = FSInputFile(excel_path) + await bot.send_document( + chat_id=user_id, + document=document, + caption='Ban list' + ) + os.remove(excel_path) except Exception as err: logging.error(f"Error processing ban data: {err}") diff --git a/handlers/errors/error_handler.py b/handlers/errors/error_handler.py index 576a9a7..4933f82 100644 --- a/handlers/errors/error_handler.py +++ b/handlers/errors/error_handler.py @@ -1,80 +1,84 @@ import logging -from aiogram import types -from loader import dp +import asyncio +from aiohttp import ClientError +from aiogram import Router +from aiogram.types import ErrorEvent, Update +from aiogram import Bot # for optional admin notification from aiogram.exceptions import ( - AiogramError, - DetailedAiogramError, - ClientDecodeError, - SceneException, - UnsupportedKeywordArgument, - TelegramAPIError, - TelegramNetworkError, - TelegramRetryAfter, - TelegramMigrateToChat, - TelegramBadRequest, - TelegramNotFound, - TelegramConflictError, - TelegramUnauthorizedError, - TelegramForbiddenError, - TelegramServerError, - RestartingTelegram, - TelegramEntityTooLarge + TelegramBadRequest, TelegramRetryAfter, TelegramAPIError, + TelegramUnauthorizedError, TelegramForbiddenError + # (In aiogram v3.18, specific errors like "MessageNotModified" are categorized under TelegramBadRequest) ) +from loader import root_logger +# from data.config import ADMINS # your admin IDs -@dp.errors() -async def errors_handler(update: types.Update, exception: Exception): - """ - Handles exceptions raised by Aiogram during task execution. - :param update: The update that caused the exception. - :param exception: The exception that was raised. - :return: True if the exception was handled, otherwise False. - """ - if isinstance(exception, (AiogramError, DetailedAiogramError, TelegramAPIError)): - logging.exception('A Telegram API or Aiogram related error occurred.') - return True - elif isinstance(exception, ClientDecodeError): - logging.exception("A client decode error occurred.") - return True - elif isinstance(exception, SceneException): - logging.exception("An error occurred with scenes.") - return True - elif isinstance(exception, UnsupportedKeywordArgument): - logging.exception("An unsupported keyword argument error occurred.") - return True - elif isinstance(exception, TelegramNetworkError): - logging.exception("A network error occurred.") - return True +router = Router() # your main router + +@router.errors() +async def global_error_handler(error: ErrorEvent) -> bool: + """Global error handler for all exceptions in handlers.""" + update: Update = error.update + exception = error.exception # The actual exception object + + # 1. Message not modified (editing message with no changes) + if isinstance(exception, TelegramBadRequest) and "message is not modified" in str(exception).lower(): + root_logger.info(f"Ignoring MessageNotModified error: {exception}") + # No changes needed, so we simply ignore this error. + return True # Error handled + + # 2. Flood control: too many requests (429 error) elif isinstance(exception, TelegramRetryAfter): - logging.exception("Flood control exceeded. Retry after the specified time.") - return True - elif isinstance(exception, TelegramMigrateToChat): - logging.exception("The chat has been migrated to a supergroup.") - return True - elif isinstance(exception, TelegramBadRequest): - logging.exception("A malformed request error occurred.") - return True - elif isinstance(exception, TelegramNotFound): - logging.exception("The requested resource was not found.") - return True - elif isinstance(exception, TelegramConflictError): - logging.exception("A bot token conflict error occurred.") - return True + retry_after = exception.retry_after # seconds to wait​:contentReference[oaicite:2]{index=2} + root_logger.warning(f"Rate limit hit. Retrying after {retry_after} seconds.") + await asyncio.sleep(retry_after) # Wait required time before continuing + # (Optionally, you might re-run the failed operation here if possible) + return True # Handled by waiting, no further propagation + + # 3. Unauthorized errors (e.g. invalid bot token or bot blocked)​:contentReference[oaicite:3]{index=3}​:contentReference[oaicite:4]{index=4} elif isinstance(exception, TelegramUnauthorizedError): - logging.exception("An unauthorized bot token error occurred.") + root_logger.critical(f"Unauthorized: {exception} – Bot may have an invalid token.") + # This is critical; the bot cannot operate if token is invalid. + # (Optional) Notify admin about the issue if possible: + # try: + # await Bot.get_current().send_message(ADMIN_CHAT_ID, f"CRITICAL: Bot unauthorized!\n{exception}") + # except Exception: + # logger.error("Failed to notify admin about Unauthorized error.") return True elif isinstance(exception, TelegramForbiddenError): - logging.exception("The bot is forbidden from accessing the chat.") + root_logger.error(f"Forbidden: {exception} – Bot lacks permission or was blocked in a chat.") + # The bot was probably removed or blocked in the target chat. + # We log this and proceed (no retry, as the action is not allowed). return True - elif isinstance(exception, TelegramServerError): - logging.exception("A Telegram server error (5xx) occurred.") + + # 4. Bad Request errors (400 errors)​:contentReference[oaicite:5]{index=5} + elif isinstance(exception, TelegramBadRequest): + root_logger.error(f"BadRequest: {exception} – Update: {repr(update)}") + # These indicate invalid requests (e.g. message not found, invalid parameters). + # They are not critical for the bot's operation, so we log and mark as handled. return True - elif isinstance(exception, RestartingTelegram): - logging.exception("The Telegram server is restarting.") + + # 5. General Telegram API errors (other errors from Telegram API)​:contentReference[oaicite:6]{index=6} + elif isinstance(exception, TelegramAPIError): + root_logger.error(f"TelegramAPIError: {exception}", exc_info=True) + # This catches any other API error (e.g. server errors, timeouts wrapped by aiogram). + # We log the full stack trace for debugging. + # (Optional) Send notification to admin for critical API errors: + # try: + # await Bot.get_current().send_message(ADMIN_CHAT_ID, f"⚠️ Telegram API error:\n{exception}") + # except Exception as notify_err: + # logger.error(f"Failed to notify admin: {notify_err}") return True - elif isinstance(exception, TelegramEntityTooLarge): - logging.exception("The file size is too large to send.") + + # 6. Network errors (aiohttp client errors, e.g. connectivity issues) + elif isinstance(exception, ClientError): + root_logger.error(f"NetworkError: {exception} – Possible network connectivity issue.") + # These errors come from the HTTP client (aiohttp). Aiogram may raise them directly if TelegramNetworkError isn't used. + # We log them and potentially attempt reconnection or alert an admin. return True + + # 7. Unhandled exceptions (any other type) else: - logging.exception(f'An unhandled exception occurred: {exception}') - return False + root_logger.exception(f"Unhandled exception: {exception}") # logs stack trace + # You might want to notify an admin here as well, since this is unexpected. + return True # Mark as handled to prevent further propagation diff --git a/keyboards/inline/admin_btn.py b/keyboards/inline/admin_btn.py index 5ac23f7..3eb6623 100644 --- a/keyboards/inline/admin_btn.py +++ b/keyboards/inline/admin_btn.py @@ -251,8 +251,8 @@ def channel_settings(language_code): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - join_channel = db.select_setting('join_channel') - if join_channel: + mandatory_membership = db.select_setting('mandatory_membership') + if mandatory_membership == 'True': text = translator(text=f'✅ Mandatory membership of', dest=language_code) else: @@ -300,14 +300,14 @@ def block_user(attention_user_id, language_code, user_id): if is_admin.block_user(): data = db.check_user_ban(user_id=attention_user_id) if data is None: - btn.button(text=translator(text=f"🚫Userni bloklash!", + btn.button(text=translator(text=f"🚫Block user!", dest=language_code), callback_data=BlockUser(action="block", user_id=attention_user_id).pack()) else: if (data['initiator_user_id'] == user_id or data['updater_user_id'] == user_id) or user_id == ADMIN: btn.button(text=translator(text=f"✅Unblock user!", dest=language_code), - callback_data=BlockUser(action="block", user_id=user_id).pack()) + callback_data=BlockUser(action="block", user_id=attention_user_id).pack()) btn.adjust(1, 2) btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) return btn.as_markup() diff --git a/loader.py b/loader.py index 330c961..ef03b5f 100755 --- a/loader.py +++ b/loader.py @@ -1,4 +1,5 @@ -from aiogram import Bot, Dispatcher +import logging +from aiogram import Bot, Dispatcher, Router from aiogram.enums import ParseMode from aiogram.fsm.storage.memory import MemoryStorage from aiogram.client.bot import DefaultBotProperties # Yangi versiyadagi default sozlamalar uchun @@ -14,5 +15,15 @@ # Dispatcher obyektini yaratishda bot va storage ni uzatamiz dp = Dispatcher(bot=bot, storage=storage) +# Router obyektini yaratamiz +router = Router() + # MySQL ma'lumotlar bazasi ulanishini yaratamiz -db = Database(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) \ No newline at end of file +db = Database(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) + + +root_logger = logging.getLogger() +root_logger.setLevel(logging.INFO) + +log_format = '%(filename)s - %(funcName)s - %(lineno)d - %(name)s - %(levelname)s - %(message)s' +formatter = logging.Formatter(log_format) \ No newline at end of file diff --git a/main.py b/main.py index e92d847..e32996c 100755 --- a/main.py +++ b/main.py @@ -26,9 +26,9 @@ async def main(): db.create_table_users() # Create the users table db.create_table_channel() # Create the channel table db.create_table_settings() # Create the settings table - join_channel = db.select_setting('join_channel') - if join_channel is None: - db.insert_settings(initiator_user_id=1, key='join_channel', value='False') + mandatory_membership = db.select_setting('mandatory_membership') + if mandatory_membership is None: + db.insert_settings(initiator_user_id=1, key='mandatory_membership', value='False') except Exception as err: logging.error(err) # Log any errors that occur during table creation @@ -36,7 +36,6 @@ async def main(): # Delete any existing webhook and start polling await bot.delete_webhook(drop_pending_updates=True) await dp.start_polling(bot) - finally: # Log the database statistics and close the bot session res = db.stat() # Get database statistics @@ -52,13 +51,7 @@ async def main(): if not os.path.exists(log_file_name): with open(log_file_name, 'w') as f: pass - - root_logger = logging.getLogger() - root_logger.setLevel(logging.INFO) - - log_format = '%(filename)s - %(funcName)s - %(lineno)d - %(name)s - %(levelname)s - %(message)s' - formatter = logging.Formatter(log_format) - + file_handler = logging.FileHandler(log_file_name) file_handler.setLevel(logging.INFO) file_handler.setFormatter(formatter) diff --git a/middlewares/check_user.py b/middlewares/check_user.py deleted file mode 100755 index aeb4efd..0000000 --- a/middlewares/check_user.py +++ /dev/null @@ -1,87 +0,0 @@ -# import logging -# from aiogram import BaseMiddleware -# from loader import bot, db, DB -# from data.config import ADMIN -# from aiogram.filters import BaseFilter -# from aiogram.types import Message, CallbackQuery -# -# -# class User_Check(BaseFilter, BaseMiddleware): -# """ -# Middleware and filter class to check if a user is a member of required channels. -# -# This class combines the functionality of a filter and middleware to ensure that users -# are members of specified channels before they can access certain bot features. -# """ -# -# def __init__(self): -# """ -# Initializes the User_Check class. -# -# Parameters: -# - None -# -# This constructor sets up the ADMIN variable from the configuration. -# """ -# self.ADMIN = ADMIN -# -# async def __call__(self, message: Message, call=CallbackQuery) -> bool: -# """ -# Checks if the user is a member of required channels. -# -# Parameters: -# - message (Message): The incoming message object. This is used to obtain user information. -# - call (CallbackQuery): The incoming callback query object. This is used if the message object is not available. -# -# Returns: -# - bool: Returns True if the user is not a member of the required channels and False otherwise. -# -# This method: -# - Reads the database to check if channel membership verification is required. -# - If required, verifies the user's membership status in each specified channel. -# - Logs errors if any exceptions occur during the check. -# """ -# try: -# # Retrieve the channel membership check requirement from the database -# data = DB.reading_db() -# if data['join_channel']: -# try: -# # Try to get the user ID from the message object -# user_id = message.from_user.id -# except Exception as err: -# # If message object is not available, use callback query object -# user_id = call.from_user.id -# logging.error(err) -# -# # If the user is not the admin, perform the channel check -# if user_id != self.ADMIN: -# force = False -# result = db.select_channels() -# for x in result: -# try: -# # Construct the chat ID for the channel -# ids = str(-100) + str(x[1]) -# await bot.get_chat(ids) -# try: -# # Check the user's membership status in the channel -# res = await bot.get_chat_member(chat_id=ids, user_id=user_id) -# except: -# # Continue if unable to retrieve chat member information -# continue -# # If the user is not a member, administrator, or creator, set force to True -# if res.status == 'member' or res.status == 'administrator' or res.status == 'creator': -# pass -# else: -# force = True -# except Exception as err: -# logging.error(err) -# return force -# else: -# return False -# else: -# return False -# except Exception as err: -# logging.error(err) -# -# return False - diff --git a/middlewares/throttling.py b/middlewares/throttling.py index 0c897e9..cea3de6 100755 --- a/middlewares/throttling.py +++ b/middlewares/throttling.py @@ -58,7 +58,7 @@ async def __call__(self, handler, event: types.Message, data): is_ban = await self.check_ban(user_data) if is_ban: return - is_member = await self.check_member(user_data) + is_member = await self.check_member(user_id=user_id, language_code=language_code) if is_member: return @@ -160,7 +160,7 @@ async def check_ban(self, user_data): async def check_member(self, user_id, language_code): try: - is_mandatory = await db.select_setting('mandatory_membership') + is_mandatory = db.select_setting('mandatory_membership') if is_mandatory is None: db.update_settings_key(updater_user_id=1, key='mandatory_membership', value=False) return False diff --git a/utils/db_api/bot_db.py b/utils/db_api/bot_db.py deleted file mode 100755 index b4c9dda..0000000 --- a/utils/db_api/bot_db.py +++ /dev/null @@ -1,132 +0,0 @@ -# import json -# import logging -# import os -# -# -# class BotDb: -# def __init__(self, file): -# """ -# Initializes the BotDb instance and loads data from the specified JSON file. -# -# Parameters: -# - file (str): The path to the JSON file to be used for storing data. -# -# This constructor attempts to load the JSON data from the file. If the file does not exist or -# contains invalid JSON, it creates a new file with default data and sets file permissions to 0777. -# """ -# self.file = file -# try: -# with open(self.file, "r") as json_file: -# self.json_data = json.load(json_file) -# except (FileNotFoundError, json.JSONDecodeError): -# data = {"join_channel": False} -# with open(self.file, "w") as json_file: -# json.dump(data, json_file) -# os.chmod(self.file, 0o777) -# with open(self.file, "r") as json_file: -# self.json_data = json.load(json_file) -# logging.info(f'Created new file: {file} with default data') -# -# def reading_db(self): -# """ -# Reads and returns the JSON data from the file. -# -# Parameters: -# - None -# -# Returns: -# - dict: The JSON data loaded from the file. -# """ -# with open(self.file, "r") as json_file: -# return json.load(json_file) -# -# def change_data(self, join_channel): -# """ -# Updates the 'join_channel' value in the JSON file. -# -# Parameters: -# - join_channel (bool): The new value to set for 'join_channel'. -# -# Returns: -# - None -# """ -# self.json_data['join_channel'] = join_channel -# with open(self.file, "w") as json_file: -# json.dump(self.json_data, json_file) -# -# -# class FileDB: -# def __init__(self, file: str): -# """ -# Initializes the FileDB instance and loads data from the specified JSON file. -# -# Parameters: -# - file (str): The path to the JSON file to be used for storing data. -# -# This constructor attempts to load the JSON data from the file. If the file does not exist or -# contains invalid JSON, it creates a new file with default empty data and sets file permissions to 0777. -# """ -# self.file = file -# try: -# with open(self.file, "r") as json_file: -# self.json_data = json.load(json_file) -# except (FileNotFoundError, json.JSONDecodeError): -# data = {} -# with open(self.file, "w") as json_file: -# json.dump(data, json_file) -# os.chmod(self.file, 0o777) -# with open(self.file, "r") as json_file: -# self.json_data = json.load(json_file) -# logging.info(f'Created new file: {file} with default data') -# -# def reading_db(self): -# """ -# Reads and returns the JSON data from the file. -# -# Parameters: -# - None -# -# Returns: -# - dict: The JSON data loaded from the file. -# """ -# try: -# with open(self.file, "r") as json_file: -# return json.load(json_file) -# except Exception as err: -# logging.info(f'Error reading the file: {err}') -# -# def add_data(self, data, key: str): -# """ -# Adds or updates an entry in the JSON file with the given key and data. -# -# Parameters: -# - data (any): The data to store in the JSON file. -# - key (str): The key under which the data will be stored. -# -# Returns: -# - None -# """ -# try: -# with open(self.file, "r") as json_file: -# self.json_data = json.load(json_file) -# self.json_data[str(key)] = data -# with open(self.file, "w") as json_file: -# json.dump(self.json_data, json_file) -# except Exception as err: -# logging.error(f'Error updating the file: {err}') -# -# def new_data(self, data): -# """ -# Replaces the entire JSON content of the file with new data. -# -# Parameters: -# - data (dict): The new data to write to the file. -# -# Returns: -# - None -# """ -# try: -# with open(self.file, "w") as json_file: -# json.dump(data, json_file) -# except Exception as err: -# logging.error(f'Error writing to the file: {err}') From b7993077c04fefe3755ab0bd5465522f0f76f2b2 Mon Sep 17 00:00:00 2001 From: UznetDev Date: Sat, 1 Mar 2025 11:15:08 +0500 Subject: [PATCH 34/71] Update .gitignore: remove redundant log directory entries for cleaner ignore rules --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9bc3142..d3e3373 100755 --- a/.gitignore +++ b/.gitignore @@ -12,7 +12,5 @@ __pycache__ __pycache__/* *.so *.json -/logs/* -/logs/ *.log *.xls \ No newline at end of file From fd8e201fb8c485655236310354b2448d677a597d Mon Sep 17 00:00:00 2001 From: UznetDev Date: Sat, 1 Mar 2025 14:09:18 +0500 Subject: [PATCH 35/71] Add function to format seconds and update database cursor for buffered results; enhance advertisement status reporting in send_ads handler --- db/database.py | 20 +- function/function.py | 7 + function/send_ads.py | 288 +++++++++++---------------- handlers/admins/send_ads/send_ads.py | 47 +++-- setup.py | 2 - test.py | 164 +++++++++++++++ 6 files changed, 330 insertions(+), 198 deletions(-) create mode 100644 test.py diff --git a/db/database.py b/db/database.py index f883a83..613fde8 100755 --- a/db/database.py +++ b/db/database.py @@ -26,7 +26,7 @@ def reconnect(self): connection_timeout=30, autocommit=True ) - self.cursor = self.connection.cursor(dictionary=True) + self.cursor = self.connection.cursor(dictionary=True, buffered=True) except mysql.connector.Error as err: logging.error(f"Database connection error: {err}") raise @@ -173,6 +173,7 @@ def ban_user_for_one_hour(self, user_id, comment=None): WHERE user_id = %s; """ self.cursor.execute(sql_event, (user_id,)) + _ = self.cursor.fetchall() # Natijani o‘qish orqali tozalaymiz self.connection.commit() except mysql.connector.Error as err: logging.error(f"MySQL error: {err}") @@ -400,7 +401,22 @@ def select_users_by_id(self, start_id: int, end_id: int) -> list: Select users from the 'users' table within a specific ID range. """ try: - sql = "SELECT * FROM users WHERE id >= %s AND id < %s;" + sql = "SELECT * FROM `users` WHERE `id` >= %s AND `id` < %s;" + values = (start_id, end_id) + self.cursor.execute(sql, values) + result = self.cursor.fetchall() + return result + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + def select_admins_by_id(self, start_id: int, end_id: int) -> list: + """ + Select admins from the 'admins' table within a specific ID range. + """ + try: + sql = "SELECT * FROM `admins` WHERE `id` >= %s AND `id` < %s;" values = (start_id, end_id) self.cursor.execute(sql, values) result = self.cursor.fetchall() diff --git a/function/function.py b/function/function.py index c3cf45c..9a8558e 100644 --- a/function/function.py +++ b/function/function.py @@ -29,3 +29,10 @@ def x_or_y(data): except Exception as err: logging.error(err) # Log the error return '' # Return an empty string if an error occurs + + +def format_seconds(seconds): + hours = int(seconds // 3600) + minutes = int((seconds % 3600) // 60) + seconds = int(seconds % 60) + return f"{hours} soat {minutes} daqiqa {seconds} soniya" \ No newline at end of file diff --git a/function/send_ads.py b/function/send_ads.py index 6c2fe5d..277a37f 100644 --- a/function/send_ads.py +++ b/function/send_ads.py @@ -1,177 +1,111 @@ -# import requests -# import logging -# import time -# import mysql.connector -# from data.config import * -# from loader import db, file_db -# -# -# class MyDatabase: -# def __init__(self, host, user, password, database): -# """ -# Initialize the MyDatabase object with connection parameters. -# -# Parameters: -# host (str): The hostname of the MySQL server. -# user (str): The username to connect to the MySQL server. -# password (str): The password to connect to the MySQL server. -# database (str): The name of the database to connect to. -# """ -# self.host = host -# self.user = user -# self.password = password -# self.database = database -# self.reconnect() -# -# def reconnect(self): -# """ -# Reconnect to the MySQL database. If the connection fails, log the error and attempt to reconnect. -# """ -# try: -# self.connection = mysql.connector.connect( -# host=self.host, -# user=self.user, -# password=self.password, -# database=self.database, -# autocommit=True -# ) -# self.cursor = self.connection.cursor() -# except mysql.connector.Error as err: -# logging.error(err) -# self.reconnect() -# except Exception as err: -# logging.error(err) -# -# def select_users_by_id(self, start_id: int, end_id: int) -> list: -# """ -# Select users from the 'users' table by their ID. -# -# :param start_id: The starting ID (inclusive). -# :param end_id: The ending ID (exclusive). -# -# :return list: A list of tuples containing user data. -# """ -# try: -# sql_query = "SELECT * FROM `users` WHERE `id` >= %s AND `id` < %s;" -# query_values = (start_id, end_id) -# self.cursor.execute(sql_query, query_values) -# result = self.cursor.fetchall() -# return result -# except mysql.connector.Error as err: -# logging.error(err) -# self.reconnect() -# except Exception as err: -# logging.error(err) -# -# -# my_db = MyDatabase(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) -# -# -# def copy_message_sync(chat_id, from_chat_id, message_id, **kwargs): -# """ -# Synchronously copy a message from one chat to another using the Telegram API. -# -# :param chat_id: The target chat ID where the message will be copied. -# :param from_chat_id: The chat ID where the message originates. -# :param message_id: The ID of the message to copy. -# :param kwargs: Additional optional parameters for the API request. -# -# :return dict: The JSON response from the Telegram API. -# """ -# url = f"https://api.telegram.org/bot{BOT_TOKEN}/copyMessage" -# data = { -# "chat_id": chat_id, -# "from_chat_id": from_chat_id, -# "message_id": message_id -# } -# data.update(kwargs) -# response = requests.post(url, data=data) -# return response.json() -# -# def send_message_sync(chat_id, text, **kwargs): -# """ -# Synchronously send a message to a specific chat using the Telegram API. -# -# :param chat_id: The target chat ID where the message will be sent. -# :param text: The text of the message to send. -# :param kwargs: Additional optional parameters for the API request. -# -# :return dict: The JSON response from the Telegram API. -# """ -# url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage" -# data = { -# "chat_id": chat_id, -# "text": text -# } -# data.update(kwargs) -# response = requests.post(url, data=data) -# return response.json() -# -# -# def send_ads(): -# """ -# Function to handle the advertisement sending process. -# -# This function reads the advertisement data from the database, selects a batch of users, -# and sends the advertisement message to each user. It updates the advertisement progress -# and logs any errors that occur. If the entire batch of users is processed, it terminates -# the sending process and updates the status in the database. -# """ -# try: -# start_time = time.time() -# ads_data = file_db.reading_db()['ads'] -# if ads_data: -# start_index = ads_data['start'] -# from_chat_id = ads_data['from_chat_id'] -# message_id = ads_data['message_id'] -# caption = ads_data['caption'] -# reply_markup = ads_data['reply_markup'] -# total_users = ads_data['total_users'] -# end_index = min(start_index + 100, total_users) -# -# users_batch = my_db.select_users_by_id(start_index, end_index) -# if users_batch: -# logging.info(f'Sending ads to users {start_index} - {end_index} (Total: {len(users_batch)})') -# for user in users_batch: -# try: -# chat_id = user[1] -# copy_message_sync(chat_id, -# from_chat_id, -# message_id, -# caption=caption, -# reply_markup=reply_markup) -# ads_data["done_count"] += 1 -# except Exception as err: -# logging.error(err) -# ads_data["fail_count"] += 1 -# -# if end_index < total_users: -# time.sleep(1) -# end_time = time.time() -# total_time = end_time - start_time -# per_time = ads_data["per_time"] -# if per_time< total_time: -# ads_data["per_time"] = per_time -# ads_data['start'] = end_index -# file_db.add_data(ads_data, key='ads') -# return send_ads() # Recursive call to continue sending to the next batch -# else: -# file_db.add_data(False, key='ads') -# summary_message = ( -# f"📬 Advertisement Sending Completed\n\n" -# f"👥 Total Users: {total_users}\n" -# f"✅ Sent: {ads_data['done_count']}\n" -# f"❌ Failed: {ads_data['fail_count']}\n" -# f"⏰ Start Time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(ads_data['start-time']))}\n" -# f"🕒 End Time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))}" -# ) -# send_message_sync(from_chat_id, summary_message) -# elif users_batch is None: -# db.reconnect() -# time.sleep(2) -# else: -# return -# else: -# return -# except Exception as err: -# logging.error(err) \ No newline at end of file +import asyncio +import logging +import time +from aiogram.types import Message +from loader import db, bot + +def init_broadcast_settings(total, admin_id, broadcast_type): + try: + db.insert_settings(admin_id, "broadcast_total", str(total)) + except Exception: + db.update_settings_key(admin_id, "broadcast_total", str(total)) + try: + db.insert_settings(admin_id, "broadcast_sent", "0") + except Exception: + db.update_settings_key(admin_id, "broadcast_sent", "0") + try: + db.insert_settings(admin_id, "broadcast_fail", "0") + except Exception: + db.update_settings_key(admin_id, "broadcast_fail", "0") + try: + db.insert_settings(admin_id, "broadcast_start_time", str(time.time())) + except Exception: + db.update_settings_key(admin_id, "broadcast_start_time", str(time.time())) + try: + db.insert_settings(admin_id, "broadcast_status", "active") + except Exception: + db.update_settings_key(admin_id, "broadcast_status", "active") + try: + db.insert_settings(admin_id, "broadcast_start_id", "0") + except Exception: + db.update_settings_key(admin_id, "broadcast_start_id", "0") + try: + db.insert_settings(admin_id, "broadcast_admin_id", str(admin_id)) + except Exception: + db.update_settings_key(admin_id, "broadcast_admin_id", str(admin_id)) + try: + db.insert_settings(admin_id, "broadcast_type", str(broadcast_type)) + except Exception: + db.update_settings_key(admin_id, "broadcast_type", str(broadcast_type)) + + +async def send_ads_to_all(message: Message): + try: + broadcast_start_id = int(db.select_setting("broadcast_start_id")) + broadcast_total = int(db.select_setting("broadcast_total")) + broadcast_sent = int(db.select_setting("broadcast_sent")) + broadcast_fail = int(db.select_setting("broadcast_fail")) + broadcast_start_time = float(db.select_setting("broadcast_start_time")) + broadcast_status = db.select_setting("broadcast_status") + broadcast_admin_id = int(db.select_setting("broadcast_admin_id")) + broadcast_type = db.select_setting("broadcast_type") + + while broadcast_status == "active": + broadcast_status = db.select_setting("broadcast_status") + if broadcast_status == "inactive": + break + + if broadcast_sent + broadcast_fail >= broadcast_total: + db.update_settings_key(broadcast_admin_id, "broadcast_status", "stop") + break + + broadcast_end_id = broadcast_start_id + 100 + + if broadcast_type == 'users': + users_data = db.select_users_by_id(start_id=broadcast_start_id, end_id=broadcast_end_id) + elif broadcast_type == 'admin': + users_data = db.select_admins_by_id(start_id=broadcast_start_id, end_id=broadcast_end_id) + else: + logging.error("Noma'lum broadcast_type: %s", broadcast_type) + break + + batch_start_time = time.time() + + for user in users_data: + try: + await bot.copy_message( + chat_id=user['user_id'], + from_chat_id=message.chat.id, + message_id=message.message_id + ) + broadcast_sent += 1 + except Exception as e: + logging.error("Xabar yuborishda xato, user %s: %s", user['user_id'], e) + broadcast_fail += 1 + + db.update_settings_key(broadcast_admin_id, "broadcast_sent", str(broadcast_sent)) + db.update_settings_key(broadcast_admin_id, "broadcast_fail", str(broadcast_fail)) + db.update_settings_key(broadcast_admin_id, "broadcast_start_id", str(broadcast_end_id)) + + batch_duration = time.time() - batch_start_time + logging.info("Batch davomiyligi: %.2f soniya", batch_duration) + + await asyncio.sleep(max(5, 60 - batch_duration)) + + broadcast_status = db.select_setting("broadcast_status") + + total_time = time.time() - broadcast_start_time + report_text = ( + f"📊 Broadcast yakunlandi.\n" + f"Send: {broadcast_sent} ({broadcast_sent / broadcast_total * 100:.2f}%)\n" + f"Fail: {broadcast_fail} ({broadcast_fail / broadcast_total * 100:.2f}%)\n" + f"Jami foydalanuvchilar: {broadcast_total}\n" + f"Umumiy vaqt: {total_time:.2f} soniya\n" + ) + try: + await bot.send_message(chat_id=broadcast_admin_id, text=report_text) + except Exception as e: + logging.error("Hisobot yuborishda xato: %s", e) + + except Exception as e: + logging.error("send_ads_to_all funksiyasida xato: %s", e) diff --git a/handlers/admins/send_ads/send_ads.py b/handlers/admins/send_ads/send_ads.py index 6a0a0e7..e92b5f0 100755 --- a/handlers/admins/send_ads/send_ads.py +++ b/handlers/admins/send_ads/send_ads.py @@ -1,11 +1,13 @@ import logging import time -from loader import dp, file_db +from loader import dp, db from aiogram import types from keyboards.inline.button import AdminCallback from keyboards.inline.close_btn import close_btn from keyboards.inline.admin_btn import stop_advertisement, main_admin_panel_btn from aiogram import F +from function.function import format_seconds +from function.send_ads import init_broadcast_settings, send_ads_to_all from aiogram.fsm.context import FSMContext from states.admin_state import AdminState from filters.admin import SelectAdmin, IsAdmin @@ -13,6 +15,7 @@ from data.config import ADMIN + @dp.callback_query(AdminCallback.filter(F.action == "send_advertisement"), IsAdmin()) async def send_ads(call: types.CallbackQuery, state: FSMContext): """ @@ -47,27 +50,37 @@ async def send_ads(call: types.CallbackQuery, state: FSMContext): button_markup = close_btn() if is_admin.send_message(): - ads_data = file_db.reading_db().get('ads') - - if ads_data: - - # Calculate remaining users - remaining_users = ads_data['total_users'] - ads_data['done_count'] - ads_data['fail_count'] - estimated_minutes = (remaining_users / 100) # 1 minute per 100 users + # users_data = db.select_all_users() + # users_count = len(users_data) + # init_broadcast_settings(total=users_count, admin_id=user_id, broadcast_type="users") + broadcast_status = db.select_setting("broadcast_status") + if broadcast_status == 'active': + broadcast_total = int(db.select_setting("broadcast_total")) + broadcast_sent = int(db.select_setting("broadcast_sent")) + broadcast_fail = int(db.select_setting("broadcast_fail")) + broadcast_start_time = float(db.select_setting("broadcast_start_time")) + broadcast_status = db.select_setting("broadcast_status") + broadcast_admin_id = int(db.select_setting("broadcast_admin_id")) + broadcast_start_time = float(db.select_setting("broadcast_start_time")) + + current_time = time.time() + elapsed = current_time - broadcast_start_time + processed = broadcast_sent + broadcast_fail + remaining = broadcast_total - processed + avg_time = elapsed / processed if processed > 0 else 0 + estimated_remaining = avg_time * remaining - # Calculate the estimated end time - estimated_end_time = time.localtime(time.time() + estimated_minutes * 60) message_text = ( - f"📢 Advertisement Status:\n\n" - f"👥 Total users: {ads_data['total_users']}\n" - f"✅ Messages sent: {ads_data['done_count']}\n" - f"❌ Failed messages: {ads_data['fail_count']}\n" - f"⏰ Start Time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(ads_data['start-time']))}\n" - f"🕒 Estimated End Time: {time.strftime('%Y-%m-%d %H:%M:%S', estimated_end_time)}" + f"📢 Advertisement Status: {broadcast_status}\n\n" + f"👥 Total users: {broadcast_total}\n" + f"✅ Messages sent: {broadcast_sent}\n" + f"❌ Failed messages: {broadcast_fail}\n" + f"⏰ Start Time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(broadcast_start_time))} \n" + f"🕒 Estimated End Time: {time.strftime('%Y-%m-%d %H:%M:%S', format_seconds(estimated_remaining))}\n" ) - if ads_data['from_chat_id'] == user_id or user_id == ADMIN: + if broadcast_admin_id == user_id or user_id == ADMIN: button_markup = stop_advertisement() else: button_markup = main_admin_panel_btn(user_id, language_code) diff --git a/setup.py b/setup.py index 4db29ab..b8b179e 100644 --- a/setup.py +++ b/setup.py @@ -3,9 +3,7 @@ extensions = [ Extension(name="cython_code.my_translator", sources=["cython_code/my_translator.pyx"]), - Extension(name="cython_code.user_check", sources=["cython_code/user_check.pyx"]), Extension(name="cython_code.throttling_middleware", sources=["cython_code/throttling_middleware.pyx"]), - Extension(name="cython_code.file_db", sources=["cython_code/file_db.pyx"]), Extension(name="cython_code.send_ads", sources=["cython_code/send_ads.pyx"]), # Corrected ] diff --git a/test.py b/test.py new file mode 100644 index 0000000..67e94f2 --- /dev/null +++ b/test.py @@ -0,0 +1,164 @@ +import asyncio +import time +from aiogram import Bot, Dispatcher, types, F +from aiogram.filters import Command +from aiogram.exceptions import TelegramAPIError +from db.database import Database +from data.config import * + + +db = Database(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) + +# Token va admin identifikatori +API_TOKEN = "1430978281:AAFbdRkUFtw3fVLqbU8_L9KJ-wy_9mwwNS4" +ADMIN_ID = 835558445 # O'zingizning admin ID raqamingiz + +bot = Bot(token=API_TOKEN) +dp = Dispatcher() + +# Foydalanuvchilar ro'yxatini oddiy to'plamda saqlaymiz (amaldagi loyihada ma'lumotlar bazasi orqali olib borish tavsiya etiladi) +registered_users = set() + +# Avvalgi keltirilgan Database modulidan db obyektini import qiling +# from your_database_module import db +# Misolda biz oldindan yaratilgan `db` obyektidan foydalanamiz + +# Broadcast jarayoni uchun 'settings' jadvalidagi kalitlar: +# "broadcast_total", "broadcast_sent", "broadcast_fail", "broadcast_start_time", "broadcast_stop" +# Ushbu funksiyalar orqali settings jadvaliga yozamiz: +def init_broadcast_settings(total, admin_id): + try: + db.insert_settings(admin_id, "broadcast_total", str(total)) + except Exception: + db.update_settings_key(admin_id, "broadcast_total", str(total)) + try: + db.insert_settings(admin_id, "broadcast_sent", "0") + except Exception: + db.update_settings_key(admin_id, "broadcast_sent", "0") + try: + db.insert_settings(admin_id, "broadcast_fail", "0") + except Exception: + db.update_settings_key(admin_id, "broadcast_fail", "0") + try: + db.insert_settings(admin_id, "broadcast_start_time", str(time.time())) + except Exception: + db.update_settings_key(admin_id, "broadcast_start_time", str(time.time())) + try: + db.insert_settings(admin_id, "broadcast_stop", "0") + except Exception: + db.update_settings_key(admin_id, "broadcast_stop", "0") + +def update_broadcast_setting(key, value, admin_id=ADMIN_ID): + try: + db.update_settings_key(admin_id, key, str(value)) + except Exception as e: + print("DB update error:", e) + +def get_broadcast_setting(key): + value = db.select_setting(key) + return value + +# /start handler – foydalanuvchini ro'yxatga qo'shish +@dp.message(Command("start")) +async def on_start(message: types.Message): + registered_users.add(message.from_user.id) + await message.answer("Botga xush kelibsiz! Siz ro'yxatga olindingiz.") + +# Global o'zgaruvchi: broadcasting jarayonining task obyektini saqlash +broadcast_task = None + +# /send komandasi – adminning broadcasting jarayonini ishga tushiradi +@dp.message(Command("send")) +async def broadcast_handler(message: types.Message): + global broadcast_task + if message.from_user.id != ADMIN_ID: + return # Faqat admin uchun + if not registered_users: + await message.answer("Hozircha foydalanuvchilar ro'yxati bo'sh.") + return + total_users = len(registered_users) + init_broadcast_settings(total_users, ADMIN_ID) + await message.answer("✅ Reklama jo'natish boshlandi.") + broadcast_task = asyncio.create_task(send_ads_to_all(message)) + +# /status komandasi – adminga real vaqt progressini ko'rsatadi +@dp.message(Command("status")) +async def status_handler(message: types.Message): + if message.from_user.id != ADMIN_ID: + return + try: + total = int(get_broadcast_setting("broadcast_total") or "0") + sent = int(get_broadcast_setting("broadcast_sent") or "0") + fail = int(get_broadcast_setting("broadcast_fail") or "0") + start_time = float(get_broadcast_setting("broadcast_start_time") or time.time()) + current_time = time.time() + elapsed = current_time - start_time + processed = sent + fail + remaining = total - processed + avg_time = elapsed / processed if processed > 0 else 0 + estimated_remaining = avg_time * remaining + status_text = ( + f"📊 Broadcast Status:\n" + f"Jami foydalanuvchilar: {total}\n" + f"Jo'natilgan: {sent}\n" + f"Xatoliklar: {fail}\n" + f"Qayta ishlangan: {processed}\n" + f"O'tgan vaqt: {int(elapsed)} soniya\n" + f"Taxminiy qolgan vaqt: {int(estimated_remaining)} soniya" + ) + await message.answer(status_text) + except Exception as err: + await message.answer(err) + +# /stop komandasi – admin broadcasting jarayonini to'xtatadi +@dp.message(Command("stop")) +async def stop_handler(message: types.Message): + if message.from_user.id != ADMIN_ID: + return + update_broadcast_setting("broadcast_stop", "1") + await message.answer("🚫 Broadcast to'xtatildi. Jarayon keyingi iteratsiyada to'xtaydi.") + +# Fon vazifasi: barcha foydalanuvchilarga xabar (adminning xabari)ni yuborish +async def send_ads_to_all(admin_message: types.Message): + total_users = len(registered_users) + sent_count = 0 + fail_count = 0 + start_time = time.time() + update_broadcast_setting("broadcast_start_time", start_time) + # Ro'yxat bo'ylab aylanamiz + for idx, user_id in enumerate(registered_users, start=1): + # Agar /stop komandasi orqali broadcast_stop 1 ga o'zgarsa, to'xtatamiz + if get_broadcast_setting("broadcast_stop") == "1": + break + try: + await bot.copy_message( + chat_id=user_id, + from_chat_id=admin_message.chat.id, + message_id=admin_message.message_id + ) + sent_count += 1 + except Exception as err: + fail_count += 1 + time.sleep(1000000000) + # Har bir xabar yuborilgandan so'ng progressni yangilaymiz + update_broadcast_setting("broadcast_sent", sent_count) + update_broadcast_setting("broadcast_fail", fail_count) + # Har 100 ta xabardan keyin 60 soniya kutish (daqiqasiga 100 ta tezlik) + if idx % 100 == 0: + await asyncio.sleep(60) + # Yakuniy hisobotni yangilaymiz va adminga jo'natamiz + update_broadcast_setting("broadcast_sent", sent_count) + update_broadcast_setting("broadcast_fail", fail_count) + report_text = ( + f"📊 Broadcast yakunlandi.\n" + f"Jo'natilgan: {sent_count}\n" + f"Xatoliklar: {fail_count}\n" + f"Jami foydalanuvchilar: {total_users}" + ) + try: + await bot.send_message(chat_id=ADMIN_ID, text=report_text) + except Exception: + pass + +if __name__ == "__main__": + asyncio.run(dp.start_polling(bot)) From f8d99f06320e200a03802c1824c7e8f2041bff1b Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Sun, 11 May 2025 16:52:13 +0500 Subject: [PATCH 36/71] Refactor database handling: add features for managing texts, translations, and feature toggles; enhance logging and middleware integration --- .gitignore | 3 +- core/feature_manager.py | 26 +++ data/config.py | 4 +- db/database.py | 221 ++++++++++++++++++++++++ function/function.py | 10 +- function/translator.py | 62 +++++-- handlers/admins/check_usr/attach_usr.py | 6 +- loader.py | 52 +++++- logs/logging.log | 4 - main.py | 15 +- middlewares/__init__.py | 2 +- middlewares/throttling.py | 43 +++-- 12 files changed, 379 insertions(+), 69 deletions(-) create mode 100644 core/feature_manager.py diff --git a/.gitignore b/.gitignore index d3e3373..ae71363 100755 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,5 @@ __pycache__/* *.so *.json *.log -*.xls \ No newline at end of file +*.xls +.bins \ No newline at end of file diff --git a/core/feature_manager.py b/core/feature_manager.py new file mode 100644 index 0000000..7776667 --- /dev/null +++ b/core/feature_manager.py @@ -0,0 +1,26 @@ +import logging +from db.database import Database + + +class FeatureManager: + + def __init__(self, db: Database, root_logger: logging.Logger): + self.db = db + self.root_logger = root_logger + + def feature(self, name: str) -> bool: + try: + feature = self.db.select_feature(name) + if feature is None: + access = input(f"Feature '{name}' not found in the database. Do you want to enable it? (y/n): ") + if access.lower() == 'y': + self.db.insert_feature(name=name, enabled=True) + return True + else: + self.db.insert_feature(name=name, enabled=False) + return False + else: + return feature + except Exception as e: + self.root_logger.error(f"Error in is_enabled: {e}") + return False \ No newline at end of file diff --git a/data/config.py b/data/config.py index 2b048d0..80fd7ce 100644 --- a/data/config.py +++ b/data/config.py @@ -26,4 +26,6 @@ # Date and time datas = datetime.datetime.now() date_day_month = (datetime.datetime.date(datetime.datetime.now())) -time_hour_minute_second = f"{datas.hour}:{datas.minute}:{datas.second}" \ No newline at end of file +time_hour_minute_second = f"{datas.hour}:{datas.minute}:{datas.second}" + +FEATURES = ['translator', 'middlewares', 'save_log'] \ No newline at end of file diff --git a/db/database.py b/db/database.py index 613fde8..69c9728 100755 --- a/db/database.py +++ b/db/database.py @@ -1,5 +1,8 @@ import logging import mysql.connector +from aiogram import Bot +from function.function import to_hash + class Database: @@ -12,6 +15,13 @@ def __init__(self, host, user, password, database): self.password = password self.database = database self.reconnect() + self.create_table_admins() # Create the admins table + self.create_table_users() # Create the users table + self.create_table_channel() # Create the channel table + self.create_table_settings() # Create the settings table + self.create_table_texts() # Create the texts table + self.create_table_translations() # Create the translations table + self.create_table_features() # Create the features table def reconnect(self): """ @@ -147,6 +157,69 @@ def create_table_settings(self): self.reconnect() except Exception as err: logging.error(err) + + def create_table_texts(self): + try: + sql = """ + CREATE TABLE IF NOT EXISTS texts ( + id INT AUTO_INCREMENT PRIMARY KEY, + hash_value BIGINT UNSIGNED, + raw_text TEXT NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + deleted_at TIMESTAMP NULL DEFAULT NULL, + INDEX(hash_value) + ) + """ + self.cursor.execute(sql) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + def create_table_translations(self): + try: + sql = """ + CREATE TABLE IF NOT EXISTS `translations` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `text_id` INT NOT NULL, + `dest_lang` CHAR(5) NOT NULL, + `translated_content` TEXT NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + deleted_at TIMESTAMP NULL DEFAULT NULL, + FOREIGN KEY (text_id) REFERENCES texts(id) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """ + self.cursor.execute(sql) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + def create_table_features(self): + try: + sql = """ + CREATE TABLE IF NOT EXISTS `features` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(255) NOT NULL UNIQUE, + `enabled` TINYINT(1) DEFAULT 0, + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP NULL DEFAULT NULL, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ) + """ + self.cursor.execute(sql) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) ## ---------------- Scheduler --------------------- def ban_user_for_one_hour(self, user_id, comment=None): @@ -183,6 +256,46 @@ def ban_user_for_one_hour(self, user_id, comment=None): ## ------------------ Insert data ------------------ ## + def insert_feature(self, name: str, enabled: bool): + try: + sql = "INSERT INTO `features` (`name`, `enabled`) VALUES (%s, %s)" + values = (name, int(enabled)) + self.cursor.execute(sql, values) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + def insert_texts(self, hash_value: str, raw_text: str): + """ + Insert a new text into the 'texts' table. + """ + try: + sql = "INSERT INTO `texts` (`hash_value`, `raw_text`) VALUES (%s, %s)" + values = (to_hash(hash_value), raw_text) + self.cursor.execute(sql, values) + self.connection.commit() + return self.cursor.lastrowid + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + def insert_translations(self, text_id: int, dest_lang: str, translated_content: str): + try: + sql = "INSERT INTO `translations` (`text_id`, `dest_lang`, `translated_content`) VALUES (%s, %s, %s)" + values = (text_id, dest_lang, translated_content) + self.cursor.execute(sql, values) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + def insert_settings(self, initiator_user_id, key, value): """ Add a setting to the 'settings' table. @@ -305,6 +418,47 @@ def update_user_status(self, user_id, status, updater_user_id): logging.error(err) ## ------------------ Select ------------------ ## + def select_feature(self, name: str): + """ + Select a feature from the 'features' table. + """ + try: + sql = "SELECT * FROM `features` WHERE `name` = %s" + values = (name,) + self.cursor.execute(sql, values) + result = self.cursor.fetchone() + return None if result is None else result['enabled'] + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + def select_texts(self, hash_value: str): + try: + sql = "SELECT * FROM `texts` WHERE `hash_value` = %s LIMIT 1" + values = (hash_value,) + self.cursor.execute(sql, values) + result = self.cursor.fetchone() + return None if result is None else result['id'] + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + def select_translations(self, text_id: int, dest_lang: str): + try: + sql = "SELECT * FROM `translations` WHERE `text_id` = %s AND `dest_lang` = %s LIMIT 1" + values = (text_id, dest_lang) + self.cursor.execute(sql, values) + result = self.cursor.fetchone() + return None if result is None else result['translated_content'] + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) def select_setting(self, key: str): """ @@ -411,6 +565,7 @@ def select_users_by_id(self, start_id: int, end_id: int) -> list: self.reconnect() except Exception as err: logging.error(err) + def select_admins_by_id(self, start_id: int, end_id: int) -> list: """ Select admins from the 'admins' table within a specific ID range. @@ -619,3 +774,69 @@ def delete_channel(self, channel_id): self.reconnect() except Exception as err: logging.error(err) + + + + + + +class MySQLHandler(logging.Handler): + def __init__(self, bot: Bot, connection: mysql.connector.MySQLConnection): + super().__init__() + try: + self.bot = bot + self.connection = connection + self.cursor = self.connection.cursor() + self.create_table() + except Exception as err: + print(err) + + def create_table(self): + try: + create_table_query = """ + CREATE TABLE IF NOT EXISTS `log_history` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `pathname` VARCHAR(255), + `filename` VARCHAR(255), + `funcname` VARCHAR(255), + `lineno` INT, + `logger_name` VARCHAR(255), + `level` VARCHAR(50), + `message` TEXT, + `create_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ) + """ + self.cursor.execute(create_table_query) + self.connection.commit() + except Exception as err: + print(err) + + except Exception as err: + print(err) + + + def emit(self, record): + try: + sql = """ + INSERT INTO `log_history` (`pathname`, `filename`, `funcname`, `lineno`, `logger_name`, `level`, `message`) + VALUES (%s, %s, %s, %s, %s, %s, %s) + """ + values = ( + record.pathname, + record.filename, + record.funcName, + record.lineno, + record.name, + record.levelname, + record.getMessage() + ) + self.cursor.execute(sql, values) + self.connection.commit() + except Exception as err: + print(err) + + + def close(self): + self.cursor.close() + self.connection.close() + super().close() \ No newline at end of file diff --git a/function/function.py b/function/function.py index 9a8558e..99bd9da 100644 --- a/function/function.py +++ b/function/function.py @@ -1,4 +1,5 @@ import logging +import hashlib def x_or_y(data): """ @@ -28,11 +29,16 @@ def x_or_y(data): return '❌' # Return cross mark if data is False except Exception as err: logging.error(err) # Log the error - return '' # Return an empty string if an error occurs + return '' def format_seconds(seconds): hours = int(seconds // 3600) minutes = int((seconds % 3600) // 60) seconds = int(seconds % 60) - return f"{hours} soat {minutes} daqiqa {seconds} soniya" \ No newline at end of file + return f"{hours} soat {minutes} daqiqa {seconds} soniya" + + +def to_hash(text: str) -> int: + hex16 = hashlib.sha256(text.encode("utf-8")).hexdigest()[:16] + return int(hex16, 16) \ No newline at end of file diff --git a/function/translator.py b/function/translator.py index 714229c..c7708e6 100644 --- a/function/translator.py +++ b/function/translator.py @@ -1,18 +1,50 @@ -import logging -from cython_code.my_translator import MyTranslator +from typing import Optional +from deep_translator import GoogleTranslator +from db.database import Database +from function.function import to_hash +from core.feature_manager import FeatureManager -def translator(text, dest, file_path='db/translate.json', real=False): - try: - if dest == 'en' or not dest or not text: - return text + +def translator(text: str, *args, **kwargs) -> str: + return text + + +class Translator: + def __init__(self, db: Database, + FM: FeatureManager = None, + default_dest: str = "en", + default_src: str = "en"): + self.db = db + self.default_dest = default_dest + self.default_src = default_src + self.FM = FM + + def translate(self, + text: str, + dest: Optional[str] = 'en', + src: Optional[str] = 'en') -> str: + if self.FM.feature('translator'): + if dest == src or not text: + return text + dest = dest or self.default_dest + src = src or self.default_src + + + hash_value = to_hash(text) + hash_index = self.db.select_texts(hash_value) + if hash_index: + check = self.db.select_translations(hash_index, dest) + if check: + return check + else: + translated = GoogleTranslator(source=src, target=dest).translate(text) + self.db.insert_translations(text_id=hash_index, dest_lang=dest, translated_content=translated) + return translated + else: + hash_index = self.db.insert_texts(hash_value=hash_value, text=text) + translated = GoogleTranslator(source=src, target=dest).translate(text) + self.db.insert_translations(text_id=hash_index, dest_lang=dest, translated_content=translated) + return translated else: - data = MyTranslator(file_path=file_path, - text=text, - lang=dest, - real=real) - result = data.translator() - return result - except Exception as err: - logging.error(err) - return text + return text \ No newline at end of file diff --git a/handlers/admins/check_usr/attach_usr.py b/handlers/admins/check_usr/attach_usr.py index 398c0ef..16f64ad 100755 --- a/handlers/admins/check_usr/attach_usr.py +++ b/handlers/admins/check_usr/attach_usr.py @@ -55,16 +55,16 @@ async def attach_user(msg: types.Message, state: FSMContext): # User is successfully unblocked text = "✅ User unblocked!" text += translator(text=f'\n\nUsername: @', dest=language_code) + user.username - text += translator(text='\nLanguage code: ', dest=language_code) + f'{user_data['language_code']}' + text += translator(text="\nLanguage code: ", dest=language_code) + user_data['language_code'] else: # User is blocked but is an admin tx = "✅ User blocked!\n👮‍♂️ User is in the list of admins!" text = translator(text=f'{tx}\n\nUsername: @', dest=language_code) + user.username - text += translator(text='\nLanguage code: ', dest=language_code) + f'{user_data['language_code']}' + text += translator(text='\nLanguage code: ', dest=language_code) + f"{user_data['language_code']}" else: # User is already blocked tx = "✅ User blocked!\n Date:" - text = translator(text=f'{tx} {user_data['created_at']}\n\nUsername: @', dest=language_code) + user.username + text = translator(text=f"{tx} {user_data['created_at']}\n\nUsername: @", dest=language_code) + user.username else: # User not found in the bot's list text = translator(text="🔴 User not found!\nThe user may not be in the bot's list..", dest=language_code) diff --git a/loader.py b/loader.py index ef03b5f..e4f8280 100755 --- a/loader.py +++ b/loader.py @@ -1,16 +1,40 @@ import logging from aiogram import Bot, Dispatcher, Router from aiogram.enums import ParseMode -from aiogram.fsm.storage.memory import MemoryStorage +from redis.asyncio import Redis +from aiogram.fsm.storage.redis import RedisStorage from aiogram.client.bot import DefaultBotProperties # Yangi versiyadagi default sozlamalar uchun from data.config import * # Konfiguratsiyalarni import qilamiz -from db.database import Database +from db.database import Database, MySQLHandler +from function.translator import Translator +from core.feature_manager import FeatureManager + + +# MySQL ma'lumotlar bazasi ulanishini yaratamiz +db = Database(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) + + +root_logger = logging.getLogger() +root_logger.setLevel(logging.INFO) + +log_format = '%(filename)s - %(funcName)s - %(lineno)d - %(name)s - %(levelname)s - %(message)s' +formatter = logging.Formatter(log_format) + + +FM = FeatureManager(db=db, root_logger=root_logger) + +for feature in FEATURES: + FM.feature(feature) + + +redis = Redis(host="localhost", port=6379, db=0, decode_responses=True) + # Botni token va default parametr orqali yaratamiz bot = Bot(token=BOT_TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML)) # Xotira asosidagi storage ni yaratamiz -storage = MemoryStorage() +storage = RedisStorage(redis=redis) # Dispatcher obyektini yaratishda bot va storage ni uzatamiz dp = Dispatcher(bot=bot, storage=storage) @@ -18,12 +42,22 @@ # Router obyektini yaratamiz router = Router() -# MySQL ma'lumotlar bazasi ulanishini yaratamiz -db = Database(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) + +translator = Translator(db, FM=FM) + +# middlewares +if FM.feature('middlewares'): + from middlewares.throttling import ThrottlingMiddleware + dp.update.middleware.register(ThrottlingMiddleware(db=db, bot=bot)) # Register the ThrottlingMiddleware + + +# save_log +if FM.feature('save_log'): + mysql_handler = MySQLHandler(bot=bot, connection=db.connection) + log_format = '%(filename)s - %(funcName)s - %(lineno)d - %(name)s - %(levelname)s - %(message)s' + formatter = logging.Formatter(log_format) + root_logger.addHandler(mysql_handler) + -root_logger = logging.getLogger() -root_logger.setLevel(logging.INFO) -log_format = '%(filename)s - %(funcName)s - %(lineno)d - %(name)s - %(levelname)s - %(message)s' -formatter = logging.Formatter(log_format) \ No newline at end of file diff --git a/logs/logging.log b/logs/logging.log index 49c03cd..e5cc4f4 100644 --- a/logs/logging.log +++ b/logs/logging.log @@ -1,6 +1,2 @@ dispatcher.py - start_polling - 527 - aiogram.dispatcher - INFO - Start polling dispatcher.py - _polling - 341 - aiogram.dispatcher - INFO - Run polling for bot @Biloger_uzbot id=1430978281 - 'B' -dispatcher.py - _signal_stop_polling - 455 - aiogram.dispatcher - WARNING - Received SIGINT signal -dispatcher.py - _polling - 359 - aiogram.dispatcher - INFO - Polling stopped for bot @Biloger_uzbot id=1430978281 - 'B' -dispatcher.py - start_polling - 554 - aiogram.dispatcher - INFO - Polling stopped -main.py - main - 39 - root - INFO - 1 diff --git a/main.py b/main.py index e32996c..1aae5f6 100755 --- a/main.py +++ b/main.py @@ -1,14 +1,12 @@ -import middlewares, handlers # Import middlewares and handlers modules -import asyncio -import sys import os +import sys +import asyncio +import middlewares, handlers # Import middlewares and handlers modules from utils.notify_admins import on_startup_notify # Import the function to notify admins on startup import logging from utils.set_bot_commands import set_default_commands # Import the function to set default bot commands from loader import * # Import all from loader module -# from middlewares import ThrottlingMiddleware # Import the ThrottlingMiddleware class -from middlewares.throttling import ThrottlingMiddleware # Import the ThrottlingMiddleware class -from data.config import log_file_name # Import the log file name from config +from data.config import log_file_name, FEATURES # Import the log file name from config async def main(): @@ -17,15 +15,10 @@ async def main(): """ await on_startup_notify() await set_default_commands() # Set the default commands for the bot - dp.update.middleware.register(ThrottlingMiddleware()) # Register the ThrottlingMiddleware try: # Try to create necessary database tables try: - db.create_table_admins() # Create the admins table - db.create_table_users() # Create the users table - db.create_table_channel() # Create the channel table - db.create_table_settings() # Create the settings table mandatory_membership = db.select_setting('mandatory_membership') if mandatory_membership is None: db.insert_settings(initiator_user_id=1, key='mandatory_membership', value='False') diff --git a/middlewares/__init__.py b/middlewares/__init__.py index 9e618ec..be80e96 100644 --- a/middlewares/__init__.py +++ b/middlewares/__init__.py @@ -1,2 +1,2 @@ # from .throttling import ThrottlingMiddleware -from cython_code.throttling_middleware import ThrottlingMiddleware \ No newline at end of file +# from cython_code.throttling_middleware import ThrottlingMiddleware \ No newline at end of file diff --git a/middlewares/throttling.py b/middlewares/throttling.py index cea3de6..706a55f 100755 --- a/middlewares/throttling.py +++ b/middlewares/throttling.py @@ -1,13 +1,10 @@ -import logging import time +import logging from data.config import ADMIN from keyboards.inline.close_btn import close_btn from aiogram import BaseMiddleware, types -from aiogram.filters import BaseFilter from aiogram.utils.keyboard import InlineKeyboardBuilder -from aiogram.types import Message, CallbackQuery from keyboards.inline.button import MainCallback -from loader import bot, db from function.translator import translator @@ -19,7 +16,7 @@ class ThrottlingMiddleware(BaseMiddleware): If a user receives the throttling warning 3 times within 1 minute, they are banned for 1 hour. """ - def __init__(self, default_rate: float = 0.5) -> None: + def __init__(self, bot, db, default_rate: float = 0.5) -> None: """ Initializes the ThrottlingMiddleware instance. @@ -28,6 +25,8 @@ def __init__(self, default_rate: float = 0.5) -> None: """ self.limiters = {} # Dictionary to store per-user throttling data. self.default_rate = default_rate + self.bot = bot + self.db = db async def __call__(self, handler, event: types.Message, data): @@ -53,7 +52,7 @@ async def __call__(self, handler, event: types.Message, data): if user_id == ADMIN: return await handler(event, data) - user_data = db.check_user(user_id=user_id) + user_data = self.db.check_user(user_id=user_id) if user_data: is_ban = await self.check_ban(user_data) if is_ban: @@ -90,12 +89,12 @@ async def __call__(self, handler, event: types.Message, data): # Agar throttling hisobi 3 yoki undan ko'p bo'lsa, foydalanuvchini ban qilamiz. if user_data["count"] >= 3: try: - db.ban_user_for_one_hour(user_id, comment="1 hour due to too many requests.") + self.db.ban_user_for_one_hour(user_id, comment="1 hour due to too many requests.") tx = translator( text='You have been banned for 1 hour due to too many requests.', dest=language_code ) - await bot.send_message(chat_id=user_id, text=tx) + await self.bot.send_message(chat_id=user_id, text=tx) except Exception as err: logging.error(f"Error banning user {user_id}: {err}") # Reset the counter to oldindan qayta-ban qilishdan saqlanish uchun. @@ -106,7 +105,7 @@ async def __call__(self, handler, event: types.Message, data): try: await event.callback_query.answer(tx) except Exception: - await bot.send_message( + await self.bot.send_message( chat_id=user_id, text=tx, reply_markup=close_btn() @@ -120,7 +119,7 @@ async def __call__(self, handler, event: types.Message, data): else: return await handler(event, data) else: - db.insert_user(user_id=user_id, + self.db.insert_user(user_id=user_id, language_code=language_code) return await handler(event, data) @@ -133,9 +132,9 @@ async def check_ban(self, user_data): "⚠ If you think this is a mistake, contact the admin.", dest=user_data['language_code']) if user_data['initiator_user_id'] == 1 or user_data['initiator_user_id'] == 0: - text += f"\n\n👮‍♂️ Admin: Bot\n " + text += f"\n\n👮‍♂️ Admin: self.bot\n " elif user_data['initiator_user_id'] is not None: - admin_info = await bot.get_chat(chat_id=user_data['updater_user_id']) + admin_info = await self.bot.get_chat(chat_id=user_data['updater_user_id']) text += f"\n\n👮‍♂️ Admin @{admin_info.username}\n " if user_data['comment'] is not None: text += f"\n📝 Comment: {user_data['comment']}\n" @@ -143,11 +142,11 @@ async def check_ban(self, user_data): if user_data['ban_time'] is not None: text += f"\n📅 Ban time: {user_data['ban_time']}\n" - admins = await bot.get_chat(chat_id=ADMIN) + admins = await self.bot.get_chat(chat_id=ADMIN) text += f'👩‍💻 Super admin @{admins.username}\n' - await bot.send_message(chat_id=user_data['user_id'], + await self.bot.send_message(chat_id=user_data['user_id'], text=f"{text}", reply_markup=close_btn()) return True @@ -160,15 +159,15 @@ async def check_ban(self, user_data): async def check_member(self, user_id, language_code): try: - is_mandatory = db.select_setting('mandatory_membership') + is_mandatory = self.db.select_setting('mandatory_membership') if is_mandatory is None: - db.update_settings_key(updater_user_id=1, key='mandatory_membership', value=False) + self.db.update_settings_key(updater_user_id=1, key='mandatory_membership', value=False) return False elif is_mandatory == 'False': return False elif is_mandatory == 'True': try: - channels = db.select_channels() + channels = self.db.select_channels() except Exception as err: logging.error(f"Error selecting channels: {err}") return False @@ -176,20 +175,20 @@ async def check_member(self, user_id, language_code): for channel in channels: try: chat_id = int("-100" + str(channel.get('channel_id'))) - res = await bot.get_chat_member(chat_id=chat_id, user_id=user_id) + res = await self.bot.get_chat_member(chat_id=chat_id, user_id=user_id) if res.status not in ('member', 'administrator', 'creator'): count = 0 - keyboard = InlineKeyboardBuilder() + keyboard = InlineKeyboardBuilder.dbuilder() message_text = translator(text="🛑 You have not joined the channel(s)!:\n\n", dest=language_code) for x in channels: channel_id = str(-100) + str(x['channel_id']) - channel = await bot.get_chat(channel_id) + channel = await self.bot.get_chat(channel_id) try: - chat_member_status = await bot.get_chat_member(chat_id=channel_id, user_id=user_id) + chat_member_status = await self.bot.get_chat_member(chat_id=channel_id, user_id=user_id) except Exception as e: logging.error(f"Error getting chat member status: {e}") continue @@ -207,7 +206,7 @@ async def check_member(self, user_id, language_code): keyboard.adjust(1) # Send the message to the user - await bot.send_message(chat_id=user_id, + await self.bot.send_message(chat_id=user_id, text=f"{message_text}", reply_markup=keyboard.as_markup()) return True From d070d197355f32ed505b12269d8b3240b816cefc Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Mon, 12 May 2025 23:50:12 +0500 Subject: [PATCH 37/71] Implement feature management with Redis caching and user prompts; add integration tests for live feature updates --- .github/workflows/ci.yml | 28 ++++ Makefile | 35 +++++ conftest.py | 43 ++++++ core/feature_manager.py | 73 +++++++--- db/database.py | 14 ++ docker-compose.test.yml | 12 ++ pytest.ini | 6 + requirements.txt | 47 ++----- setup.py | 113 ++++++++++++++-- test/feature_manager.py | 127 ++++++++++++++++++ test/integration/test_feature_manager_live.py | 27 ++++ test/unit/test_feature_manager.py | 0 12 files changed, 458 insertions(+), 67 deletions(-) create mode 100644 .github/workflows/ci.yml create mode 100644 Makefile create mode 100644 conftest.py create mode 100644 docker-compose.test.yml create mode 100644 pytest.ini create mode 100644 test/feature_manager.py create mode 100644 test/integration/test_feature_manager_live.py create mode 100644 test/unit/test_feature_manager.py diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e3a53b2 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,28 @@ +name: CI + +on: [push, pull_request] + +jobs: + test: + runs-on: ubuntu-latest + services: + mysql: + image: mysql:8.4 + env: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: app_db + ports: [3306] + options: --health-cmd="mysqladmin ping -h localhost -proot" --health-interval=5s --health-timeout=5s --health-retries=5 + redis: + image: redis:7-alpine + ports: [6379] + options: >- + --health-cmd="redis-cli ping" --health-interval=5s + --health-timeout=5s --health-retries=5 + + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: { python-version: '3.12' } + - run: pip install -r requirements.txt + - run: pytest -q --cov=. diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5b72162 --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +.DEFAULT_GOAL := setup +SHELL := bash + +VENV := env + +ifeq (, $(shell command -v python3 2> /dev/null)) + PY_SYS := python +else + PY_SYS := python3 +endif + +ifeq ($(OS),Windows_NT) + VENV_PY := $(VENV)/Scripts/python.exe +else + VENV_PY := $(VENV)/bin/python +endif + +.PHONY: setup requirements venv + +setup: requirements + $(VENV_PY) setup.py + +requirements: venv + $(VENV_PY) -m pip install --upgrade pip + $(VENV_PY) -m pip install --upgrade mysql-connector-python + +venv: + @if [ ! -f "$(VENV_PY)" ]; then \ + echo "🔧 Creating virtual environment in $(VENV)"; \ + $(PY_SYS) -m venv $(VENV); \ + $(VENV_PY) -m pip install --upgrade pip; \ + $(VENV_PY) -m pip install -r requirements.txt; \ + else \ + echo "✅ Virtual environment already exists."; \ + fi diff --git a/conftest.py b/conftest.py new file mode 100644 index 0000000..6375e8b --- /dev/null +++ b/conftest.py @@ -0,0 +1,43 @@ +import os, time, contextlib +import pytest +import mysql.connector +from redis import Redis +from pytest_docker.plugin import Services + +MYSQL_URL = "mysql://root:root@localhost:3306/app_db" + +# ───────────── Docker servislar tayyor bo‘lguncha kutish ───────────── +def _wait_mysql_up(): + for _ in range(20): + try: + mysql.connector.connect( + host="localhost", user="root", password="root", database="app_db" + ).close() + return + except mysql.connector.Error: + time.sleep(1) + pytest.exit("MySQL konteyneri ishga tushmadi", returncode=1) + +def _wait_redis_up(): + for _ in range(20): + try: + Redis(host="localhost", port=6379).ping() + return + except Exception: + time.sleep(1) + pytest.exit("Redis konteyneri ishga tushmadi", returncode=1) + +# ───────────── Pytest hooks ───────────── +def pytest_configure(): + os.environ["DATABASE_URL"] = MYSQL_URL + os.environ["REDIS_HOST"] = "localhost" + +# ───────────── Docker services fixture ───────────── +@pytest.fixture(scope="session", autouse=True) +def _spin_up_docker_services(docker_services: Services): + """Redis va MySQL konteynerlarini test sessiyasi boshida ko‘taradi.""" + docker_services.start() # docker-compose.test.yml bo‘yicha + _wait_mysql_up() + _wait_redis_up() + yield + docker_services.stop() diff --git a/core/feature_manager.py b/core/feature_manager.py index 7776667..86a5a50 100644 --- a/core/feature_manager.py +++ b/core/feature_manager.py @@ -1,26 +1,65 @@ import logging +from typing import Optional from db.database import Database +from redis import Redis, RedisError class FeatureManager: + _REDIS_HASH = "features" - def __init__(self, db: Database, root_logger: logging.Logger): + def __init__( + self, + db: Database, + redis_client: Redis, + root_logger: logging.Logger, + ): self.db = db - self.root_logger = root_logger - + self.redis = redis_client + self.log = root_logger + def feature(self, name: str) -> bool: try: - feature = self.db.select_feature(name) - if feature is None: - access = input(f"Feature '{name}' not found in the database. Do you want to enable it? (y/n): ") - if access.lower() == 'y': - self.db.insert_feature(name=name, enabled=True) - return True - else: - self.db.insert_feature(name=name, enabled=False) - return False - else: - return feature - except Exception as e: - self.root_logger.error(f"Error in is_enabled: {e}") - return False \ No newline at end of file + cached = self._get_from_redis(name) + if cached is not None: + return cached + + db_value = self.db.select_feature(name) + if db_value is None: + enabled = self._ask_user(name) + self._persist(name, enabled) + return enabled + + self.redis.hset(self._REDIS_HASH, name, int(db_value)) + return bool(db_value) + + except (RedisError, Exception) as exc: + self.log.error(f"Error in feature('{name}'): {exc}") + return False + + def update_feature(self, name: str, enabled: bool) -> None: + try: + rows = self.db.update_feature(name=name, enabled=enabled) + if rows == 0: # feature yo‘q edi + self.db.insert_feature(name=name, enabled=enabled) + + self.redis.hset(self._REDIS_HASH, name, int(enabled)) + + self.log.info(f"Feature '{name}' updated → {enabled}") + + except (RedisError, Exception) as exc: + self.log.error(f"Error in update_feature('{name}'): {exc}") + raise + + def _get_from_redis(self, name: str) -> Optional[bool]: + val = self.redis.hget(self._REDIS_HASH, name) + return bool(int(val)) if val is not None else None + + def _ask_user(self, name: str) -> bool: + access = input( + f"Feature '{name}' not found, do you want to enable it? (y/n): " + ) + return access.strip().lower() == "y" + + def _persist(self, name: str, enabled: bool) -> None: + self.db.insert_feature(name=name, enabled=enabled) + self.redis.hset(self._REDIS_HASH, name, int(enabled)) diff --git a/db/database.py b/db/database.py index 69c9728..48d57b5 100755 --- a/db/database.py +++ b/db/database.py @@ -363,6 +363,20 @@ def insert_admin(self, user_id, initiator_user_id): logging.error(err) ## ------------------ Update ------------------ ## + def update_feature(self, name: str, enabled: bool): + """ + Update a feature in the 'features' table. + """ + try: + sql = "UPDATE `features` SET `enabled` = %s WHERE `name` = %s" + values = (int(enabled), name) + self.cursor.execute(sql, values) + self.connection.commit() + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) def update_settings_key(self, updater_user_id, key, value): """ diff --git a/docker-compose.test.yml b/docker-compose.test.yml new file mode 100644 index 0000000..c14cebb --- /dev/null +++ b/docker-compose.test.yml @@ -0,0 +1,12 @@ +services: + mysql: + image: mysql:8.4 + command: --default-authentication-plugin=mysql_native_password + environment: + MYSQL_ROOT_PASSWORD: root + MYSQL_DATABASE: app_db + ports: ["3306:3306"] + + redis: + image: redis:7-alpine + ports: ["6379:6379"] diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..eb3b349 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,6 @@ +[pytest] +asyncio_mode = auto +testpaths = tests +addopts = -ra -q --cov=. +markers = + integration: Slow tests with real Redis/MySQL diff --git a/requirements.txt b/requirements.txt index b0e92b2..b52f65d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,37 +1,10 @@ -aiofiles==23.2.1 -aiogram==3.18.0 -aiohttp==3.9.5 -aiosignal==1.3.2 -annotated-types==0.7.0 -attrs==25.1.0 -beautifulsoup4==4.13.3 -certifi==2025.1.31 -charset-normalizer==3.4.1 -Cython==3.0.11 -deep-translator==1.11.4 -environs==11.0.0 -et_xmlfile==2.0.0 -frozenlist==1.5.0 -idna==3.10 -magic-filter==1.0.12 -marshmallow==3.26.1 -multidict==6.1.0 -mysql-connector-python==9.0.0 -numpy==2.0.1 -openpyxl==3.1.5 -packaging==24.2 -pandas==2.2.2 -propcache==0.3.0 -pydantic==2.7.4 -pydantic_core==2.18.4 -python-dateutil==2.9.0.post0 -python-dotenv==1.0.1 -pytz==2025.1 -requests==2.32.3 -setuptools==75.8.2 -six==1.17.0 -soupsieve==2.6 -typing_extensions==4.12.2 -tzdata==2025.1 -urllib3==2.2.2 -yarl==1.18.3 +aiogram>=3.4 +redis>=5.0 +mysql-connector-python>=8.4 +python-dotenv>=1.0 +pytest>=8.2 +pytest-asyncio>=0.23 +pytest-cov>=5.0 +pytest-docker>=0.13 +pytest-mock>=3.14 +aioresponses>=0.7 diff --git a/setup.py b/setup.py index b8b179e..cd2cd68 100644 --- a/setup.py +++ b/setup.py @@ -1,19 +1,106 @@ -from setuptools import setup, Extension -from Cython.Build import cythonize +import os +import sys +from getpass import getpass -extensions = [ - Extension(name="cython_code.my_translator", sources=["cython_code/my_translator.pyx"]), - Extension(name="cython_code.throttling_middleware", sources=["cython_code/throttling_middleware.pyx"]), - Extension(name="cython_code.send_ads", sources=["cython_code/send_ads.pyx"]), # Corrected +REQUIRED = [ + "BOT_TOKEN", + "ADMIN", + "HOST", + "MYSQL_USER", + "MYSQL_PASSWORD", + "MYSQL_DATABASE", ] +ENV_PATH = ".env" -setup( - ext_modules=cythonize(extensions, build_dir="build", language_level="3"), - package_dir={"cython_code": "cython_code"}, - packages=["cython_code"], - zip_safe=False, -) +def load_env(path=ENV_PATH) -> dict: + if not os.path.isfile(path): + return {} + data = {} + with open(path, encoding="utf-8") as f: + for line in f: + line = line.strip() + if not line or line.startswith("#") or "=" not in line: + continue + k, v = line.split("=", 1) + data[k.strip()] = v.strip() + return data -# python setup.py build_ext --inplace \ No newline at end of file +def save_env(cfg: dict, path=ENV_PATH) -> None: + with open(path, "w", encoding="utf‑8") as f: + for k in REQUIRED: + f.write(f"{k}={cfg[k]}\n") + print(f"✅ {path} written.") + + +def prompt_for(keys: list[str], base: dict | None = None) -> dict: + cfg = base.copy() if base else {} + for k in keys: + if k in cfg and cfg[k]: + continue + if k == "MYSQL_PASSWORD": + val = getpass(f"{k}: ") + else: + val = input(f"{k}: ") + cfg[k] = val.strip() + return cfg + + +def test_mysql(cfg: dict) -> bool: + """Attempt to connect to MySQL with the supplied settings.""" + try: + import mysql.connector + except ModuleNotFoundError: + print("❌ mysql‑connector‑python not installed. Run:\n" + " pip install mysql‑connector‑python") + return False + + try: + conn = mysql.connector.connect( + host=cfg["HOST"], + user=cfg["MYSQL_USER"], + password=cfg["MYSQL_PASSWORD"], + database=cfg["MYSQL_DATABASE"], + connection_timeout=5, + ) + conn.close() + print("✅ Database connection successful.") + return True + except mysql.connector.Error as e: + print(f"❌ Database connection failed: {e}") + return False + + +def ask_yes(question: str, default_no=True) -> bool: + suffix = "[y/N]: " if default_no else "[Y/n]: " + ans = input(question + " " + suffix).strip().lower() + return ans == "y" if default_no else ans != "n" + + +def main_setup() -> None: + cfg = load_env() + print("🔧 Configuration wizard") + + while True: + missing = [k for k in REQUIRED if k not in cfg or not cfg[k]] + if missing: + print(f"Missing values: {', '.join(missing)}") + cfg = prompt_for(missing, cfg) + + if test_mysql(cfg): + save_env(cfg) + break + else: + if not ask_yes("Re‑enter all values and try again?"): + print("👋 Aborted. .env NOT saved.") + break + cfg = prompt_for(REQUIRED, {}) + + +if __name__ == "__main__": + try: + main_setup() + except KeyboardInterrupt: + print("\n👋 Interrupted. .env NOT saved.") + sys.exit(1) diff --git a/test/feature_manager.py b/test/feature_manager.py new file mode 100644 index 0000000..54ac8d7 --- /dev/null +++ b/test/feature_manager.py @@ -0,0 +1,127 @@ +import logging +from unittest.mock import MagicMock, patch + +import pytest +from redis import RedisError + +# Import the class under test +from core.feature_manager import FeatureManager + + +# ──────────────────────────── Fixtures ──────────────────────────── + +@pytest.fixture +def db_mock(): + """Return a mock of the Database adapter.""" + mock = MagicMock() + # select_feature → None by default (no record) + mock.select_feature.return_value = None + # update_feature returns number of affected rows (1 = updated, 0 = not found) + mock.update_feature.return_value = 1 + return mock + + +@pytest.fixture +def redis_mock(): + """Return a mock of the Redis client (decode_responses=True expected).""" + mock = MagicMock() + mock.hget.return_value = None # no value cached by default + return mock + + +@pytest.fixture +def logger(): + """Real logger (captures to pytest).""" + logging.basicConfig(level=logging.DEBUG) + return logging.getLogger("feature_manager_test") + + +@pytest.fixture +def fm(db_mock, redis_mock, logger): + """FeatureManager instance with mocked dependencies.""" + return FeatureManager(db=db_mock, redis_client=redis_mock, root_logger=logger) + + +# ──────────────────────────── Tests: Feature lookup ──────────────────────────── + +def test_feature_returns_cached_value(fm, redis_mock, db_mock): + """If Redis already has the flag, it should be returned and DB not queried.""" + redis_mock.hget.return_value = "1" # cached True + result = fm.feature("dark_mode") + assert result is True + redis_mock.hget.assert_called_once_with(fm._REDIS_HASH, "dark_mode") + # DB should be untouched + db_mock.select_feature.assert_not_called() + + +def test_feature_fallbacks_to_db_and_caches(fm, redis_mock, db_mock): + """If Redis miss but DB has value, it must be cached and returned.""" + redis_mock.hget.return_value = None + db_mock.select_feature.return_value = 0 # False in DB + + result = fm.feature("dark_mode") + assert result is False + + redis_mock.hset.assert_called_once_with(fm._REDIS_HASH, "dark_mode", 0) + db_mock.select_feature.assert_called_once_with("dark_mode") + + +@pytest.mark.parametrize("user_input, expected_bool", [("y", True), ("n", False)]) +@patch("builtins.input") +def test_feature_asks_user_when_not_found(mock_input, fm, redis_mock, db_mock, user_input, expected_bool): + """When not in Redis nor DB, ask user; persist answer to both stores.""" + mock_input.return_value = user_input + redis_mock.hget.return_value = None + db_mock.select_feature.return_value = None + + result = fm.feature("beta_flag") + + assert result is expected_bool + # Persist to DB & Redis + db_mock.insert_feature.assert_called_once_with(name="beta_flag", enabled=expected_bool) + redis_mock.hset.assert_called_once_with(fm._REDIS_HASH, "beta_flag", int(expected_bool)) + + +# ──────────────────────────── Tests: update_feature ──────────────────────────── + +def test_update_feature_updates_existing_flag(fm, redis_mock, db_mock): + """update_feature should call DB.update_feature and Redis.hset when flag exists.""" + db_mock.update_feature.return_value = 1 # one row updated + + fm.update_feature("dark_mode", enabled=True) + + db_mock.update_feature.assert_called_once_with(name="dark_mode", enabled=True) + db_mock.insert_feature.assert_not_called() + redis_mock.hset.assert_called_once_with(fm._REDIS_HASH, "dark_mode", 1) + + +def test_update_feature_inserts_when_not_exists(fm, redis_mock, db_mock): + """If DB.update_feature affects 0 rows, insert_feature must be called.""" + db_mock.update_feature.return_value = 0 + + fm.update_feature("new_flag", enabled=False) + + db_mock.update_feature.assert_called_once_with(name="new_flag", enabled=False) + db_mock.insert_feature.assert_called_once_with(name="new_flag", enabled=False) + redis_mock.hset.assert_called_once_with(fm._REDIS_HASH, "new_flag", 0) + + +# ──────────────────────────── Tests: error handling ──────────────────────────── + +def test_feature_redis_error_returns_false(fm, redis_mock, caplog): + """If Redis raises an error, feature() should log it and return False.""" + caplog.set_level(logging.ERROR) + redis_mock.hget.side_effect = RedisError("Redis down") + + result = fm.feature("unstable_flag") + + assert result is False + assert any("Redis down" in r.message for r in caplog.records) + + +def test_update_feature_redis_error_raises(fm, redis_mock): + """update_feature should re‑raise if RedisError occurs (transactional).""" + redis_mock.hset.side_effect = RedisError("write failed") + + with pytest.raises(RedisError): + fm.update_feature("any_flag", enabled=True) diff --git a/test/integration/test_feature_manager_live.py b/test/integration/test_feature_manager_live.py new file mode 100644 index 0000000..5b5949a --- /dev/null +++ b/test/integration/test_feature_manager_live.py @@ -0,0 +1,27 @@ +import logging +from feature_manager import FeatureManager +from db.database import Database +from redis import Redis +import mysql.connector + +log = logging.getLogger("it") + +def _db(): + conn = mysql.connector.connect( + host="localhost", user="root", password="root", database="app_db" + ) + return Database(conn) # sizning adapteringiz (simple wrapper bo‘lishi mumkin) + +def _redis(): + return Redis(host="localhost", port=6379, decode_responses=True) + +def test_live_roundtrip(tmp_path): + fm = FeatureManager(db=_db(), redis_client=_redis(), root_logger=log) + name = "integration_flag" + + # new → user prompt'ni bypass qilish uchun _persist chaqiramiz + fm._persist(name, True) + assert fm.feature(name) is True + + fm.update_feature(name, enabled=False) + assert fm.feature(name) is False diff --git a/test/unit/test_feature_manager.py b/test/unit/test_feature_manager.py new file mode 100644 index 0000000..e69de29 From 77eaca0f18a99e908c374bb94cd9677e9e8a543b Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Tue, 13 May 2025 20:07:11 +0500 Subject: [PATCH 38/71] Refactor Makefile to set default goal to 'main' and enhance setup commands; remove unused Cython files and update requirements for new dependencies. --- Makefile | 10 +- cython_code/file_db.pyx | 75 -------------- cython_code/my_translator.pyx | 49 --------- cython_code/send_ads.pyx | 137 -------------------------- cython_code/throttling_middleware.pyx | 95 ------------------ cython_code/user_check.pyx | 87 ---------------- data/config.py | 1 - function/translator.py | 8 ++ loader.py | 23 +---- main.py | 24 +++-- pytest.ini | 6 -- requirements.txt | 23 +++-- setup.py | 11 +++ 13 files changed, 60 insertions(+), 489 deletions(-) delete mode 100644 cython_code/file_db.pyx delete mode 100644 cython_code/my_translator.pyx delete mode 100644 cython_code/send_ads.pyx delete mode 100644 cython_code/throttling_middleware.pyx delete mode 100644 cython_code/user_check.pyx delete mode 100644 pytest.ini diff --git a/Makefile b/Makefile index 5b72162..e4cc85e 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.DEFAULT_GOAL := setup +.DEFAULT_GOAL := main SHELL := bash VENV := env @@ -15,12 +15,18 @@ else VENV_PY := $(VENV)/bin/python endif -.PHONY: setup requirements venv +.PHONY: main setup requirements venv + +main: setup + @echo "🚀 Running main.py…" + $(VENV_PY) main.py setup: requirements + @echo "⚙️ Running setup.py…" $(VENV_PY) setup.py requirements: venv + @echo "📦 Installing/upgrading requirements…" $(VENV_PY) -m pip install --upgrade pip $(VENV_PY) -m pip install --upgrade mysql-connector-python diff --git a/cython_code/file_db.pyx b/cython_code/file_db.pyx deleted file mode 100644 index 3b52005..0000000 --- a/cython_code/file_db.pyx +++ /dev/null @@ -1,75 +0,0 @@ -# file_db.pyx -import json -import logging -import os -from cython cimport bint, dict - -cdef class BotDb: - cdef str file - cdef dict json_data - - def __cinit__(self, str file): - self.file = file - try: - with open(self.file, "r") as json_file: - self.json_data = json.load(json_file) - except (FileNotFoundError, json.JSONDecodeError): - data = {"join_channel": False} - with open(self.file, "w") as json_file: - json.dump(data, json_file) - os.chmod(self.file, 0o777) - with open(self.file, "r") as json_file: - self.json_data = json.load(json_file) - logging.info(f'Created new file: {file} with default data') - - def reading_db(self): - with open(self.file, "r") as json_file: - return json.load(json_file) - - def change_data(self, bint join_channel): - self.json_data['join_channel'] = join_channel - with open(self.file, "w") as json_file: - json.dump(self.json_data, json_file) - -cdef class FileDB: - cdef str file - cdef dict json_data - - def __cinit__(self, str file): - self.file = file - try: - with open(self.file, "r") as json_file: - self.json_data = json.load(json_file) - except (FileNotFoundError, json.JSONDecodeError): - data = {"ads": False, - "join_channel": False} - with open(self.file, "w") as json_file: - json.dump(data, json_file) - os.chmod(self.file, 0o777) - with open(self.file, "r") as json_file: - self.json_data = json.load(json_file) - logging.info(f'Created new file: {file} with default data') - - def reading_db(self): - try: - with open(self.file, "r") as json_file: - return json.load(json_file) - except Exception as err: - logging.info(f'Error reading the file: {err}') - - def add_data(self, data, str key): - try: - with open(self.file, "r") as json_file: - self.json_data = json.load(json_file) - self.json_data[str(key)] = data - with open(self.file, "w") as json_file: - json.dump(self.json_data, json_file) - except Exception as err: - logging.error(f'Error updating the file: {err}') - - def new_data(self, dict data): - try: - with open(self.file, "w") as json_file: - json.dump(data, json_file) - except Exception as err: - logging.error(f'Error writing to the file: {err}') diff --git a/cython_code/my_translator.pyx b/cython_code/my_translator.pyx deleted file mode 100644 index fb3a964..0000000 --- a/cython_code/my_translator.pyx +++ /dev/null @@ -1,49 +0,0 @@ -import json -import logging -from deep_translator import GoogleTranslator -from data.config import yil_oy_kun, soat_minut_sekund - -cdef class MyTranslator: - cdef str file_path - cdef str text - cdef str lang - cdef bint real - cdef dict json_data - - def __init__(self, str file_path, str text, str lang, bint real=False): - self.file_path = file_path - self.text = text - self.lang = lang - self.real = real - try: - with open(self.file_path, "r") as json_file: - self.json_data = json.load(json_file) - except (FileNotFoundError, json.JSONDecodeError): - data = {"date": str(yil_oy_kun) + ' / ' + str(soat_minut_sekund)} - with open(self.file_path, "w") as json_file: - json.dump(data, json_file) - with open(self.file_path, "r") as json_file: - self.json_data = json.load(json_file) - - def translator(self): - try: - if self.real: - return GoogleTranslator(source='auto', target=self.lang).translate(self.text) - try: - return self.json_data[self.text][self.lang] - except KeyError: - pass - result = GoogleTranslator(source='auto', target=self.lang).translate(self.text) - data = { - self.lang: result - } - try: - self.json_data[self.text] = data - with open(self.file_path, "w") as json_file: - json.dump(self.json_data, json_file) - except Exception as err: - logging.error(err) - return result - except Exception as err: - logging.error(err) - return self.text \ No newline at end of file diff --git a/cython_code/send_ads.pyx b/cython_code/send_ads.pyx deleted file mode 100644 index 48b4534..0000000 --- a/cython_code/send_ads.pyx +++ /dev/null @@ -1,137 +0,0 @@ -# send_ads.pyx -import requests -import logging -import time -import mysql.connector # Import normally, do not use 'cimport' -from data.config import * -from loader import db, file_db - -cdef class MyDatabase: - cdef str host, user, password, database - cdef object connection # Use 'object' since it's a generic Python object - cdef object cursor # Use 'object' since it's a generic Python object - - def __init__(self, str host, str user, str password, str database): - self.host = host - self.user = user - self.password = password - self.database = database - self.reconnect() - - def reconnect(self): - try: - self.connection = mysql.connector.connect( - host=self.host, - user=self.user, - password=self.password, - database=self.database, - autocommit=True - ) - self.cursor = self.connection.cursor() - except mysql.connector.Error as err: - logging.error(err) - self.reconnect() - except Exception as err: - logging.error(err) - - def select_users_by_id(self, int start_id, int end_id) -> list: - try: - sql_query = "SELECT * FROM `users` WHERE `id` >= %s AND `id` < %s;" - query_values = (start_id, end_id) - self.cursor.execute(sql_query, query_values) - result = self.cursor.fetchall() - return result - except mysql.connector.Error as err: - logging.error(err) - self.reconnect() - except Exception as err: - logging.error(err) - -cdef MyDatabase my_db = MyDatabase(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) - -def copy_message_sync(int chat_id, int from_chat_id, int message_id, **kwargs): - url = f"https://api.telegram.org/bot{BOT_TOKEN}/copyMessage" - data = { - "chat_id": chat_id, - "from_chat_id": from_chat_id, - "message_id": message_id - } - data.update(kwargs) - response = requests.post(url, data=data) - return response.json() - -def send_message_sync(int chat_id, str text, **kwargs): - url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage" - data = { - "chat_id": chat_id, - "text": text - } - data.update(kwargs) - response = requests.post(url, data=data) - return response.json() - -def send_ads(): - cdef float start_time, end_time, total_time, per_time - cdef int start_index, end_index, total_users, chat_id, from_chat_id, message_id - cdef str caption - users_batch = None - reply_markup = None - - try: - start_time = time.time() - ads_data = file_db.reading_db()['ads'] - if ads_data: - start_index = ads_data['start'] - from_chat_id = ads_data['from_chat_id'] - message_id = ads_data['message_id'] - caption = ads_data['caption'] - reply_markup = ads_data['reply_markup'] - total_users = ads_data['total_users'] - end_index = min(start_index + 100, total_users) - - users_batch = my_db.select_users_by_id(start_index, end_index) - if users_batch: - logging.info(f'Sending ads to users {start_index} - {end_index} (Total: {len(users_batch)})') - for user in users_batch: - try: - chat_id = user[1] - copy_message_sync(chat_id, - from_chat_id, - message_id, - caption=caption, - reply_markup=reply_markup) - ads_data["done_count"] += 1 - except Exception as err: - logging.error(err) - ads_data["fail_count"] += 1 - - if end_index < total_users: - time.sleep(1) - end_time = time.time() - total_time = end_time - start_time - per_time = ads_data["per_time"] - if per_time < total_time: - ads_data["per_time"] = per_time - ads_data['start'] = end_index - file_db.add_data(ads_data, key='ads') - return send_ads() - else: - file_db.add_data(False, key='ads') - summary_message = ( - f"📬 Advertisement Sending Completed\n\n" - f"👥 Total Users: {total_users}\n" - f"✅ Sent: {ads_data['done_count']}\n" - f"❌ Failed: {ads_data['fail_count']}\n" - f"⏰ Start Time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(ads_data['start-time']))}\n" - f"🕒 End Time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))}" - ) - send_message_sync(from_chat_id, summary_message) - elif users_batch is None: - db.reconnect() - time.sleep(2) - else: - return - else: - return - except Exception as err: - logging.error(err) diff --git a/cython_code/throttling_middleware.pyx b/cython_code/throttling_middleware.pyx deleted file mode 100644 index 939385d..0000000 --- a/cython_code/throttling_middleware.pyx +++ /dev/null @@ -1,95 +0,0 @@ -# cython: language_level=3 -import logging -import time -from keyboards.inline.close_btn import close_btn -from aiogram import BaseMiddleware, types -from loader import bot, db -from function.translator import translator - -# E'tibor bering: BaseMiddleware toza Python klassi, shuning uchun cdef class emas. -class ThrottlingMiddleware(BaseMiddleware): - """ - So'rovlarni cheklash (throttling) orqali tizim yuklanishini kamaytiruvchi middleware. - Agar foydalanuvchi 1 daqiqa ichida 3 marta "Many requests have been made" xabarini olsa, - u 1 soatga ban qilinadi. - """ - def __init__(self, default_rate: float = 0.5) -> None: - """ - Middleware'ni boshlang'ich sozlamalar bilan yaratadi. - - Parameters: - default_rate (float): So'rovlar oralig'idagi minimal vaqt (sekundlarda), default 0.5 sekund. - """ - self.limiters = {} # Foydalanuvchi ID bo'yicha throttling ma'lumotlari - self.default_rate = default_rate - - async def __call__(self, handler, event: types.Message, data): - """ - So'rovlarni qabul qilib, throttling qoidalarini bajarsa, keyingi handlerga o'tadi. - Agar foydalanuvchi 1 daqiqa ichida 3 marta throttlingga tushsa, u 1 soatga ban qilinadi. - """ - # real_handler-ni oddiy Python obyekti sifatida olamiz, uni C tip sifatida belgilashga hojat yo'q - real_handler = data["handler"] - skip_pass = True - - # Foydalanuvchi identifikatori va tilini aniqlaymiz - if event.message: - user_id = event.message.from_user.id - lang = event.message.from_user.language_code - elif event.callback_query: - user_id = event.callback_query.from_user.id - lang = event.callback_query.from_user.language_code - else: - lang = 'en' - return await handler(event, data) - - if real_handler.flags.get("skip_pass") is not None: - skip_pass = real_handler.flags.get("skip_pass") - - now = time.time() - # Har bir foydalanuvchi uchun: "last": oxirgi so'rov vaqti, "count": throttled holatlar soni, "first": oynaning boshlanish vaqti - user_data = self.limiters.get(user_id, {"last": now, "count": 0, "first": now}) - - if skip_pass: - if now - user_data["last"] >= self.default_rate: - user_data["last"] = now - user_data["count"] = 0 # Hisobni tiklash - user_data["first"] = now - self.limiters[user_id] = user_data - return await handler(event, data) - else: - if now - user_data["first"] > 60: - user_data["count"] = 0 - user_data["first"] = now - user_data["count"] += 1 - - if user_data["count"] >= 3: - try: - db.ban_user_for_one_hour(user_id) - tx = translator( - text='You have been banned for 1 hour due to too many requests.', - dest=lang - ) - await bot.send_message(chat_id=user_id, text=tx) - except Exception as err: - logging.error("Error banning user %d: %s", user_id, err) - user_data["count"] = 0 - else: - try: - tx = translator(text='Many requests have been made', dest=lang) - try: - await event.callback_query.answer(tx) - except Exception: - await bot.send_message( - chat_id=user_id, - text=tx, - reply_markup=close_btn() - ) - except Exception as err: - logging.error(err) - - user_data["last"] = now - self.limiters[user_id] = user_data - return - else: - return await handler(event, data) diff --git a/cython_code/user_check.pyx b/cython_code/user_check.pyx deleted file mode 100644 index 8a47b81..0000000 --- a/cython_code/user_check.pyx +++ /dev/null @@ -1,87 +0,0 @@ -# user_check.pyx -import logging -from loader import bot, db, DB -from data.config import ADMIN -from aiogram.filters import BaseFilter -from aiogram.types import Message, CallbackQuery -from aiogram import BaseMiddleware - - -class User_Check(BaseFilter, BaseMiddleware): - """ - Middleware and filter class to check if a user is a member of required channels. - - This class combines the functionality of a filter and middleware to ensure that users - are members of specified channels before they can access certain bot features. - """ - - def __init__(self): - """ - Initializes the User_Check class. - - Parameters: - - None - - This constructor sets up the ADMIN variable from the configuration. - """ - self.ADMIN = ADMIN - - async def __call__(self, message: Message, call: CallbackQuery = None) -> bool: - """ - Checks if the user is a member of required channels. - - Parameters: - - message (Message): The incoming message object. This is used to obtain user information. - - call (CallbackQuery): The incoming callback query object. This is used if the message object is not available. - - Returns: - - bool: Returns True if the user is not a member of the required channels and False otherwise. - - This method: - - Reads the database to check if channel membership verification is required. - - If required, verifies the user's membership status in each specified channel. - - Logs errors if any exceptions occur during the check. - """ - try: - # Retrieve the channel membership check requirement from the database - data = DB.reading_db() - if data['join_channel']: - try: - # Try to get the user ID from the message object - user_id = message.from_user.id - except Exception as err: - # If message object is not available, use callback query object - user_id = call.from_user.id - logging.error(err) - - # If the user is not the admin, perform the channel check - if user_id != self.ADMIN: - force = False - result = db.select_channels() - for x in result: - try: - # Construct the chat ID for the channel - ids = str(-100) + str(x['channel_id']) - await bot.get_chat(ids) - try: - # Check the user's membership status in the channel - res = await bot.get_chat_member(chat_id=ids, user_id=user_id) - except: - # Continue if unable to retrieve chat member information - continue - # If the user is not a member, administrator, or creator, set force to True - if res.status == 'member' or res.status == 'administrator' or res.status == 'creator': - pass - else: - force = True - except Exception as err: - logging.error(err) - return force - else: - return False - else: - return False - except Exception as err: - logging.error(err) - - return False diff --git a/data/config.py b/data/config.py index 80fd7ce..f1ec830 100644 --- a/data/config.py +++ b/data/config.py @@ -28,4 +28,3 @@ date_day_month = (datetime.datetime.date(datetime.datetime.now())) time_hour_minute_second = f"{datas.hour}:{datas.minute}:{datas.second}" -FEATURES = ['translator', 'middlewares', 'save_log'] \ No newline at end of file diff --git a/function/translator.py b/function/translator.py index c7708e6..ffed8c6 100644 --- a/function/translator.py +++ b/function/translator.py @@ -20,6 +20,14 @@ def __init__(self, db: Database, self.default_src = default_src self.FM = FM + def __call__( + self, + text: str, + dest: Optional[str] = None, + src: Optional[str] = None, + ) -> str: + return self.translate(text, dest=dest, src=src) + def translate(self, text: str, dest: Optional[str] = 'en', diff --git a/loader.py b/loader.py index e4f8280..51eebb2 100755 --- a/loader.py +++ b/loader.py @@ -1,7 +1,7 @@ import logging from aiogram import Bot, Dispatcher, Router from aiogram.enums import ParseMode -from redis.asyncio import Redis +from redis import Redis from aiogram.fsm.storage.redis import RedisStorage from aiogram.client.bot import DefaultBotProperties # Yangi versiyadagi default sozlamalar uchun from data.config import * # Konfiguratsiyalarni import qilamiz @@ -20,15 +20,10 @@ log_format = '%(filename)s - %(funcName)s - %(lineno)d - %(name)s - %(levelname)s - %(message)s' formatter = logging.Formatter(log_format) - -FM = FeatureManager(db=db, root_logger=root_logger) - -for feature in FEATURES: - FM.feature(feature) - - redis = Redis(host="localhost", port=6379, db=0, decode_responses=True) +FM = FeatureManager(db=db, root_logger=root_logger, redis_client=redis) + # Botni token va default parametr orqali yaratamiz bot = Bot(token=BOT_TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML)) @@ -43,20 +38,10 @@ router = Router() -translator = Translator(db, FM=FM) +translator = Translator(db=db, FM=FM) -# middlewares -if FM.feature('middlewares'): - from middlewares.throttling import ThrottlingMiddleware - dp.update.middleware.register(ThrottlingMiddleware(db=db, bot=bot)) # Register the ThrottlingMiddleware -# save_log -if FM.feature('save_log'): - mysql_handler = MySQLHandler(bot=bot, connection=db.connection) - log_format = '%(filename)s - %(funcName)s - %(lineno)d - %(name)s - %(levelname)s - %(message)s' - formatter = logging.Formatter(log_format) - root_logger.addHandler(mysql_handler) diff --git a/main.py b/main.py index 1aae5f6..f4bc24b 100755 --- a/main.py +++ b/main.py @@ -17,14 +17,22 @@ async def main(): await set_default_commands() # Set the default commands for the bot try: - # Try to create necessary database tables - try: - mandatory_membership = db.select_setting('mandatory_membership') - if mandatory_membership is None: - db.insert_settings(initiator_user_id=1, key='mandatory_membership', value='False') - - except Exception as err: - logging.error(err) # Log any errors that occur during table creation + # middlewares + if FM.feature('middlewares'): + from middlewares.throttling import ThrottlingMiddleware + dp.update.middleware.register(ThrottlingMiddleware(db=db, bot=bot)) # Register the ThrottlingMiddleware + + + # save_log + if FM.feature('save_log'): + mysql_handler = MySQLHandler(bot=bot, connection=db.connection) + log_format = '%(filename)s - %(funcName)s - %(lineno)d - %(name)s - %(levelname)s - %(message)s' + formatter = logging.Formatter(log_format) + root_logger.addHandler(mysql_handler) + + mandatory_membership = db.select_setting('mandatory_membership') + if mandatory_membership is None: + db.insert_settings(initiator_user_id=1, key='mandatory_membership', value='False') # Delete any existing webhook and start polling await bot.delete_webhook(drop_pending_updates=True) diff --git a/pytest.ini b/pytest.ini deleted file mode 100644 index eb3b349..0000000 --- a/pytest.ini +++ /dev/null @@ -1,6 +0,0 @@ -[pytest] -asyncio_mode = auto -testpaths = tests -addopts = -ra -q --cov=. -markers = - integration: Slow tests with real Redis/MySQL diff --git a/requirements.txt b/requirements.txt index b52f65d..1a15a40 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,13 @@ -aiogram>=3.4 -redis>=5.0 -mysql-connector-python>=8.4 -python-dotenv>=1.0 -pytest>=8.2 -pytest-asyncio>=0.23 -pytest-cov>=5.0 -pytest-docker>=0.13 -pytest-mock>=3.14 -aioresponses>=0.7 +aiogram +redis +environs +mysql-connector-python +python-dotenv +pytest +pytest-asyncio +pytest-cov +pytest-docker +pytest-mock +aioresponses +deep_translator +pandas \ No newline at end of file diff --git a/setup.py b/setup.py index cd2cd68..9713eb7 100644 --- a/setup.py +++ b/setup.py @@ -2,6 +2,7 @@ import sys from getpass import getpass + REQUIRED = [ "BOT_TOKEN", "ADMIN", @@ -97,6 +98,16 @@ def main_setup() -> None: break cfg = prompt_for(REQUIRED, {}) + print("🔧 Configuration complete.") + + from loader import FM + + + FEATURES = ['translator', 'middlewares', 'save_log'] + for feature in FEATURES: + FM.feature(feature) + print("🔧 Features loaded.") + if __name__ == "__main__": try: From 4aaf537283a590710c791e399a03ac25949f8e0b Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Tue, 13 May 2025 20:17:08 +0500 Subject: [PATCH 39/71] feat: Implement inline keyboard buttons and callbacks for user interactions - Added MainCallback, AdminCallback, EditAdminSetting, AdminSetting, and BlockUser classes for handling callback queries. - Created close_btn function to generate a close button with error handling. - Developed send_url and share_audio functions for sharing URLs and audio content with inline keyboards. - Established loader.py for bot initialization, including database and Redis connections. - Implemented main.py for bot startup, command setting, and logging. - Introduced ThrottlingMiddleware to manage request rates and prevent abuse. - Defined AdminState for managing admin workflow states. - Created utility functions for notifying admins on startup and setting default bot commands. - Removed obsolete docker-compose.test.yml and test.py files. - Cleaned up logging files and test files related to feature manager. - Added pytest fixtures for Docker services setup in tests. --- {function => bot/api}/translator.py | 5 - bot/build/cython_code/file_db.c | 13448 ++++++++++++++ bot/build/cython_code/my_translator.c | 11536 ++++++++++++ bot/build/cython_code/send_ads.c | 14874 ++++++++++++++++ bot/build/cython_code/throttling_middleware.c | 12190 +++++++++++++ bot/build/cython_code/user_check.c | 12191 +++++++++++++ {core => bot/core}/feature_manager.py | 0 {data => bot/data}/config.py | 0 {db => bot/db}/database.py | 0 {filters => bot/filters}/admin.py | 0 {function => bot/function}/function.py | 0 {function => bot/function}/send_ads.py | 0 {handlers => bot/handlers}/__init__.py | 0 .../admins/admin_settings/add_admin.py | 2 +- .../admin_settings/add_admin_first_step.py | 2 +- .../admins/admin_settings/admin_setting.py | 2 +- .../admins/admin_settings/attach_admins.py | 2 +- .../admins/admin_settings/edit_admin.py | 2 +- .../admins/callback_query/main_admin_panel.py | 2 +- .../admins/channel_settings/add_channel.py | 2 +- .../channel_settings/channel_setting.py | 2 +- .../admins/channel_settings/delete_channel.py | 2 +- .../admins/channel_settings/get_id.py | 2 +- .../channel_settings/mandatory_membership.py | 2 +- .../admins/channel_settings/remove_channel.py | 2 +- .../handlers}/admins/check_usr/attach_usr.py | 2 +- .../handlers}/admins/check_usr/block_users.py | 2 +- .../handlers}/admins/check_usr/check_usr.py | 2 +- .../admins/check_usr/send_ads_message.py | 2 +- .../admins/check_usr/send_message.py | 2 +- .../handlers}/admins/main_panel.py | 2 +- .../handlers}/admins/send_ads/get_message.py | 2 +- .../handlers}/admins/send_ads/send_ads.py | 2 +- .../handlers}/admins/send_ads/stop_ads.py | 2 +- .../admins/statistika/download_statistics.py | 2 +- .../handlers}/admins/statistika/staristika.py | 2 +- .../handlers}/admins/super_admin.py | 0 .../handlers}/errors/error_handler.py | 0 .../handlers}/users/check_join.py | 2 +- {handlers => bot/handlers}/users/close.py | 0 {handlers => bot/handlers}/users/help.py | 2 +- {handlers => bot/handlers}/users/start.py | 13 +- .../keyboards}/inline/admin_btn.py | 145 +- {keyboards => bot/keyboards}/inline/button.py | 0 .../keyboards}/inline/close_btn.py | 0 {keyboards => bot/keyboards}/inline/user.py | 2 +- loader.py => bot/loader.py | 2 +- main.py => bot/main.py | 0 {middlewares => bot/middlewares}/__init__.py | 0 .../middlewares}/throttling.py | 2 +- {states => bot/states}/admin_state.py | 0 {utils => bot/utils}/notify_admins.py | 0 {utils => bot/utils}/set_bot_commands.py | 0 docker-compose.test.yml | 12 - logs/logging.log | 2 - test.py | 164 - test/feature_manager.py | 127 - test/integration/test_feature_manager_live.py | 27 - test/unit/test_feature_manager.py | 0 conftest.py => tests/conftest.py | 0 60 files changed, 64269 insertions(+), 521 deletions(-) rename {function => bot/api}/translator.py (96%) create mode 100644 bot/build/cython_code/file_db.c create mode 100644 bot/build/cython_code/my_translator.c create mode 100644 bot/build/cython_code/send_ads.c create mode 100644 bot/build/cython_code/throttling_middleware.c create mode 100644 bot/build/cython_code/user_check.c rename {core => bot/core}/feature_manager.py (100%) rename {data => bot/data}/config.py (100%) rename {db => bot/db}/database.py (100%) rename {filters => bot/filters}/admin.py (100%) rename {function => bot/function}/function.py (100%) rename {function => bot/function}/send_ads.py (100%) rename {handlers => bot/handlers}/__init__.py (100%) rename {handlers => bot/handlers}/admins/admin_settings/add_admin.py (99%) rename {handlers => bot/handlers}/admins/admin_settings/add_admin_first_step.py (98%) rename {handlers => bot/handlers}/admins/admin_settings/admin_setting.py (98%) rename {handlers => bot/handlers}/admins/admin_settings/attach_admins.py (99%) rename {handlers => bot/handlers}/admins/admin_settings/edit_admin.py (99%) rename {handlers => bot/handlers}/admins/callback_query/main_admin_panel.py (98%) rename {handlers => bot/handlers}/admins/channel_settings/add_channel.py (98%) rename {handlers => bot/handlers}/admins/channel_settings/channel_setting.py (99%) rename {handlers => bot/handlers}/admins/channel_settings/delete_channel.py (99%) rename {handlers => bot/handlers}/admins/channel_settings/get_id.py (99%) rename {handlers => bot/handlers}/admins/channel_settings/mandatory_membership.py (98%) rename {handlers => bot/handlers}/admins/channel_settings/remove_channel.py (99%) rename {handlers => bot/handlers}/admins/check_usr/attach_usr.py (99%) rename {handlers => bot/handlers}/admins/check_usr/block_users.py (99%) rename {handlers => bot/handlers}/admins/check_usr/check_usr.py (98%) rename {handlers => bot/handlers}/admins/check_usr/send_ads_message.py (98%) rename {handlers => bot/handlers}/admins/check_usr/send_message.py (98%) rename {handlers => bot/handlers}/admins/main_panel.py (98%) rename {handlers => bot/handlers}/admins/send_ads/get_message.py (99%) rename {handlers => bot/handlers}/admins/send_ads/send_ads.py (99%) rename {handlers => bot/handlers}/admins/send_ads/stop_ads.py (98%) rename {handlers => bot/handlers}/admins/statistika/download_statistics.py (98%) rename {handlers => bot/handlers}/admins/statistika/staristika.py (98%) rename {handlers => bot/handlers}/admins/super_admin.py (100%) rename {handlers => bot/handlers}/errors/error_handler.py (100%) rename {handlers => bot/handlers}/users/check_join.py (98%) rename {handlers => bot/handlers}/users/close.py (100%) rename {handlers => bot/handlers}/users/help.py (97%) rename {handlers => bot/handlers}/users/start.py (77%) rename {keyboards => bot/keyboards}/inline/admin_btn.py (68%) rename {keyboards => bot/keyboards}/inline/button.py (100%) rename {keyboards => bot/keyboards}/inline/close_btn.py (100%) rename {keyboards => bot/keyboards}/inline/user.py (97%) rename loader.py => bot/loader.py (96%) rename main.py => bot/main.py (100%) rename {middlewares => bot/middlewares}/__init__.py (100%) rename {middlewares => bot/middlewares}/throttling.py (99%) rename {states => bot/states}/admin_state.py (100%) rename {utils => bot/utils}/notify_admins.py (100%) rename {utils => bot/utils}/set_bot_commands.py (100%) delete mode 100644 docker-compose.test.yml delete mode 100644 logs/logging.log delete mode 100644 test.py delete mode 100644 test/feature_manager.py delete mode 100644 test/integration/test_feature_manager_live.py delete mode 100644 test/unit/test_feature_manager.py rename conftest.py => tests/conftest.py (100%) diff --git a/function/translator.py b/bot/api/translator.py similarity index 96% rename from function/translator.py rename to bot/api/translator.py index ffed8c6..5ea62eb 100644 --- a/function/translator.py +++ b/bot/api/translator.py @@ -5,11 +5,6 @@ from core.feature_manager import FeatureManager - -def translator(text: str, *args, **kwargs) -> str: - return text - - class Translator: def __init__(self, db: Database, FM: FeatureManager = None, diff --git a/bot/build/cython_code/file_db.c b/bot/build/cython_code/file_db.c new file mode 100644 index 0000000..a8a2199 --- /dev/null +++ b/bot/build/cython_code/file_db.c @@ -0,0 +1,13448 @@ +/* Generated by Cython 3.0.11 */ + +/* BEGIN: Cython Metadata +{ + "distutils": { + "name": "cython_code.file_db", + "sources": [ + "cython_code/file_db.pyx" + ] + }, + "module_name": "cython_code.file_db" +} +END: Cython Metadata */ + +#ifndef PY_SSIZE_T_CLEAN +#define PY_SSIZE_T_CLEAN +#endif /* PY_SSIZE_T_CLEAN */ +#if defined(CYTHON_LIMITED_API) && 0 + #ifndef Py_LIMITED_API + #if CYTHON_LIMITED_API+0 > 0x03030000 + #define Py_LIMITED_API CYTHON_LIMITED_API + #else + #define Py_LIMITED_API 0x03030000 + #endif + #endif +#endif + +#include "Python.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#elif PY_VERSION_HEX < 0x02070000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) + #error Cython requires Python 2.7+ or Python 3.3+. +#else +#if defined(CYTHON_LIMITED_API) && CYTHON_LIMITED_API +#define __PYX_EXTRA_ABI_MODULE_NAME "limited" +#else +#define __PYX_EXTRA_ABI_MODULE_NAME "" +#endif +#define CYTHON_ABI "3_0_11" __PYX_EXTRA_ABI_MODULE_NAME +#define __PYX_ABI_MODULE_NAME "_cython_" CYTHON_ABI +#define __PYX_TYPE_MODULE_PREFIX __PYX_ABI_MODULE_NAME "." +#define CYTHON_HEX_VERSION 0x03000BF0 +#define CYTHON_FUTURE_DIVISION 1 +#include +#ifndef offsetof + #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) +#endif +#if !defined(_WIN32) && !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#endif +#ifndef DL_IMPORT + #define DL_IMPORT(t) t +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif +#define __PYX_COMMA , +#ifndef HAVE_LONG_LONG + #define HAVE_LONG_LONG +#endif +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifndef Py_HUGE_VAL + #define Py_HUGE_VAL HUGE_VAL +#endif +#define __PYX_LIMITED_VERSION_HEX PY_VERSION_HEX +#if defined(GRAALVM_PYTHON) + /* For very preliminary testing purposes. Most variables are set the same as PyPy. + The existence of this section does not imply that anything works or is even tested */ + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 1 + #define CYTHON_COMPILING_IN_NOGIL 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #undef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS (PY_MAJOR_VERSION >= 3) + #endif + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #undef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #endif + #undef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 +#elif defined(PYPY_VERSION) + #define CYTHON_COMPILING_IN_PYPY 1 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #ifndef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #undef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS (PY_MAJOR_VERSION >= 3) + #endif + #if PY_VERSION_HEX < 0x03090000 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #elif !defined(CYTHON_PEP489_MULTI_PHASE_INIT) + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #undef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1 && PYPY_VERSION_NUM >= 0x07030C00) + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #endif + #undef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 +#elif defined(CYTHON_LIMITED_API) + #ifdef Py_LIMITED_API + #undef __PYX_LIMITED_VERSION_HEX + #define __PYX_LIMITED_VERSION_HEX Py_LIMITED_API + #endif + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 1 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 0 + #undef CYTHON_CLINE_IN_TRACEBACK + #define CYTHON_CLINE_IN_TRACEBACK 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 1 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #endif + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #undef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS 1 + #endif + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #undef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 1 + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #endif + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #endif + #undef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 +#elif defined(Py_GIL_DISABLED) || defined(Py_NOGIL) + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 1 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #ifndef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #ifndef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #ifndef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #ifndef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 1 + #endif + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS 1 + #endif + #ifndef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #ifndef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #endif + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 1 + #endif + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 1 + #endif + #ifndef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 + #endif +#else + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 1 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 0 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #ifndef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #endif + #ifndef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 1 + #endif + #if PY_MAJOR_VERSION < 3 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #ifndef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 1 + #endif + #ifndef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 1 + #endif + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #if PY_VERSION_HEX < 0x030300F0 || PY_VERSION_HEX >= 0x030B00A2 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #elif !defined(CYTHON_USE_UNICODE_WRITER) + #define CYTHON_USE_UNICODE_WRITER 1 + #endif + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #ifndef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 1 + #endif + #ifndef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL (PY_MAJOR_VERSION < 3 || PY_VERSION_HEX >= 0x03060000 && PY_VERSION_HEX < 0x030C00A6) + #endif + #ifndef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL (PY_VERSION_HEX >= 0x030700A1) + #endif + #ifndef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 1 + #endif + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS 1 + #endif + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #elif !defined(CYTHON_PEP489_MULTI_PHASE_INIT) + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #ifndef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #endif + #if PY_VERSION_HEX < 0x030400a1 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #elif !defined(CYTHON_USE_TP_FINALIZE) + #define CYTHON_USE_TP_FINALIZE 1 + #endif + #if PY_VERSION_HEX < 0x030600B1 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #elif !defined(CYTHON_USE_DICT_VERSIONS) + #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX < 0x030C00A5) + #endif + #if PY_VERSION_HEX < 0x030700A3 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #elif !defined(CYTHON_USE_EXC_INFO_STACK) + #define CYTHON_USE_EXC_INFO_STACK 1 + #endif + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 1 + #endif + #ifndef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 1 + #endif +#endif +#if !defined(CYTHON_FAST_PYCCALL) +#define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) +#endif +#if !defined(CYTHON_VECTORCALL) +#define CYTHON_VECTORCALL (CYTHON_FAST_PYCCALL && PY_VERSION_HEX >= 0x030800B1) +#endif +#define CYTHON_BACKPORT_VECTORCALL (CYTHON_METH_FASTCALL && PY_VERSION_HEX < 0x030800B1) +#if CYTHON_USE_PYLONG_INTERNALS + #if PY_MAJOR_VERSION < 3 + #include "longintrepr.h" + #endif + #undef SHIFT + #undef BASE + #undef MASK + #ifdef SIZEOF_VOID_P + enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; + #endif +#endif +#ifndef __has_attribute + #define __has_attribute(x) 0 +#endif +#ifndef __has_cpp_attribute + #define __has_cpp_attribute(x) 0 +#endif +#ifndef CYTHON_RESTRICT + #if defined(__GNUC__) + #define CYTHON_RESTRICT __restrict__ + #elif defined(_MSC_VER) && _MSC_VER >= 1400 + #define CYTHON_RESTRICT __restrict + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_RESTRICT restrict + #else + #define CYTHON_RESTRICT + #endif +#endif +#ifndef CYTHON_UNUSED + #if defined(__cplusplus) + /* for clang __has_cpp_attribute(maybe_unused) is true even before C++17 + * but leads to warnings with -pedantic, since it is a C++17 feature */ + #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) + #if __has_cpp_attribute(maybe_unused) + #define CYTHON_UNUSED [[maybe_unused]] + #endif + #endif + #endif +#endif +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_UNUSED_VAR +# if defined(__cplusplus) + template void CYTHON_UNUSED_VAR( const T& ) { } +# else +# define CYTHON_UNUSED_VAR(x) (void)(x) +# endif +#endif +#ifndef CYTHON_MAYBE_UNUSED_VAR + #define CYTHON_MAYBE_UNUSED_VAR(x) CYTHON_UNUSED_VAR(x) +#endif +#ifndef CYTHON_NCP_UNUSED +# if CYTHON_COMPILING_IN_CPYTHON +# define CYTHON_NCP_UNUSED +# else +# define CYTHON_NCP_UNUSED CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_USE_CPP_STD_MOVE + #if defined(__cplusplus) && (\ + __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600)) + #define CYTHON_USE_CPP_STD_MOVE 1 + #else + #define CYTHON_USE_CPP_STD_MOVE 0 + #endif +#endif +#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) +#ifdef _MSC_VER + #ifndef _MSC_STDINT_H_ + #if _MSC_VER < 1300 + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + typedef unsigned int uint32_t; + #else + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; + #endif + #endif + #if _MSC_VER < 1300 + #ifdef _WIN64 + typedef unsigned long long __pyx_uintptr_t; + #else + typedef unsigned int __pyx_uintptr_t; + #endif + #else + #ifdef _WIN64 + typedef unsigned __int64 __pyx_uintptr_t; + #else + typedef unsigned __int32 __pyx_uintptr_t; + #endif + #endif +#else + #include + typedef uintptr_t __pyx_uintptr_t; +#endif +#ifndef CYTHON_FALLTHROUGH + #if defined(__cplusplus) + /* for clang __has_cpp_attribute(fallthrough) is true even before C++17 + * but leads to warnings with -pedantic, since it is a C++17 feature */ + #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) + #if __has_cpp_attribute(fallthrough) + #define CYTHON_FALLTHROUGH [[fallthrough]] + #endif + #endif + #ifndef CYTHON_FALLTHROUGH + #if __has_cpp_attribute(clang::fallthrough) + #define CYTHON_FALLTHROUGH [[clang::fallthrough]] + #elif __has_cpp_attribute(gnu::fallthrough) + #define CYTHON_FALLTHROUGH [[gnu::fallthrough]] + #endif + #endif + #endif + #ifndef CYTHON_FALLTHROUGH + #if __has_attribute(fallthrough) + #define CYTHON_FALLTHROUGH __attribute__((fallthrough)) + #else + #define CYTHON_FALLTHROUGH + #endif + #endif + #if defined(__clang__) && defined(__apple_build_version__) + #if __apple_build_version__ < 7000000 + #undef CYTHON_FALLTHROUGH + #define CYTHON_FALLTHROUGH + #endif + #endif +#endif +#ifdef __cplusplus + template + struct __PYX_IS_UNSIGNED_IMPL {static const bool value = T(0) < T(-1);}; + #define __PYX_IS_UNSIGNED(type) (__PYX_IS_UNSIGNED_IMPL::value) +#else + #define __PYX_IS_UNSIGNED(type) (((type)-1) > 0) +#endif +#if CYTHON_COMPILING_IN_PYPY == 1 + #define __PYX_NEED_TP_PRINT_SLOT (PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x030A0000) +#else + #define __PYX_NEED_TP_PRINT_SLOT (PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000) +#endif +#define __PYX_REINTERPRET_FUNCION(func_pointer, other_pointer) ((func_pointer)(void(*)(void))(other_pointer)) + +#ifndef CYTHON_INLINE + #if defined(__clang__) + #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) + #elif defined(__GNUC__) + #define CYTHON_INLINE __inline__ + #elif defined(_MSC_VER) + #define CYTHON_INLINE __inline + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_INLINE inline + #else + #define CYTHON_INLINE + #endif +#endif + +#define __PYX_BUILD_PY_SSIZE_T "n" +#define CYTHON_FORMAT_SSIZE_T "z" +#if PY_MAJOR_VERSION < 3 + #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" + #define __Pyx_DefaultClassType PyClass_Type + #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #define __Pyx_BUILTIN_MODULE_NAME "builtins" + #define __Pyx_DefaultClassType PyType_Type +#if CYTHON_COMPILING_IN_LIMITED_API + static CYTHON_INLINE PyObject* __Pyx_PyCode_New(int a, int p, int k, int l, int s, int f, + PyObject *code, PyObject *c, PyObject* n, PyObject *v, + PyObject *fv, PyObject *cell, PyObject* fn, + PyObject *name, int fline, PyObject *lnos) { + PyObject *exception_table = NULL; + PyObject *types_module=NULL, *code_type=NULL, *result=NULL; + #if __PYX_LIMITED_VERSION_HEX < 0x030B0000 + PyObject *version_info; + PyObject *py_minor_version = NULL; + #endif + long minor_version = 0; + PyObject *type, *value, *traceback; + PyErr_Fetch(&type, &value, &traceback); + #if __PYX_LIMITED_VERSION_HEX >= 0x030B0000 + minor_version = 11; + #else + if (!(version_info = PySys_GetObject("version_info"))) goto end; + if (!(py_minor_version = PySequence_GetItem(version_info, 1))) goto end; + minor_version = PyLong_AsLong(py_minor_version); + Py_DECREF(py_minor_version); + if (minor_version == -1 && PyErr_Occurred()) goto end; + #endif + if (!(types_module = PyImport_ImportModule("types"))) goto end; + if (!(code_type = PyObject_GetAttrString(types_module, "CodeType"))) goto end; + if (minor_version <= 7) { + (void)p; + result = PyObject_CallFunction(code_type, "iiiiiOOOOOOiOO", a, k, l, s, f, code, + c, n, v, fn, name, fline, lnos, fv, cell); + } else if (minor_version <= 10) { + result = PyObject_CallFunction(code_type, "iiiiiiOOOOOOiOO", a,p, k, l, s, f, code, + c, n, v, fn, name, fline, lnos, fv, cell); + } else { + if (!(exception_table = PyBytes_FromStringAndSize(NULL, 0))) goto end; + result = PyObject_CallFunction(code_type, "iiiiiiOOOOOOOiOO", a,p, k, l, s, f, code, + c, n, v, fn, name, name, fline, lnos, exception_table, fv, cell); + } + end: + Py_XDECREF(code_type); + Py_XDECREF(exception_table); + Py_XDECREF(types_module); + if (type) { + PyErr_Restore(type, value, traceback); + } + return result; + } + #ifndef CO_OPTIMIZED + #define CO_OPTIMIZED 0x0001 + #endif + #ifndef CO_NEWLOCALS + #define CO_NEWLOCALS 0x0002 + #endif + #ifndef CO_VARARGS + #define CO_VARARGS 0x0004 + #endif + #ifndef CO_VARKEYWORDS + #define CO_VARKEYWORDS 0x0008 + #endif + #ifndef CO_ASYNC_GENERATOR + #define CO_ASYNC_GENERATOR 0x0200 + #endif + #ifndef CO_GENERATOR + #define CO_GENERATOR 0x0020 + #endif + #ifndef CO_COROUTINE + #define CO_COROUTINE 0x0080 + #endif +#elif PY_VERSION_HEX >= 0x030B0000 + static CYTHON_INLINE PyCodeObject* __Pyx_PyCode_New(int a, int p, int k, int l, int s, int f, + PyObject *code, PyObject *c, PyObject* n, PyObject *v, + PyObject *fv, PyObject *cell, PyObject* fn, + PyObject *name, int fline, PyObject *lnos) { + PyCodeObject *result; + PyObject *empty_bytes = PyBytes_FromStringAndSize("", 0); + if (!empty_bytes) return NULL; + result = + #if PY_VERSION_HEX >= 0x030C0000 + PyUnstable_Code_NewWithPosOnlyArgs + #else + PyCode_NewWithPosOnlyArgs + #endif + (a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, name, fline, lnos, empty_bytes); + Py_DECREF(empty_bytes); + return result; + } +#elif PY_VERSION_HEX >= 0x030800B2 && !CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_NewWithPosOnlyArgs(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#endif +#endif +#if PY_VERSION_HEX >= 0x030900A4 || defined(Py_IS_TYPE) + #define __Pyx_IS_TYPE(ob, type) Py_IS_TYPE(ob, type) +#else + #define __Pyx_IS_TYPE(ob, type) (((const PyObject*)ob)->ob_type == (type)) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_Is) + #define __Pyx_Py_Is(x, y) Py_Is(x, y) +#else + #define __Pyx_Py_Is(x, y) ((x) == (y)) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsNone) + #define __Pyx_Py_IsNone(ob) Py_IsNone(ob) +#else + #define __Pyx_Py_IsNone(ob) __Pyx_Py_Is((ob), Py_None) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsTrue) + #define __Pyx_Py_IsTrue(ob) Py_IsTrue(ob) +#else + #define __Pyx_Py_IsTrue(ob) __Pyx_Py_Is((ob), Py_True) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsFalse) + #define __Pyx_Py_IsFalse(ob) Py_IsFalse(ob) +#else + #define __Pyx_Py_IsFalse(ob) __Pyx_Py_Is((ob), Py_False) +#endif +#define __Pyx_NoneAsNull(obj) (__Pyx_Py_IsNone(obj) ? NULL : (obj)) +#if PY_VERSION_HEX >= 0x030900F0 && !CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyObject_GC_IsFinalized(o) PyObject_GC_IsFinalized(o) +#else + #define __Pyx_PyObject_GC_IsFinalized(o) _PyGC_FINALIZED(o) +#endif +#ifndef CO_COROUTINE + #define CO_COROUTINE 0x80 +#endif +#ifndef CO_ASYNC_GENERATOR + #define CO_ASYNC_GENERATOR 0x200 +#endif +#ifndef Py_TPFLAGS_CHECKTYPES + #define Py_TPFLAGS_CHECKTYPES 0 +#endif +#ifndef Py_TPFLAGS_HAVE_INDEX + #define Py_TPFLAGS_HAVE_INDEX 0 +#endif +#ifndef Py_TPFLAGS_HAVE_NEWBUFFER + #define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif +#ifndef Py_TPFLAGS_HAVE_FINALIZE + #define Py_TPFLAGS_HAVE_FINALIZE 0 +#endif +#ifndef Py_TPFLAGS_SEQUENCE + #define Py_TPFLAGS_SEQUENCE 0 +#endif +#ifndef Py_TPFLAGS_MAPPING + #define Py_TPFLAGS_MAPPING 0 +#endif +#ifndef METH_STACKLESS + #define METH_STACKLESS 0 +#endif +#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL) + #ifndef METH_FASTCALL + #define METH_FASTCALL 0x80 + #endif + typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs); + typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args, + Py_ssize_t nargs, PyObject *kwnames); +#else + #if PY_VERSION_HEX >= 0x030d00A4 + # define __Pyx_PyCFunctionFast PyCFunctionFast + # define __Pyx_PyCFunctionFastWithKeywords PyCFunctionFastWithKeywords + #else + # define __Pyx_PyCFunctionFast _PyCFunctionFast + # define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords + #endif +#endif +#if CYTHON_METH_FASTCALL + #define __Pyx_METH_FASTCALL METH_FASTCALL + #define __Pyx_PyCFunction_FastCall __Pyx_PyCFunctionFast + #define __Pyx_PyCFunction_FastCallWithKeywords __Pyx_PyCFunctionFastWithKeywords +#else + #define __Pyx_METH_FASTCALL METH_VARARGS + #define __Pyx_PyCFunction_FastCall PyCFunction + #define __Pyx_PyCFunction_FastCallWithKeywords PyCFunctionWithKeywords +#endif +#if CYTHON_VECTORCALL + #define __pyx_vectorcallfunc vectorcallfunc + #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET PY_VECTORCALL_ARGUMENTS_OFFSET + #define __Pyx_PyVectorcall_NARGS(n) PyVectorcall_NARGS((size_t)(n)) +#elif CYTHON_BACKPORT_VECTORCALL + typedef PyObject *(*__pyx_vectorcallfunc)(PyObject *callable, PyObject *const *args, + size_t nargsf, PyObject *kwnames); + #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET ((size_t)1 << (8 * sizeof(size_t) - 1)) + #define __Pyx_PyVectorcall_NARGS(n) ((Py_ssize_t)(((size_t)(n)) & ~__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)) +#else + #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET 0 + #define __Pyx_PyVectorcall_NARGS(n) ((Py_ssize_t)(n)) +#endif +#if PY_MAJOR_VERSION >= 0x030900B1 +#define __Pyx_PyCFunction_CheckExact(func) PyCFunction_CheckExact(func) +#else +#define __Pyx_PyCFunction_CheckExact(func) PyCFunction_Check(func) +#endif +#define __Pyx_CyOrPyCFunction_Check(func) PyCFunction_Check(func) +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_CyOrPyCFunction_GET_FUNCTION(func) (((PyCFunctionObject*)(func))->m_ml->ml_meth) +#elif !CYTHON_COMPILING_IN_LIMITED_API +#define __Pyx_CyOrPyCFunction_GET_FUNCTION(func) PyCFunction_GET_FUNCTION(func) +#endif +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_CyOrPyCFunction_GET_FLAGS(func) (((PyCFunctionObject*)(func))->m_ml->ml_flags) +static CYTHON_INLINE PyObject* __Pyx_CyOrPyCFunction_GET_SELF(PyObject *func) { + return (__Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_STATIC) ? NULL : ((PyCFunctionObject*)func)->m_self; +} +#endif +static CYTHON_INLINE int __Pyx__IsSameCFunction(PyObject *func, void *cfunc) { +#if CYTHON_COMPILING_IN_LIMITED_API + return PyCFunction_Check(func) && PyCFunction_GetFunction(func) == (PyCFunction) cfunc; +#else + return PyCFunction_Check(func) && PyCFunction_GET_FUNCTION(func) == (PyCFunction) cfunc; +#endif +} +#define __Pyx_IsSameCFunction(func, cfunc) __Pyx__IsSameCFunction(func, cfunc) +#if __PYX_LIMITED_VERSION_HEX < 0x030900B1 + #define __Pyx_PyType_FromModuleAndSpec(m, s, b) ((void)m, PyType_FromSpecWithBases(s, b)) + typedef PyObject *(*__Pyx_PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *, size_t, PyObject *); +#else + #define __Pyx_PyType_FromModuleAndSpec(m, s, b) PyType_FromModuleAndSpec(m, s, b) + #define __Pyx_PyCMethod PyCMethod +#endif +#ifndef METH_METHOD + #define METH_METHOD 0x200 +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) + #define PyObject_Malloc(s) PyMem_Malloc(s) + #define PyObject_Free(p) PyMem_Free(p) + #define PyObject_Realloc(p) PyMem_Realloc(p) +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) +#else + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_PyThreadState_Current PyThreadState_Get() +#elif !CYTHON_FAST_THREAD_STATE + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#elif PY_VERSION_HEX >= 0x030d00A1 + #define __Pyx_PyThreadState_Current PyThreadState_GetUnchecked() +#elif PY_VERSION_HEX >= 0x03060000 + #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet() +#elif PY_VERSION_HEX >= 0x03000000 + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#else + #define __Pyx_PyThreadState_Current _PyThreadState_Current +#endif +#if CYTHON_COMPILING_IN_LIMITED_API +static CYTHON_INLINE void *__Pyx_PyModule_GetState(PyObject *op) +{ + void *result; + result = PyModule_GetState(op); + if (!result) + Py_FatalError("Couldn't find the module state"); + return result; +} +#endif +#define __Pyx_PyObject_GetSlot(obj, name, func_ctype) __Pyx_PyType_GetSlot(Py_TYPE(obj), name, func_ctype) +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_PyType_GetSlot(type, name, func_ctype) ((func_ctype) PyType_GetSlot((type), Py_##name)) +#else + #define __Pyx_PyType_GetSlot(type, name, func_ctype) ((type)->name) +#endif +#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT) +#include "pythread.h" +#define Py_tss_NEEDS_INIT 0 +typedef int Py_tss_t; +static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) { + *key = PyThread_create_key(); + return 0; +} +static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) { + Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t)); + *key = Py_tss_NEEDS_INIT; + return key; +} +static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) { + PyObject_Free(key); +} +static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) { + return *key != Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) { + PyThread_delete_key(*key); + *key = Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) { + return PyThread_set_key_value(*key, value); +} +static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { + return PyThread_get_key_value(*key); +} +#endif +#if PY_MAJOR_VERSION < 3 + #if CYTHON_COMPILING_IN_PYPY + #if PYPY_VERSION_NUM < 0x07030600 + #if defined(__cplusplus) && __cplusplus >= 201402L + [[deprecated("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6")]] + #elif defined(__GNUC__) || defined(__clang__) + __attribute__ ((__deprecated__("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6"))) + #elif defined(_MSC_VER) + __declspec(deprecated("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6")) + #endif + static CYTHON_INLINE int PyGILState_Check(void) { + return 0; + } + #else // PYPY_VERSION_NUM < 0x07030600 + #endif // PYPY_VERSION_NUM < 0x07030600 + #else + static CYTHON_INLINE int PyGILState_Check(void) { + PyThreadState * tstate = _PyThreadState_Current; + return tstate && (tstate == PyGILState_GetThisThreadState()); + } + #endif +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000 || defined(_PyDict_NewPresized) +#define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n)) +#else +#define __Pyx_PyDict_NewPresized(n) PyDict_New() +#endif +#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX > 0x030600B4 && PY_VERSION_HEX < 0x030d0000 && CYTHON_USE_UNICODE_INTERNALS +#define __Pyx_PyDict_GetItemStrWithError(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash) +static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStr(PyObject *dict, PyObject *name) { + PyObject *res = __Pyx_PyDict_GetItemStrWithError(dict, name); + if (res == NULL) PyErr_Clear(); + return res; +} +#elif PY_MAJOR_VERSION >= 3 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07020000) +#define __Pyx_PyDict_GetItemStrWithError PyDict_GetItemWithError +#define __Pyx_PyDict_GetItemStr PyDict_GetItem +#else +static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict, PyObject *name) { +#if CYTHON_COMPILING_IN_PYPY + return PyDict_GetItem(dict, name); +#else + PyDictEntry *ep; + PyDictObject *mp = (PyDictObject*) dict; + long hash = ((PyStringObject *) name)->ob_shash; + assert(hash != -1); + ep = (mp->ma_lookup)(mp, name, hash); + if (ep == NULL) { + return NULL; + } + return ep->me_value; +#endif +} +#define __Pyx_PyDict_GetItemStr PyDict_GetItem +#endif +#if CYTHON_USE_TYPE_SLOTS + #define __Pyx_PyType_GetFlags(tp) (((PyTypeObject *)tp)->tp_flags) + #define __Pyx_PyType_HasFeature(type, feature) ((__Pyx_PyType_GetFlags(type) & (feature)) != 0) + #define __Pyx_PyObject_GetIterNextFunc(obj) (Py_TYPE(obj)->tp_iternext) +#else + #define __Pyx_PyType_GetFlags(tp) (PyType_GetFlags((PyTypeObject *)tp)) + #define __Pyx_PyType_HasFeature(type, feature) PyType_HasFeature(type, feature) + #define __Pyx_PyObject_GetIterNextFunc(obj) PyIter_Next +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_SetItemOnTypeDict(tp, k, v) PyObject_GenericSetAttr((PyObject*)tp, k, v) +#else + #define __Pyx_SetItemOnTypeDict(tp, k, v) PyDict_SetItem(tp->tp_dict, k, v) +#endif +#if CYTHON_USE_TYPE_SPECS && PY_VERSION_HEX >= 0x03080000 +#define __Pyx_PyHeapTypeObject_GC_Del(obj) {\ + PyTypeObject *type = Py_TYPE((PyObject*)obj);\ + assert(__Pyx_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE));\ + PyObject_GC_Del(obj);\ + Py_DECREF(type);\ +} +#else +#define __Pyx_PyHeapTypeObject_GC_Del(obj) PyObject_GC_Del(obj) +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define CYTHON_PEP393_ENABLED 1 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GetLength(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_ReadChar(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((void)u, 1114111U) + #define __Pyx_PyUnicode_KIND(u) ((void)u, (0)) + #define __Pyx_PyUnicode_DATA(u) ((void*)u) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)k, PyUnicode_ReadChar((PyObject*)(d), i)) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GetLength(u)) +#elif PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) + #define CYTHON_PEP393_ENABLED 1 + #if PY_VERSION_HEX >= 0x030C0000 + #define __Pyx_PyUnicode_READY(op) (0) + #else + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ + 0 : _PyUnicode_Ready((PyObject *)(op))) + #endif + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) + #define __Pyx_PyUnicode_KIND(u) ((int)PyUnicode_KIND(u)) + #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) + #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, (Py_UCS4) ch) + #if PY_VERSION_HEX >= 0x030C0000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) + #else + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length)) + #else + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) + #endif + #endif +#else + #define CYTHON_PEP393_ENABLED 0 + #define PyUnicode_1BYTE_KIND 1 + #define PyUnicode_2BYTE_KIND 2 + #define PyUnicode_4BYTE_KIND 4 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535U : 1114111U) + #define __Pyx_PyUnicode_KIND(u) ((int)sizeof(Py_UNICODE)) + #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = (Py_UNICODE) ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) +#endif +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) +#else + #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ + PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) +#endif +#if CYTHON_COMPILING_IN_PYPY + #if !defined(PyUnicode_DecodeUnicodeEscape) + #define PyUnicode_DecodeUnicodeEscape(s, size, errors) PyUnicode_Decode(s, size, "unicode_escape", errors) + #endif + #if !defined(PyUnicode_Contains) || (PY_MAJOR_VERSION == 2 && PYPY_VERSION_NUM < 0x07030500) + #undef PyUnicode_Contains + #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) + #endif + #if !defined(PyByteArray_Check) + #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) + #endif + #if !defined(PyObject_Format) + #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) + #endif +#endif +#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) +#else + #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) +#endif +#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) + #define PyObject_ASCII(o) PyObject_Repr(o) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBaseString_Type PyUnicode_Type + #define PyStringObject PyUnicodeObject + #define PyString_Type PyUnicode_Type + #define PyString_Check PyUnicode_Check + #define PyString_CheckExact PyUnicode_CheckExact +#ifndef PyObject_Unicode + #define PyObject_Unicode PyObject_Str +#endif +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) + #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) +#else + #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) + #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) +#endif +#if CYTHON_COMPILING_IN_CPYTHON + #define __Pyx_PySequence_ListKeepNew(obj)\ + (likely(PyList_CheckExact(obj) && Py_REFCNT(obj) == 1) ? __Pyx_NewRef(obj) : PySequence_List(obj)) +#else + #define __Pyx_PySequence_ListKeepNew(obj) PySequence_List(obj) +#endif +#ifndef PySet_CheckExact + #define PySet_CheckExact(obj) __Pyx_IS_TYPE(obj, &PySet_Type) +#endif +#if PY_VERSION_HEX >= 0x030900A4 + #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) +#else + #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) +#endif +#if CYTHON_ASSUME_SAFE_MACROS + #define __Pyx_PySequence_ITEM(o, i) PySequence_ITEM(o, i) + #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq) + #define __Pyx_PyTuple_SET_ITEM(o, i, v) (PyTuple_SET_ITEM(o, i, v), (0)) + #define __Pyx_PyList_SET_ITEM(o, i, v) (PyList_SET_ITEM(o, i, v), (0)) + #define __Pyx_PyTuple_GET_SIZE(o) PyTuple_GET_SIZE(o) + #define __Pyx_PyList_GET_SIZE(o) PyList_GET_SIZE(o) + #define __Pyx_PySet_GET_SIZE(o) PySet_GET_SIZE(o) + #define __Pyx_PyBytes_GET_SIZE(o) PyBytes_GET_SIZE(o) + #define __Pyx_PyByteArray_GET_SIZE(o) PyByteArray_GET_SIZE(o) +#else + #define __Pyx_PySequence_ITEM(o, i) PySequence_GetItem(o, i) + #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq) + #define __Pyx_PyTuple_SET_ITEM(o, i, v) PyTuple_SetItem(o, i, v) + #define __Pyx_PyList_SET_ITEM(o, i, v) PyList_SetItem(o, i, v) + #define __Pyx_PyTuple_GET_SIZE(o) PyTuple_Size(o) + #define __Pyx_PyList_GET_SIZE(o) PyList_Size(o) + #define __Pyx_PySet_GET_SIZE(o) PySet_Size(o) + #define __Pyx_PyBytes_GET_SIZE(o) PyBytes_Size(o) + #define __Pyx_PyByteArray_GET_SIZE(o) PyByteArray_Size(o) +#endif +#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1 + #define __Pyx_PyImport_AddModuleRef(name) PyImport_AddModuleRef(name) +#else + static CYTHON_INLINE PyObject *__Pyx_PyImport_AddModuleRef(const char *name) { + PyObject *module = PyImport_AddModule(name); + Py_XINCREF(module); + return module; + } +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyIntObject PyLongObject + #define PyInt_Type PyLong_Type + #define PyInt_Check(op) PyLong_Check(op) + #define PyInt_CheckExact(op) PyLong_CheckExact(op) + #define __Pyx_Py3Int_Check(op) PyLong_Check(op) + #define __Pyx_Py3Int_CheckExact(op) PyLong_CheckExact(op) + #define PyInt_FromString PyLong_FromString + #define PyInt_FromUnicode PyLong_FromUnicode + #define PyInt_FromLong PyLong_FromLong + #define PyInt_FromSize_t PyLong_FromSize_t + #define PyInt_FromSsize_t PyLong_FromSsize_t + #define PyInt_AsLong PyLong_AsLong + #define PyInt_AS_LONG PyLong_AS_LONG + #define PyInt_AsSsize_t PyLong_AsSsize_t + #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask + #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask + #define PyNumber_Int PyNumber_Long +#else + #define __Pyx_Py3Int_Check(op) (PyLong_Check(op) || PyInt_Check(op)) + #define __Pyx_Py3Int_CheckExact(op) (PyLong_CheckExact(op) || PyInt_CheckExact(op)) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBoolObject PyLongObject +#endif +#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY + #ifndef PyUnicode_InternFromString + #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) + #endif +#endif +#if PY_VERSION_HEX < 0x030200A4 + typedef long Py_hash_t; + #define __Pyx_PyInt_FromHash_t PyInt_FromLong + #define __Pyx_PyInt_AsHash_t __Pyx_PyIndex_AsHash_t +#else + #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t + #define __Pyx_PyInt_AsHash_t __Pyx_PyIndex_AsSsize_t +#endif +#if CYTHON_USE_ASYNC_SLOTS + #if PY_VERSION_HEX >= 0x030500B1 + #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods + #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) + #else + #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) + #endif +#else + #define __Pyx_PyType_AsAsync(obj) NULL +#endif +#ifndef __Pyx_PyAsyncMethodsStruct + typedef struct { + unaryfunc am_await; + unaryfunc am_aiter; + unaryfunc am_anext; + } __Pyx_PyAsyncMethodsStruct; +#endif + +#if defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS) + #if !defined(_USE_MATH_DEFINES) + #define _USE_MATH_DEFINES + #endif +#endif +#include +#ifdef NAN +#define __PYX_NAN() ((float) NAN) +#else +static CYTHON_INLINE float __PYX_NAN() { + float value; + memset(&value, 0xFF, sizeof(value)); + return value; +} +#endif +#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) +#define __Pyx_truncl trunc +#else +#define __Pyx_truncl truncl +#endif + +#define __PYX_MARK_ERR_POS(f_index, lineno) \ + { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } +#define __PYX_ERR(f_index, lineno, Ln_error) \ + { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; } + +#ifdef CYTHON_EXTERN_C + #undef __PYX_EXTERN_C + #define __PYX_EXTERN_C CYTHON_EXTERN_C +#elif defined(__PYX_EXTERN_C) + #ifdef _MSC_VER + #pragma message ("Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.") + #else + #warning Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead. + #endif +#else + #ifdef __cplusplus + #define __PYX_EXTERN_C extern "C" + #else + #define __PYX_EXTERN_C extern + #endif +#endif + +#define __PYX_HAVE__cython_code__file_db +#define __PYX_HAVE_API__cython_code__file_db +/* Early includes */ +#ifdef _OPENMP +#include +#endif /* _OPENMP */ + +#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS) +#define CYTHON_WITHOUT_ASSERTIONS +#endif + +typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; + const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; + +#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) +#define __PYX_DEFAULT_STRING_ENCODING "" +#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString +#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#define __Pyx_uchar_cast(c) ((unsigned char)c) +#define __Pyx_long_cast(x) ((long)x) +#define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ + (sizeof(type) < sizeof(Py_ssize_t)) ||\ + (sizeof(type) > sizeof(Py_ssize_t) &&\ + likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX) &&\ + (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ + v == (type)PY_SSIZE_T_MIN))) ||\ + (sizeof(type) == sizeof(Py_ssize_t) &&\ + (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX))) ) +static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { + return (size_t) i < (size_t) limit; +} +#if defined (__cplusplus) && __cplusplus >= 201103L + #include + #define __Pyx_sst_abs(value) std::abs(value) +#elif SIZEOF_INT >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) abs(value) +#elif SIZEOF_LONG >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) labs(value) +#elif defined (_MSC_VER) + #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value)) +#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define __Pyx_sst_abs(value) llabs(value) +#elif defined (__GNUC__) + #define __Pyx_sst_abs(value) __builtin_llabs(value) +#else + #define __Pyx_sst_abs(value) ((value<0) ? -value : value) +#endif +static CYTHON_INLINE Py_ssize_t __Pyx_ssize_strlen(const char *s); +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*); +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); +static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char*); +#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) +#define __Pyx_PyBytes_FromString PyBytes_FromString +#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); +#if PY_MAJOR_VERSION < 3 + #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#else + #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize +#endif +#define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyObject_AsWritableString(s) ((char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableSString(s) ((signed char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) +#define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) +#define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) +#define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) +#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) +#define __Pyx_PyUnicode_FromOrdinal(o) PyUnicode_FromOrdinal((int)o) +#define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode +#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) +#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b); +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*); +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); +#define __Pyx_PySequence_Tuple(obj)\ + (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj)) +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*); +#if CYTHON_ASSUME_SAFE_MACROS +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) +#else +#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) +#endif +#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) +#else +#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) +#endif +#if CYTHON_USE_PYLONG_INTERNALS + #if PY_VERSION_HEX >= 0x030C00A7 + #ifndef _PyLong_SIGN_MASK + #define _PyLong_SIGN_MASK 3 + #endif + #ifndef _PyLong_NON_SIZE_BITS + #define _PyLong_NON_SIZE_BITS 3 + #endif + #define __Pyx_PyLong_Sign(x) (((PyLongObject*)x)->long_value.lv_tag & _PyLong_SIGN_MASK) + #define __Pyx_PyLong_IsNeg(x) ((__Pyx_PyLong_Sign(x) & 2) != 0) + #define __Pyx_PyLong_IsNonNeg(x) (!__Pyx_PyLong_IsNeg(x)) + #define __Pyx_PyLong_IsZero(x) (__Pyx_PyLong_Sign(x) & 1) + #define __Pyx_PyLong_IsPos(x) (__Pyx_PyLong_Sign(x) == 0) + #define __Pyx_PyLong_CompactValueUnsigned(x) (__Pyx_PyLong_Digits(x)[0]) + #define __Pyx_PyLong_DigitCount(x) ((Py_ssize_t) (((PyLongObject*)x)->long_value.lv_tag >> _PyLong_NON_SIZE_BITS)) + #define __Pyx_PyLong_SignedDigitCount(x)\ + ((1 - (Py_ssize_t) __Pyx_PyLong_Sign(x)) * __Pyx_PyLong_DigitCount(x)) + #if defined(PyUnstable_Long_IsCompact) && defined(PyUnstable_Long_CompactValue) + #define __Pyx_PyLong_IsCompact(x) PyUnstable_Long_IsCompact((PyLongObject*) x) + #define __Pyx_PyLong_CompactValue(x) PyUnstable_Long_CompactValue((PyLongObject*) x) + #else + #define __Pyx_PyLong_IsCompact(x) (((PyLongObject*)x)->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS)) + #define __Pyx_PyLong_CompactValue(x) ((1 - (Py_ssize_t) __Pyx_PyLong_Sign(x)) * (Py_ssize_t) __Pyx_PyLong_Digits(x)[0]) + #endif + typedef Py_ssize_t __Pyx_compact_pylong; + typedef size_t __Pyx_compact_upylong; + #else + #define __Pyx_PyLong_IsNeg(x) (Py_SIZE(x) < 0) + #define __Pyx_PyLong_IsNonNeg(x) (Py_SIZE(x) >= 0) + #define __Pyx_PyLong_IsZero(x) (Py_SIZE(x) == 0) + #define __Pyx_PyLong_IsPos(x) (Py_SIZE(x) > 0) + #define __Pyx_PyLong_CompactValueUnsigned(x) ((Py_SIZE(x) == 0) ? 0 : __Pyx_PyLong_Digits(x)[0]) + #define __Pyx_PyLong_DigitCount(x) __Pyx_sst_abs(Py_SIZE(x)) + #define __Pyx_PyLong_SignedDigitCount(x) Py_SIZE(x) + #define __Pyx_PyLong_IsCompact(x) (Py_SIZE(x) == 0 || Py_SIZE(x) == 1 || Py_SIZE(x) == -1) + #define __Pyx_PyLong_CompactValue(x)\ + ((Py_SIZE(x) == 0) ? (sdigit) 0 : ((Py_SIZE(x) < 0) ? -(sdigit)__Pyx_PyLong_Digits(x)[0] : (sdigit)__Pyx_PyLong_Digits(x)[0])) + typedef sdigit __Pyx_compact_pylong; + typedef digit __Pyx_compact_upylong; + #endif + #if PY_VERSION_HEX >= 0x030C00A5 + #define __Pyx_PyLong_Digits(x) (((PyLongObject*)x)->long_value.ob_digit) + #else + #define __Pyx_PyLong_Digits(x) (((PyLongObject*)x)->ob_digit) + #endif +#endif +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII +#include +static int __Pyx_sys_getdefaultencoding_not_ascii; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + PyObject* ascii_chars_u = NULL; + PyObject* ascii_chars_b = NULL; + const char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + if (strcmp(default_encoding_c, "ascii") == 0) { + __Pyx_sys_getdefaultencoding_not_ascii = 0; + } else { + char ascii_chars[128]; + int c; + for (c = 0; c < 128; c++) { + ascii_chars[c] = (char) c; + } + __Pyx_sys_getdefaultencoding_not_ascii = 1; + ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); + if (!ascii_chars_u) goto bad; + ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); + if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { + PyErr_Format( + PyExc_ValueError, + "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", + default_encoding_c); + goto bad; + } + Py_DECREF(ascii_chars_u); + Py_DECREF(ascii_chars_b); + } + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + Py_XDECREF(ascii_chars_u); + Py_XDECREF(ascii_chars_b); + return -1; +} +#endif +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) +#else +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +#include +static char* __PYX_DEFAULT_STRING_ENCODING; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1); + if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; + strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + return -1; +} +#endif +#endif + + +/* Test for GCC > 2.95 */ +#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) +#else /* !__GNUC__ or GCC < 2.95 */ + #define likely(x) (x) + #define unlikely(x) (x) +#endif /* __GNUC__ */ +static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; } + +#if !CYTHON_USE_MODULE_STATE +static PyObject *__pyx_m = NULL; +#endif +static int __pyx_lineno; +static int __pyx_clineno = 0; +static const char * __pyx_cfilenm = __FILE__; +static const char *__pyx_filename; + +/* #### Code section: filename_table ### */ + +static const char *__pyx_f[] = { + "cython_code/file_db.pyx", + "", +}; +/* #### Code section: utility_code_proto_before_types ### */ +/* ForceInitThreads.proto */ +#ifndef __PYX_FORCE_INIT_THREADS + #define __PYX_FORCE_INIT_THREADS 0 +#endif + +/* #### Code section: numeric_typedefs ### */ +/* #### Code section: complex_type_declarations ### */ +/* #### Code section: type_declarations ### */ + +/*--- Type declarations ---*/ +struct __pyx_obj_11cython_code_7file_db_BotDb; +struct __pyx_obj_11cython_code_7file_db_FileDB; + +/* "cython_code/file_db.pyx":7 + * from cython cimport bint, dict + * + * cdef class BotDb: # <<<<<<<<<<<<<< + * cdef str file + * cdef dict json_data + */ +struct __pyx_obj_11cython_code_7file_db_BotDb { + PyObject_HEAD + PyObject *file; + PyObject *json_data; +}; + + +/* "cython_code/file_db.pyx":34 + * json.dump(self.json_data, json_file) + * + * cdef class FileDB: # <<<<<<<<<<<<<< + * cdef str file + * cdef dict json_data + */ +struct __pyx_obj_11cython_code_7file_db_FileDB { + PyObject_HEAD + PyObject *file; + PyObject *json_data; +}; + +/* #### Code section: utility_code_proto ### */ + +/* --- Runtime support code (head) --- */ +/* Refnanny.proto */ +#ifndef CYTHON_REFNANNY + #define CYTHON_REFNANNY 0 +#endif +#if CYTHON_REFNANNY + typedef struct { + void (*INCREF)(void*, PyObject*, Py_ssize_t); + void (*DECREF)(void*, PyObject*, Py_ssize_t); + void (*GOTREF)(void*, PyObject*, Py_ssize_t); + void (*GIVEREF)(void*, PyObject*, Py_ssize_t); + void* (*SetupContext)(const char*, Py_ssize_t, const char*); + void (*FinishContext)(void**); + } __Pyx_RefNannyAPIStruct; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); + #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; +#ifdef WITH_THREAD + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + if (acquire_gil) {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__));\ + PyGILState_Release(__pyx_gilstate_save);\ + } else {\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__));\ + } + #define __Pyx_RefNannyFinishContextNogil() {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __Pyx_RefNannyFinishContext();\ + PyGILState_Release(__pyx_gilstate_save);\ + } +#else + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__)) + #define __Pyx_RefNannyFinishContextNogil() __Pyx_RefNannyFinishContext() +#endif + #define __Pyx_RefNannyFinishContextNogil() {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __Pyx_RefNannyFinishContext();\ + PyGILState_Release(__pyx_gilstate_save);\ + } + #define __Pyx_RefNannyFinishContext()\ + __Pyx_RefNanny->FinishContext(&__pyx_refnanny) + #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_XINCREF(r) do { if((r) == NULL); else {__Pyx_INCREF(r); }} while(0) + #define __Pyx_XDECREF(r) do { if((r) == NULL); else {__Pyx_DECREF(r); }} while(0) + #define __Pyx_XGOTREF(r) do { if((r) == NULL); else {__Pyx_GOTREF(r); }} while(0) + #define __Pyx_XGIVEREF(r) do { if((r) == NULL); else {__Pyx_GIVEREF(r);}} while(0) +#else + #define __Pyx_RefNannyDeclarations + #define __Pyx_RefNannySetupContext(name, acquire_gil) + #define __Pyx_RefNannyFinishContextNogil() + #define __Pyx_RefNannyFinishContext() + #define __Pyx_INCREF(r) Py_INCREF(r) + #define __Pyx_DECREF(r) Py_DECREF(r) + #define __Pyx_GOTREF(r) + #define __Pyx_GIVEREF(r) + #define __Pyx_XINCREF(r) Py_XINCREF(r) + #define __Pyx_XDECREF(r) Py_XDECREF(r) + #define __Pyx_XGOTREF(r) + #define __Pyx_XGIVEREF(r) +#endif +#define __Pyx_Py_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; Py_XDECREF(tmp);\ + } while (0) +#define __Pyx_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_XDECREF(tmp);\ + } while (0) +#define __Pyx_DECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_DECREF(tmp);\ + } while (0) +#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) +#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) + +/* PyErrExceptionMatches.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err) +static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err); +#else +#define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(err) +#endif + +/* PyThreadStateGet.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; +#define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current; +#if PY_VERSION_HEX >= 0x030C00A6 +#define __Pyx_PyErr_Occurred() (__pyx_tstate->current_exception != NULL) +#define __Pyx_PyErr_CurrentExceptionType() (__pyx_tstate->current_exception ? (PyObject*) Py_TYPE(__pyx_tstate->current_exception) : (PyObject*) NULL) +#else +#define __Pyx_PyErr_Occurred() (__pyx_tstate->curexc_type != NULL) +#define __Pyx_PyErr_CurrentExceptionType() (__pyx_tstate->curexc_type) +#endif +#else +#define __Pyx_PyThreadState_declare +#define __Pyx_PyThreadState_assign +#define __Pyx_PyErr_Occurred() (PyErr_Occurred() != NULL) +#define __Pyx_PyErr_CurrentExceptionType() PyErr_Occurred() +#endif + +/* PyErrFetchRestore.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL) +#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A6 +#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL)) +#else +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#endif +#else +#define __Pyx_PyErr_Clear() PyErr_Clear() +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) +#endif + +/* PyObjectGetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) +#endif + +/* PyObjectGetAttrStrNoError.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name); + +/* GetBuiltinName.proto */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name); + +/* TupleAndListFromArray.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n); +static CYTHON_INLINE PyObject* __Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n); +#endif + +/* IncludeStringH.proto */ +#include + +/* BytesEquals.proto */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); + +/* UnicodeEquals.proto */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); + +/* fastcall.proto */ +#if CYTHON_AVOID_BORROWED_REFS + #define __Pyx_Arg_VARARGS(args, i) PySequence_GetItem(args, i) +#elif CYTHON_ASSUME_SAFE_MACROS + #define __Pyx_Arg_VARARGS(args, i) PyTuple_GET_ITEM(args, i) +#else + #define __Pyx_Arg_VARARGS(args, i) PyTuple_GetItem(args, i) +#endif +#if CYTHON_AVOID_BORROWED_REFS + #define __Pyx_Arg_NewRef_VARARGS(arg) __Pyx_NewRef(arg) + #define __Pyx_Arg_XDECREF_VARARGS(arg) Py_XDECREF(arg) +#else + #define __Pyx_Arg_NewRef_VARARGS(arg) arg + #define __Pyx_Arg_XDECREF_VARARGS(arg) +#endif +#define __Pyx_NumKwargs_VARARGS(kwds) PyDict_Size(kwds) +#define __Pyx_KwValues_VARARGS(args, nargs) NULL +#define __Pyx_GetKwValue_VARARGS(kw, kwvalues, s) __Pyx_PyDict_GetItemStrWithError(kw, s) +#define __Pyx_KwargsAsDict_VARARGS(kw, kwvalues) PyDict_Copy(kw) +#if CYTHON_METH_FASTCALL + #define __Pyx_Arg_FASTCALL(args, i) args[i] + #define __Pyx_NumKwargs_FASTCALL(kwds) PyTuple_GET_SIZE(kwds) + #define __Pyx_KwValues_FASTCALL(args, nargs) ((args) + (nargs)) + static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s); +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000 + CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues); + #else + #define __Pyx_KwargsAsDict_FASTCALL(kw, kwvalues) _PyStack_AsDict(kwvalues, kw) + #endif + #define __Pyx_Arg_NewRef_FASTCALL(arg) arg /* no-op, __Pyx_Arg_FASTCALL is direct and this needs + to have the same reference counting */ + #define __Pyx_Arg_XDECREF_FASTCALL(arg) +#else + #define __Pyx_Arg_FASTCALL __Pyx_Arg_VARARGS + #define __Pyx_NumKwargs_FASTCALL __Pyx_NumKwargs_VARARGS + #define __Pyx_KwValues_FASTCALL __Pyx_KwValues_VARARGS + #define __Pyx_GetKwValue_FASTCALL __Pyx_GetKwValue_VARARGS + #define __Pyx_KwargsAsDict_FASTCALL __Pyx_KwargsAsDict_VARARGS + #define __Pyx_Arg_NewRef_FASTCALL(arg) __Pyx_Arg_NewRef_VARARGS(arg) + #define __Pyx_Arg_XDECREF_FASTCALL(arg) __Pyx_Arg_XDECREF_VARARGS(arg) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS +#define __Pyx_ArgsSlice_VARARGS(args, start, stop) __Pyx_PyTuple_FromArray(&__Pyx_Arg_VARARGS(args, start), stop - start) +#define __Pyx_ArgsSlice_FASTCALL(args, start, stop) __Pyx_PyTuple_FromArray(&__Pyx_Arg_FASTCALL(args, start), stop - start) +#else +#define __Pyx_ArgsSlice_VARARGS(args, start, stop) PyTuple_GetSlice(args, start, stop) +#define __Pyx_ArgsSlice_FASTCALL(args, start, stop) PyTuple_GetSlice(args, start, stop) +#endif + +/* RaiseDoubleKeywords.proto */ +static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); + +/* ParseKeywords.proto */ +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject *const *kwvalues, + PyObject **argnames[], + PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, + const char* function_name); + +/* RaiseArgTupleInvalid.proto */ +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); + +/* ArgTypeTest.proto */ +#define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\ + ((likely(__Pyx_IS_TYPE(obj, type) | (none_allowed && (obj == Py_None)))) ? 1 :\ + __Pyx__ArgTypeTest(obj, type, name, exact)) +static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact); + +/* PyObjectCall.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); +#else +#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) +#endif + +/* PyObjectLookupSpecial.proto */ +#if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS +#define __Pyx_PyObject_LookupSpecialNoError(obj, attr_name) __Pyx__PyObject_LookupSpecial(obj, attr_name, 0) +#define __Pyx_PyObject_LookupSpecial(obj, attr_name) __Pyx__PyObject_LookupSpecial(obj, attr_name, 1) +static CYTHON_INLINE PyObject* __Pyx__PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name, int with_error); +#else +#define __Pyx_PyObject_LookupSpecialNoError(o,n) __Pyx_PyObject_GetAttrStrNoError(o,n) +#define __Pyx_PyObject_LookupSpecial(o,n) __Pyx_PyObject_GetAttrStr(o,n) +#endif + +/* PyFunctionFastCall.proto */ +#if CYTHON_FAST_PYCALL +#if !CYTHON_VECTORCALL +#define __Pyx_PyFunction_FastCall(func, args, nargs)\ + __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL) +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs); +#endif +#define __Pyx_BUILD_ASSERT_EXPR(cond)\ + (sizeof(char [1 - 2*!(cond)]) - 1) +#ifndef Py_MEMBER_SIZE +#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) +#endif +#if !CYTHON_VECTORCALL +#if PY_VERSION_HEX >= 0x03080000 + #include "frameobject.h" +#if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API + #ifndef Py_BUILD_CORE + #define Py_BUILD_CORE 1 + #endif + #include "internal/pycore_frame.h" +#endif + #define __Pxy_PyFrame_Initialize_Offsets() + #define __Pyx_PyFrame_GetLocalsplus(frame) ((frame)->f_localsplus) +#else + static size_t __pyx_pyframe_localsplus_offset = 0; + #include "frameobject.h" + #define __Pxy_PyFrame_Initialize_Offsets()\ + ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ + (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) + #define __Pyx_PyFrame_GetLocalsplus(frame)\ + (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) +#endif +#endif +#endif + +/* PyObjectCallMethO.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); +#endif + +/* PyObjectFastCall.proto */ +#define __Pyx_PyObject_FastCall(func, args, nargs) __Pyx_PyObject_FastCallDict(func, args, (size_t)(nargs), NULL) +static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject **args, size_t nargs, PyObject *kwargs); + +/* PyDictVersioning.proto */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) +#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ + (version_var) = __PYX_GET_DICT_VERSION(dict);\ + (cache_var) = (value); +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ + (VAR) = __pyx_dict_cached_value;\ + } else {\ + (VAR) = __pyx_dict_cached_value = (LOOKUP);\ + __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ + }\ +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); +#else +#define __PYX_GET_DICT_VERSION(dict) (0) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); +#endif + +/* GetModuleGlobalName.proto */ +#if CYTHON_USE_DICT_VERSIONS +#define __Pyx_GetModuleGlobalName(var, name) do {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ + (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ + __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} while(0) +#define __Pyx_GetModuleGlobalNameUncached(var, name) do {\ + PY_UINT64_T __pyx_dict_version;\ + PyObject *__pyx_dict_cached_value;\ + (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} while(0) +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); +#else +#define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) +#define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); +#endif + +/* RaiseUnexpectedTypeError.proto */ +static int __Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj); + +/* GetTopmostException.proto */ +#if CYTHON_USE_EXC_INFO_STACK && CYTHON_FAST_THREAD_STATE +static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate); +#endif + +/* SaveResetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#define __Pyx_ExceptionReset(type, value, tb) __Pyx__ExceptionReset(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +#else +#define __Pyx_ExceptionSave(type, value, tb) PyErr_GetExcInfo(type, value, tb) +#define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb) +#endif + +/* GetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_GetException(type, value, tb) __Pyx__GetException(__pyx_tstate, type, value, tb) +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* FastTypeChecks.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type) +#define __Pyx_TypeCheck2(obj, type1, type2) __Pyx_IsAnySubtype2(Py_TYPE(obj), (PyTypeObject *)type1, (PyTypeObject *)type2) +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b); +static CYTHON_INLINE int __Pyx_IsAnySubtype2(PyTypeObject *cls, PyTypeObject *a, PyTypeObject *b); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2); +#else +#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) +#define __Pyx_TypeCheck2(obj, type1, type2) (PyObject_TypeCheck(obj, (PyTypeObject *)type1) || PyObject_TypeCheck(obj, (PyTypeObject *)type2)) +#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type) +#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2)) +#endif +#define __Pyx_PyErr_ExceptionMatches2(err1, err2) __Pyx_PyErr_GivenExceptionMatches2(__Pyx_PyErr_CurrentExceptionType(), err1, err2) +#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) + +/* PyUnicode_Unicode.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_Unicode(PyObject *obj); + +/* JoinPyUnicode.proto */ +static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, + Py_UCS4 max_char); + +/* KeywordStringCheck.proto */ +static int __Pyx_CheckKeywordStrings(PyObject *kw, const char* function_name, int kw_allowed); + +/* RaiseException.proto */ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); + +/* PyObjectFormatSimple.proto */ +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyObject_FormatSimple(s, f) (\ + likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ + PyObject_Format(s, f)) +#elif PY_MAJOR_VERSION < 3 + #define __Pyx_PyObject_FormatSimple(s, f) (\ + likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ + likely(PyString_CheckExact(s)) ? PyUnicode_FromEncodedObject(s, NULL, "strict") :\ + PyObject_Format(s, f)) +#elif CYTHON_USE_TYPE_SLOTS + #define __Pyx_PyObject_FormatSimple(s, f) (\ + likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ + likely(PyLong_CheckExact(s)) ? PyLong_Type.tp_repr(s) :\ + likely(PyFloat_CheckExact(s)) ? PyFloat_Type.tp_repr(s) :\ + PyObject_Format(s, f)) +#else + #define __Pyx_PyObject_FormatSimple(s, f) (\ + likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ + PyObject_Format(s, f)) +#endif + +/* SwapException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* IncludeStructmemberH.proto */ +#include + +/* FixUpExtensionType.proto */ +#if CYTHON_USE_TYPE_SPECS +static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type); +#endif + +/* PyObjectCallNoArg.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); + +/* PyObjectCallOneArg.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); + +/* PyObjectGetMethod.proto */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); + +/* PyObjectCallMethod0.proto */ +static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); + +/* ValidateBasesTuple.proto */ +#if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS +static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases); +#endif + +/* PyType_Ready.proto */ +CYTHON_UNUSED static int __Pyx_PyType_Ready(PyTypeObject *t); + +/* PyObject_GenericGetAttrNoDict.proto */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr +#endif + +/* PyObject_GenericGetAttr.proto */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr +#endif + +/* SetupReduce.proto */ +#if !CYTHON_COMPILING_IN_LIMITED_API +static int __Pyx_setup_reduce(PyObject* type_obj); +#endif + +/* Import.proto */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); + +/* ImportDottedModule.proto */ +static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple); +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple); +#endif + +/* FetchSharedCythonModule.proto */ +static PyObject *__Pyx_FetchSharedCythonABIModule(void); + +/* FetchCommonType.proto */ +#if !CYTHON_USE_TYPE_SPECS +static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type); +#else +static PyTypeObject* __Pyx_FetchCommonTypeFromSpec(PyObject *module, PyType_Spec *spec, PyObject *bases); +#endif + +/* PyMethodNew.proto */ +#if CYTHON_COMPILING_IN_LIMITED_API +static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) { + PyObject *typesModule=NULL, *methodType=NULL, *result=NULL; + CYTHON_UNUSED_VAR(typ); + if (!self) + return __Pyx_NewRef(func); + typesModule = PyImport_ImportModule("types"); + if (!typesModule) return NULL; + methodType = PyObject_GetAttrString(typesModule, "MethodType"); + Py_DECREF(typesModule); + if (!methodType) return NULL; + result = PyObject_CallFunctionObjArgs(methodType, func, self, NULL); + Py_DECREF(methodType); + return result; +} +#elif PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) { + CYTHON_UNUSED_VAR(typ); + if (!self) + return __Pyx_NewRef(func); + return PyMethod_New(func, self); +} +#else + #define __Pyx_PyMethod_New PyMethod_New +#endif + +/* PyVectorcallFastCallDict.proto */ +#if CYTHON_METH_FASTCALL +static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw); +#endif + +/* CythonFunctionShared.proto */ +#define __Pyx_CyFunction_USED +#define __Pyx_CYFUNCTION_STATICMETHOD 0x01 +#define __Pyx_CYFUNCTION_CLASSMETHOD 0x02 +#define __Pyx_CYFUNCTION_CCLASS 0x04 +#define __Pyx_CYFUNCTION_COROUTINE 0x08 +#define __Pyx_CyFunction_GetClosure(f)\ + (((__pyx_CyFunctionObject *) (f))->func_closure) +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_CyFunction_GetClassObj(f)\ + (((__pyx_CyFunctionObject *) (f))->func_classobj) +#else + #define __Pyx_CyFunction_GetClassObj(f)\ + ((PyObject*) ((PyCMethodObject *) (f))->mm_class) +#endif +#define __Pyx_CyFunction_SetClassObj(f, classobj)\ + __Pyx__CyFunction_SetClassObj((__pyx_CyFunctionObject *) (f), (classobj)) +#define __Pyx_CyFunction_Defaults(type, f)\ + ((type *)(((__pyx_CyFunctionObject *) (f))->defaults)) +#define __Pyx_CyFunction_SetDefaultsGetter(f, g)\ + ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g) +typedef struct { +#if CYTHON_COMPILING_IN_LIMITED_API + PyObject_HEAD + PyObject *func; +#elif PY_VERSION_HEX < 0x030900B1 + PyCFunctionObject func; +#else + PyCMethodObject func; +#endif +#if CYTHON_BACKPORT_VECTORCALL + __pyx_vectorcallfunc func_vectorcall; +#endif +#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API + PyObject *func_weakreflist; +#endif + PyObject *func_dict; + PyObject *func_name; + PyObject *func_qualname; + PyObject *func_doc; + PyObject *func_globals; + PyObject *func_code; + PyObject *func_closure; +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + PyObject *func_classobj; +#endif + void *defaults; + int defaults_pyobjects; + size_t defaults_size; + int flags; + PyObject *defaults_tuple; + PyObject *defaults_kwdict; + PyObject *(*defaults_getter)(PyObject *); + PyObject *func_annotations; + PyObject *func_is_coroutine; +} __pyx_CyFunctionObject; +#undef __Pyx_CyOrPyCFunction_Check +#define __Pyx_CyFunction_Check(obj) __Pyx_TypeCheck(obj, __pyx_CyFunctionType) +#define __Pyx_CyOrPyCFunction_Check(obj) __Pyx_TypeCheck2(obj, __pyx_CyFunctionType, &PyCFunction_Type) +#define __Pyx_CyFunction_CheckExact(obj) __Pyx_IS_TYPE(obj, __pyx_CyFunctionType) +static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc); +#undef __Pyx_IsSameCFunction +#define __Pyx_IsSameCFunction(func, cfunc) __Pyx__IsSameCyOrCFunction(func, cfunc) +static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject* op, PyMethodDef *ml, + int flags, PyObject* qualname, + PyObject *closure, + PyObject *module, PyObject *globals, + PyObject* code); +static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj); +static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m, + size_t size, + int pyobjects); +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m, + PyObject *tuple); +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m, + PyObject *dict); +static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m, + PyObject *dict); +static int __pyx_CyFunction_init(PyObject *module); +#if CYTHON_METH_FASTCALL +static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +#if CYTHON_BACKPORT_VECTORCALL +#define __Pyx_CyFunction_func_vectorcall(f) (((__pyx_CyFunctionObject*)f)->func_vectorcall) +#else +#define __Pyx_CyFunction_func_vectorcall(f) (((PyCFunctionObject*)f)->vectorcall) +#endif +#endif + +/* CythonFunction.proto */ +static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, + int flags, PyObject* qualname, + PyObject *closure, + PyObject *module, PyObject *globals, + PyObject* code); + +/* CLineInTraceback.proto */ +#ifdef CYTHON_CLINE_IN_TRACEBACK +#define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0) +#else +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line); +#endif + +/* CodeObjectCache.proto */ +#if !CYTHON_COMPILING_IN_LIMITED_API +typedef struct { + PyCodeObject* code_object; + int code_line; +} __Pyx_CodeObjectCacheEntry; +struct __Pyx_CodeObjectCache { + int count; + int max_count; + __Pyx_CodeObjectCacheEntry* entries; +}; +static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); +static PyCodeObject *__pyx_find_code_object(int code_line); +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); +#endif + +/* AddTraceback.proto */ +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename); + +/* FormatTypeName.proto */ +#if CYTHON_COMPILING_IN_LIMITED_API +typedef PyObject *__Pyx_TypeName; +#define __Pyx_FMT_TYPENAME "%U" +static __Pyx_TypeName __Pyx_PyType_GetName(PyTypeObject* tp); +#define __Pyx_DECREF_TypeName(obj) Py_XDECREF(obj) +#else +typedef const char *__Pyx_TypeName; +#define __Pyx_FMT_TYPENAME "%.200s" +#define __Pyx_PyType_GetName(tp) ((tp)->tp_name) +#define __Pyx_DECREF_TypeName(obj) +#endif + +/* GCCDiagnostics.proto */ +#if !defined(__INTEL_COMPILER) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +#define __Pyx_HAS_GCC_DIAGNOSTIC +#endif + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + +/* CIntFromPy.proto */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); + +/* CIntFromPy.proto */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); + +/* CheckBinaryVersion.proto */ +static unsigned long __Pyx_get_runtime_version(void); +static int __Pyx_check_binary_version(unsigned long ct_version, unsigned long rt_version, int allow_newer); + +/* InitStrings.proto */ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); + +/* #### Code section: module_declarations ### */ + +/* Module declarations from "cython" */ + +/* Module declarations from "cython_code.file_db" */ +/* #### Code section: typeinfo ### */ +/* #### Code section: before_global_var ### */ +#define __Pyx_MODULE_NAME "cython_code.file_db" +extern int __pyx_module_is_main_cython_code__file_db; +int __pyx_module_is_main_cython_code__file_db = 0; + +/* Implementation of "cython_code.file_db" */ +/* #### Code section: global_var ### */ +static PyObject *__pyx_builtin_open; +static PyObject *__pyx_builtin_TypeError; +/* #### Code section: string_decls ### */ +static const char __pyx_k_r[] = "r"; +static const char __pyx_k_w[] = "w"; +static const char __pyx_k__2[] = "*"; +static const char __pyx_k_gc[] = "gc"; +static const char __pyx_k_os[] = "os"; +static const char __pyx_k__19[] = "?"; +static const char __pyx_k_ads[] = "ads"; +static const char __pyx_k_err[] = "err"; +static const char __pyx_k_key[] = "key"; +static const char __pyx_k_None[] = "None"; +static const char __pyx_k_data[] = "data"; +static const char __pyx_k_dump[] = "dump"; +static const char __pyx_k_exit[] = "__exit__"; +static const char __pyx_k_file[] = "file"; +static const char __pyx_k_info[] = "info"; +static const char __pyx_k_json[] = "json"; +static const char __pyx_k_load[] = "load"; +static const char __pyx_k_main[] = "__main__"; +static const char __pyx_k_name[] = "__name__"; +static const char __pyx_k_open[] = "open"; +static const char __pyx_k_self[] = "self"; +static const char __pyx_k_spec[] = "__spec__"; +static const char __pyx_k_test[] = "__test__"; +static const char __pyx_k_BotDb[] = "BotDb"; +static const char __pyx_k_chmod[] = "chmod"; +static const char __pyx_k_enter[] = "__enter__"; +static const char __pyx_k_error[] = "error"; +static const char __pyx_k_FileDB[] = "FileDB"; +static const char __pyx_k_enable[] = "enable"; +static const char __pyx_k_import[] = "__import__"; +static const char __pyx_k_reduce[] = "__reduce__"; +static const char __pyx_k_disable[] = "disable"; +static const char __pyx_k_logging[] = "logging"; +static const char __pyx_k_add_data[] = "add_data"; +static const char __pyx_k_getstate[] = "__getstate__"; +static const char __pyx_k_new_data[] = "new_data"; +static const char __pyx_k_setstate[] = "__setstate__"; +static const char __pyx_k_TypeError[] = "TypeError"; +static const char __pyx_k_isenabled[] = "isenabled"; +static const char __pyx_k_json_file[] = "json_file"; +static const char __pyx_k_pyx_state[] = "__pyx_state"; +static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; +static const char __pyx_k_reading_db[] = "reading_db"; +static const char __pyx_k_change_data[] = "change_data"; +static const char __pyx_k_initializing[] = "_initializing"; +static const char __pyx_k_is_coroutine[] = "_is_coroutine"; +static const char __pyx_k_join_channel[] = "join_channel"; +static const char __pyx_k_stringsource[] = ""; +static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; +static const char __pyx_k_FileDB_add_data[] = "FileDB.add_data"; +static const char __pyx_k_FileDB_new_data[] = "FileDB.new_data"; +static const char __pyx_k_JSONDecodeError[] = "JSONDecodeError"; +static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; +static const char __pyx_k_BotDb_reading_db[] = "BotDb.reading_db"; +static const char __pyx_k_Created_new_file[] = "Created new file: "; +static const char __pyx_k_BotDb_change_data[] = "BotDb.change_data"; +static const char __pyx_k_FileDB_reading_db[] = "FileDB.reading_db"; +static const char __pyx_k_FileNotFoundError[] = "FileNotFoundError"; +static const char __pyx_k_with_default_data[] = " with default data"; +static const char __pyx_k_asyncio_coroutines[] = "asyncio.coroutines"; +static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; +static const char __pyx_k_cython_code_file_db[] = "cython_code.file_db"; +static const char __pyx_k_BotDb___reduce_cython[] = "BotDb.__reduce_cython__"; +static const char __pyx_k_Error_reading_the_file[] = "Error reading the file: "; +static const char __pyx_k_FileDB___reduce_cython[] = "FileDB.__reduce_cython__"; +static const char __pyx_k_BotDb___setstate_cython[] = "BotDb.__setstate_cython__"; +static const char __pyx_k_Error_updating_the_file[] = "Error updating the file: "; +static const char __pyx_k_cython_code_file_db_pyx[] = "cython_code/file_db.pyx"; +static const char __pyx_k_FileDB___setstate_cython[] = "FileDB.__setstate_cython__"; +static const char __pyx_k_Error_writing_to_the_file[] = "Error writing to the file: "; +static const char __pyx_k_no_default___reduce___due_to_non[] = "no default __reduce__ due to non-trivial __cinit__"; +/* #### Code section: decls ### */ +static int __pyx_pf_11cython_code_7file_db_5BotDb___cinit__(struct __pyx_obj_11cython_code_7file_db_BotDb *__pyx_v_self, PyObject *__pyx_v_file); /* proto */ +static PyObject *__pyx_pf_11cython_code_7file_db_5BotDb_2reading_db(struct __pyx_obj_11cython_code_7file_db_BotDb *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_11cython_code_7file_db_5BotDb_4change_data(struct __pyx_obj_11cython_code_7file_db_BotDb *__pyx_v_self, int __pyx_v_join_channel); /* proto */ +static PyObject *__pyx_pf_11cython_code_7file_db_5BotDb_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_11cython_code_7file_db_BotDb *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_11cython_code_7file_db_5BotDb_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_11cython_code_7file_db_BotDb *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static int __pyx_pf_11cython_code_7file_db_6FileDB___cinit__(struct __pyx_obj_11cython_code_7file_db_FileDB *__pyx_v_self, PyObject *__pyx_v_file); /* proto */ +static PyObject *__pyx_pf_11cython_code_7file_db_6FileDB_2reading_db(struct __pyx_obj_11cython_code_7file_db_FileDB *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_11cython_code_7file_db_6FileDB_4add_data(struct __pyx_obj_11cython_code_7file_db_FileDB *__pyx_v_self, PyObject *__pyx_v_data, PyObject *__pyx_v_key); /* proto */ +static PyObject *__pyx_pf_11cython_code_7file_db_6FileDB_6new_data(struct __pyx_obj_11cython_code_7file_db_FileDB *__pyx_v_self, PyObject *__pyx_v_data); /* proto */ +static PyObject *__pyx_pf_11cython_code_7file_db_6FileDB_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_11cython_code_7file_db_FileDB *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_11cython_code_7file_db_6FileDB_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_11cython_code_7file_db_FileDB *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_tp_new_11cython_code_7file_db_BotDb(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static PyObject *__pyx_tp_new_11cython_code_7file_db_FileDB(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +/* #### Code section: late_includes ### */ +/* #### Code section: module_state ### */ +typedef struct { + PyObject *__pyx_d; + PyObject *__pyx_b; + PyObject *__pyx_cython_runtime; + PyObject *__pyx_empty_tuple; + PyObject *__pyx_empty_bytes; + PyObject *__pyx_empty_unicode; + #ifdef __Pyx_CyFunction_USED + PyTypeObject *__pyx_CyFunctionType; + #endif + #ifdef __Pyx_FusedFunction_USED + PyTypeObject *__pyx_FusedFunctionType; + #endif + #ifdef __Pyx_Generator_USED + PyTypeObject *__pyx_GeneratorType; + #endif + #ifdef __Pyx_IterableCoroutine_USED + PyTypeObject *__pyx_IterableCoroutineType; + #endif + #ifdef __Pyx_Coroutine_USED + PyTypeObject *__pyx_CoroutineAwaitType; + #endif + #ifdef __Pyx_Coroutine_USED + PyTypeObject *__pyx_CoroutineType; + #endif + #if CYTHON_USE_MODULE_STATE + #endif + #if CYTHON_USE_MODULE_STATE + PyObject *__pyx_type_11cython_code_7file_db_BotDb; + PyObject *__pyx_type_11cython_code_7file_db_FileDB; + #endif + PyTypeObject *__pyx_ptype_11cython_code_7file_db_BotDb; + PyTypeObject *__pyx_ptype_11cython_code_7file_db_FileDB; + PyObject *__pyx_n_s_BotDb; + PyObject *__pyx_n_s_BotDb___reduce_cython; + PyObject *__pyx_n_s_BotDb___setstate_cython; + PyObject *__pyx_n_s_BotDb_change_data; + PyObject *__pyx_n_s_BotDb_reading_db; + PyObject *__pyx_kp_u_Created_new_file; + PyObject *__pyx_kp_u_Error_reading_the_file; + PyObject *__pyx_kp_u_Error_updating_the_file; + PyObject *__pyx_kp_u_Error_writing_to_the_file; + PyObject *__pyx_n_s_FileDB; + PyObject *__pyx_n_s_FileDB___reduce_cython; + PyObject *__pyx_n_s_FileDB___setstate_cython; + PyObject *__pyx_n_s_FileDB_add_data; + PyObject *__pyx_n_s_FileDB_new_data; + PyObject *__pyx_n_s_FileDB_reading_db; + PyObject *__pyx_n_s_FileNotFoundError; + PyObject *__pyx_n_s_JSONDecodeError; + PyObject *__pyx_kp_u_None; + PyObject *__pyx_n_s_TypeError; + PyObject *__pyx_n_s__19; + PyObject *__pyx_n_s__2; + PyObject *__pyx_n_s_add_data; + PyObject *__pyx_n_u_ads; + PyObject *__pyx_n_s_asyncio_coroutines; + PyObject *__pyx_n_s_change_data; + PyObject *__pyx_n_s_chmod; + PyObject *__pyx_n_s_cline_in_traceback; + PyObject *__pyx_n_s_cython_code_file_db; + PyObject *__pyx_kp_s_cython_code_file_db_pyx; + PyObject *__pyx_n_s_data; + PyObject *__pyx_kp_u_disable; + PyObject *__pyx_n_s_dump; + PyObject *__pyx_kp_u_enable; + PyObject *__pyx_n_s_enter; + PyObject *__pyx_n_s_err; + PyObject *__pyx_n_s_error; + PyObject *__pyx_n_s_exit; + PyObject *__pyx_n_s_file; + PyObject *__pyx_kp_u_gc; + PyObject *__pyx_n_s_getstate; + PyObject *__pyx_n_s_import; + PyObject *__pyx_n_s_info; + PyObject *__pyx_n_s_initializing; + PyObject *__pyx_n_s_is_coroutine; + PyObject *__pyx_kp_u_isenabled; + PyObject *__pyx_n_s_join_channel; + PyObject *__pyx_n_u_join_channel; + PyObject *__pyx_n_s_json; + PyObject *__pyx_n_s_json_file; + PyObject *__pyx_n_s_key; + PyObject *__pyx_n_s_load; + PyObject *__pyx_n_s_logging; + PyObject *__pyx_n_s_main; + PyObject *__pyx_n_s_name; + PyObject *__pyx_n_s_new_data; + PyObject *__pyx_kp_s_no_default___reduce___due_to_non; + PyObject *__pyx_n_s_open; + PyObject *__pyx_n_s_os; + PyObject *__pyx_n_s_pyx_state; + PyObject *__pyx_n_u_r; + PyObject *__pyx_n_s_reading_db; + PyObject *__pyx_n_s_reduce; + PyObject *__pyx_n_s_reduce_cython; + PyObject *__pyx_n_s_reduce_ex; + PyObject *__pyx_n_s_self; + PyObject *__pyx_n_s_setstate; + PyObject *__pyx_n_s_setstate_cython; + PyObject *__pyx_n_s_spec; + PyObject *__pyx_kp_s_stringsource; + PyObject *__pyx_n_s_test; + PyObject *__pyx_n_u_w; + PyObject *__pyx_kp_u_with_default_data; + PyObject *__pyx_int_511; + PyObject *__pyx_tuple_; + PyObject *__pyx_tuple__3; + PyObject *__pyx_tuple__5; + PyObject *__pyx_tuple__7; + PyObject *__pyx_tuple__9; + PyObject *__pyx_tuple__11; + PyObject *__pyx_tuple__13; + PyObject *__pyx_tuple__15; + PyObject *__pyx_codeobj__4; + PyObject *__pyx_codeobj__6; + PyObject *__pyx_codeobj__8; + PyObject *__pyx_codeobj__10; + PyObject *__pyx_codeobj__12; + PyObject *__pyx_codeobj__14; + PyObject *__pyx_codeobj__16; + PyObject *__pyx_codeobj__17; + PyObject *__pyx_codeobj__18; +} __pyx_mstate; + +#if CYTHON_USE_MODULE_STATE +#ifdef __cplusplus +namespace { + extern struct PyModuleDef __pyx_moduledef; +} /* anonymous namespace */ +#else +static struct PyModuleDef __pyx_moduledef; +#endif + +#define __pyx_mstate(o) ((__pyx_mstate *)__Pyx_PyModule_GetState(o)) + +#define __pyx_mstate_global (__pyx_mstate(PyState_FindModule(&__pyx_moduledef))) + +#define __pyx_m (PyState_FindModule(&__pyx_moduledef)) +#else +static __pyx_mstate __pyx_mstate_global_static = +#ifdef __cplusplus + {}; +#else + {0}; +#endif +static __pyx_mstate *__pyx_mstate_global = &__pyx_mstate_global_static; +#endif +/* #### Code section: module_state_clear ### */ +#if CYTHON_USE_MODULE_STATE +static int __pyx_m_clear(PyObject *m) { + __pyx_mstate *clear_module_state = __pyx_mstate(m); + if (!clear_module_state) return 0; + Py_CLEAR(clear_module_state->__pyx_d); + Py_CLEAR(clear_module_state->__pyx_b); + Py_CLEAR(clear_module_state->__pyx_cython_runtime); + Py_CLEAR(clear_module_state->__pyx_empty_tuple); + Py_CLEAR(clear_module_state->__pyx_empty_bytes); + Py_CLEAR(clear_module_state->__pyx_empty_unicode); + #ifdef __Pyx_CyFunction_USED + Py_CLEAR(clear_module_state->__pyx_CyFunctionType); + #endif + #ifdef __Pyx_FusedFunction_USED + Py_CLEAR(clear_module_state->__pyx_FusedFunctionType); + #endif + Py_CLEAR(clear_module_state->__pyx_ptype_11cython_code_7file_db_BotDb); + Py_CLEAR(clear_module_state->__pyx_type_11cython_code_7file_db_BotDb); + Py_CLEAR(clear_module_state->__pyx_ptype_11cython_code_7file_db_FileDB); + Py_CLEAR(clear_module_state->__pyx_type_11cython_code_7file_db_FileDB); + Py_CLEAR(clear_module_state->__pyx_n_s_BotDb); + Py_CLEAR(clear_module_state->__pyx_n_s_BotDb___reduce_cython); + Py_CLEAR(clear_module_state->__pyx_n_s_BotDb___setstate_cython); + Py_CLEAR(clear_module_state->__pyx_n_s_BotDb_change_data); + Py_CLEAR(clear_module_state->__pyx_n_s_BotDb_reading_db); + Py_CLEAR(clear_module_state->__pyx_kp_u_Created_new_file); + Py_CLEAR(clear_module_state->__pyx_kp_u_Error_reading_the_file); + Py_CLEAR(clear_module_state->__pyx_kp_u_Error_updating_the_file); + Py_CLEAR(clear_module_state->__pyx_kp_u_Error_writing_to_the_file); + Py_CLEAR(clear_module_state->__pyx_n_s_FileDB); + Py_CLEAR(clear_module_state->__pyx_n_s_FileDB___reduce_cython); + Py_CLEAR(clear_module_state->__pyx_n_s_FileDB___setstate_cython); + Py_CLEAR(clear_module_state->__pyx_n_s_FileDB_add_data); + Py_CLEAR(clear_module_state->__pyx_n_s_FileDB_new_data); + Py_CLEAR(clear_module_state->__pyx_n_s_FileDB_reading_db); + Py_CLEAR(clear_module_state->__pyx_n_s_FileNotFoundError); + Py_CLEAR(clear_module_state->__pyx_n_s_JSONDecodeError); + Py_CLEAR(clear_module_state->__pyx_kp_u_None); + Py_CLEAR(clear_module_state->__pyx_n_s_TypeError); + Py_CLEAR(clear_module_state->__pyx_n_s__19); + Py_CLEAR(clear_module_state->__pyx_n_s__2); + Py_CLEAR(clear_module_state->__pyx_n_s_add_data); + Py_CLEAR(clear_module_state->__pyx_n_u_ads); + Py_CLEAR(clear_module_state->__pyx_n_s_asyncio_coroutines); + Py_CLEAR(clear_module_state->__pyx_n_s_change_data); + Py_CLEAR(clear_module_state->__pyx_n_s_chmod); + Py_CLEAR(clear_module_state->__pyx_n_s_cline_in_traceback); + Py_CLEAR(clear_module_state->__pyx_n_s_cython_code_file_db); + Py_CLEAR(clear_module_state->__pyx_kp_s_cython_code_file_db_pyx); + Py_CLEAR(clear_module_state->__pyx_n_s_data); + Py_CLEAR(clear_module_state->__pyx_kp_u_disable); + Py_CLEAR(clear_module_state->__pyx_n_s_dump); + Py_CLEAR(clear_module_state->__pyx_kp_u_enable); + Py_CLEAR(clear_module_state->__pyx_n_s_enter); + Py_CLEAR(clear_module_state->__pyx_n_s_err); + Py_CLEAR(clear_module_state->__pyx_n_s_error); + Py_CLEAR(clear_module_state->__pyx_n_s_exit); + Py_CLEAR(clear_module_state->__pyx_n_s_file); + Py_CLEAR(clear_module_state->__pyx_kp_u_gc); + Py_CLEAR(clear_module_state->__pyx_n_s_getstate); + Py_CLEAR(clear_module_state->__pyx_n_s_import); + Py_CLEAR(clear_module_state->__pyx_n_s_info); + Py_CLEAR(clear_module_state->__pyx_n_s_initializing); + Py_CLEAR(clear_module_state->__pyx_n_s_is_coroutine); + Py_CLEAR(clear_module_state->__pyx_kp_u_isenabled); + Py_CLEAR(clear_module_state->__pyx_n_s_join_channel); + Py_CLEAR(clear_module_state->__pyx_n_u_join_channel); + Py_CLEAR(clear_module_state->__pyx_n_s_json); + Py_CLEAR(clear_module_state->__pyx_n_s_json_file); + Py_CLEAR(clear_module_state->__pyx_n_s_key); + Py_CLEAR(clear_module_state->__pyx_n_s_load); + Py_CLEAR(clear_module_state->__pyx_n_s_logging); + Py_CLEAR(clear_module_state->__pyx_n_s_main); + Py_CLEAR(clear_module_state->__pyx_n_s_name); + Py_CLEAR(clear_module_state->__pyx_n_s_new_data); + Py_CLEAR(clear_module_state->__pyx_kp_s_no_default___reduce___due_to_non); + Py_CLEAR(clear_module_state->__pyx_n_s_open); + Py_CLEAR(clear_module_state->__pyx_n_s_os); + Py_CLEAR(clear_module_state->__pyx_n_s_pyx_state); + Py_CLEAR(clear_module_state->__pyx_n_u_r); + Py_CLEAR(clear_module_state->__pyx_n_s_reading_db); + Py_CLEAR(clear_module_state->__pyx_n_s_reduce); + Py_CLEAR(clear_module_state->__pyx_n_s_reduce_cython); + Py_CLEAR(clear_module_state->__pyx_n_s_reduce_ex); + Py_CLEAR(clear_module_state->__pyx_n_s_self); + Py_CLEAR(clear_module_state->__pyx_n_s_setstate); + Py_CLEAR(clear_module_state->__pyx_n_s_setstate_cython); + Py_CLEAR(clear_module_state->__pyx_n_s_spec); + Py_CLEAR(clear_module_state->__pyx_kp_s_stringsource); + Py_CLEAR(clear_module_state->__pyx_n_s_test); + Py_CLEAR(clear_module_state->__pyx_n_u_w); + Py_CLEAR(clear_module_state->__pyx_kp_u_with_default_data); + Py_CLEAR(clear_module_state->__pyx_int_511); + Py_CLEAR(clear_module_state->__pyx_tuple_); + Py_CLEAR(clear_module_state->__pyx_tuple__3); + Py_CLEAR(clear_module_state->__pyx_tuple__5); + Py_CLEAR(clear_module_state->__pyx_tuple__7); + Py_CLEAR(clear_module_state->__pyx_tuple__9); + Py_CLEAR(clear_module_state->__pyx_tuple__11); + Py_CLEAR(clear_module_state->__pyx_tuple__13); + Py_CLEAR(clear_module_state->__pyx_tuple__15); + Py_CLEAR(clear_module_state->__pyx_codeobj__4); + Py_CLEAR(clear_module_state->__pyx_codeobj__6); + Py_CLEAR(clear_module_state->__pyx_codeobj__8); + Py_CLEAR(clear_module_state->__pyx_codeobj__10); + Py_CLEAR(clear_module_state->__pyx_codeobj__12); + Py_CLEAR(clear_module_state->__pyx_codeobj__14); + Py_CLEAR(clear_module_state->__pyx_codeobj__16); + Py_CLEAR(clear_module_state->__pyx_codeobj__17); + Py_CLEAR(clear_module_state->__pyx_codeobj__18); + return 0; +} +#endif +/* #### Code section: module_state_traverse ### */ +#if CYTHON_USE_MODULE_STATE +static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { + __pyx_mstate *traverse_module_state = __pyx_mstate(m); + if (!traverse_module_state) return 0; + Py_VISIT(traverse_module_state->__pyx_d); + Py_VISIT(traverse_module_state->__pyx_b); + Py_VISIT(traverse_module_state->__pyx_cython_runtime); + Py_VISIT(traverse_module_state->__pyx_empty_tuple); + Py_VISIT(traverse_module_state->__pyx_empty_bytes); + Py_VISIT(traverse_module_state->__pyx_empty_unicode); + #ifdef __Pyx_CyFunction_USED + Py_VISIT(traverse_module_state->__pyx_CyFunctionType); + #endif + #ifdef __Pyx_FusedFunction_USED + Py_VISIT(traverse_module_state->__pyx_FusedFunctionType); + #endif + Py_VISIT(traverse_module_state->__pyx_ptype_11cython_code_7file_db_BotDb); + Py_VISIT(traverse_module_state->__pyx_type_11cython_code_7file_db_BotDb); + Py_VISIT(traverse_module_state->__pyx_ptype_11cython_code_7file_db_FileDB); + Py_VISIT(traverse_module_state->__pyx_type_11cython_code_7file_db_FileDB); + Py_VISIT(traverse_module_state->__pyx_n_s_BotDb); + Py_VISIT(traverse_module_state->__pyx_n_s_BotDb___reduce_cython); + Py_VISIT(traverse_module_state->__pyx_n_s_BotDb___setstate_cython); + Py_VISIT(traverse_module_state->__pyx_n_s_BotDb_change_data); + Py_VISIT(traverse_module_state->__pyx_n_s_BotDb_reading_db); + Py_VISIT(traverse_module_state->__pyx_kp_u_Created_new_file); + Py_VISIT(traverse_module_state->__pyx_kp_u_Error_reading_the_file); + Py_VISIT(traverse_module_state->__pyx_kp_u_Error_updating_the_file); + Py_VISIT(traverse_module_state->__pyx_kp_u_Error_writing_to_the_file); + Py_VISIT(traverse_module_state->__pyx_n_s_FileDB); + Py_VISIT(traverse_module_state->__pyx_n_s_FileDB___reduce_cython); + Py_VISIT(traverse_module_state->__pyx_n_s_FileDB___setstate_cython); + Py_VISIT(traverse_module_state->__pyx_n_s_FileDB_add_data); + Py_VISIT(traverse_module_state->__pyx_n_s_FileDB_new_data); + Py_VISIT(traverse_module_state->__pyx_n_s_FileDB_reading_db); + Py_VISIT(traverse_module_state->__pyx_n_s_FileNotFoundError); + Py_VISIT(traverse_module_state->__pyx_n_s_JSONDecodeError); + Py_VISIT(traverse_module_state->__pyx_kp_u_None); + Py_VISIT(traverse_module_state->__pyx_n_s_TypeError); + Py_VISIT(traverse_module_state->__pyx_n_s__19); + Py_VISIT(traverse_module_state->__pyx_n_s__2); + Py_VISIT(traverse_module_state->__pyx_n_s_add_data); + Py_VISIT(traverse_module_state->__pyx_n_u_ads); + Py_VISIT(traverse_module_state->__pyx_n_s_asyncio_coroutines); + Py_VISIT(traverse_module_state->__pyx_n_s_change_data); + Py_VISIT(traverse_module_state->__pyx_n_s_chmod); + Py_VISIT(traverse_module_state->__pyx_n_s_cline_in_traceback); + Py_VISIT(traverse_module_state->__pyx_n_s_cython_code_file_db); + Py_VISIT(traverse_module_state->__pyx_kp_s_cython_code_file_db_pyx); + Py_VISIT(traverse_module_state->__pyx_n_s_data); + Py_VISIT(traverse_module_state->__pyx_kp_u_disable); + Py_VISIT(traverse_module_state->__pyx_n_s_dump); + Py_VISIT(traverse_module_state->__pyx_kp_u_enable); + Py_VISIT(traverse_module_state->__pyx_n_s_enter); + Py_VISIT(traverse_module_state->__pyx_n_s_err); + Py_VISIT(traverse_module_state->__pyx_n_s_error); + Py_VISIT(traverse_module_state->__pyx_n_s_exit); + Py_VISIT(traverse_module_state->__pyx_n_s_file); + Py_VISIT(traverse_module_state->__pyx_kp_u_gc); + Py_VISIT(traverse_module_state->__pyx_n_s_getstate); + Py_VISIT(traverse_module_state->__pyx_n_s_import); + Py_VISIT(traverse_module_state->__pyx_n_s_info); + Py_VISIT(traverse_module_state->__pyx_n_s_initializing); + Py_VISIT(traverse_module_state->__pyx_n_s_is_coroutine); + Py_VISIT(traverse_module_state->__pyx_kp_u_isenabled); + Py_VISIT(traverse_module_state->__pyx_n_s_join_channel); + Py_VISIT(traverse_module_state->__pyx_n_u_join_channel); + Py_VISIT(traverse_module_state->__pyx_n_s_json); + Py_VISIT(traverse_module_state->__pyx_n_s_json_file); + Py_VISIT(traverse_module_state->__pyx_n_s_key); + Py_VISIT(traverse_module_state->__pyx_n_s_load); + Py_VISIT(traverse_module_state->__pyx_n_s_logging); + Py_VISIT(traverse_module_state->__pyx_n_s_main); + Py_VISIT(traverse_module_state->__pyx_n_s_name); + Py_VISIT(traverse_module_state->__pyx_n_s_new_data); + Py_VISIT(traverse_module_state->__pyx_kp_s_no_default___reduce___due_to_non); + Py_VISIT(traverse_module_state->__pyx_n_s_open); + Py_VISIT(traverse_module_state->__pyx_n_s_os); + Py_VISIT(traverse_module_state->__pyx_n_s_pyx_state); + Py_VISIT(traverse_module_state->__pyx_n_u_r); + Py_VISIT(traverse_module_state->__pyx_n_s_reading_db); + Py_VISIT(traverse_module_state->__pyx_n_s_reduce); + Py_VISIT(traverse_module_state->__pyx_n_s_reduce_cython); + Py_VISIT(traverse_module_state->__pyx_n_s_reduce_ex); + Py_VISIT(traverse_module_state->__pyx_n_s_self); + Py_VISIT(traverse_module_state->__pyx_n_s_setstate); + Py_VISIT(traverse_module_state->__pyx_n_s_setstate_cython); + Py_VISIT(traverse_module_state->__pyx_n_s_spec); + Py_VISIT(traverse_module_state->__pyx_kp_s_stringsource); + Py_VISIT(traverse_module_state->__pyx_n_s_test); + Py_VISIT(traverse_module_state->__pyx_n_u_w); + Py_VISIT(traverse_module_state->__pyx_kp_u_with_default_data); + Py_VISIT(traverse_module_state->__pyx_int_511); + Py_VISIT(traverse_module_state->__pyx_tuple_); + Py_VISIT(traverse_module_state->__pyx_tuple__3); + Py_VISIT(traverse_module_state->__pyx_tuple__5); + Py_VISIT(traverse_module_state->__pyx_tuple__7); + Py_VISIT(traverse_module_state->__pyx_tuple__9); + Py_VISIT(traverse_module_state->__pyx_tuple__11); + Py_VISIT(traverse_module_state->__pyx_tuple__13); + Py_VISIT(traverse_module_state->__pyx_tuple__15); + Py_VISIT(traverse_module_state->__pyx_codeobj__4); + Py_VISIT(traverse_module_state->__pyx_codeobj__6); + Py_VISIT(traverse_module_state->__pyx_codeobj__8); + Py_VISIT(traverse_module_state->__pyx_codeobj__10); + Py_VISIT(traverse_module_state->__pyx_codeobj__12); + Py_VISIT(traverse_module_state->__pyx_codeobj__14); + Py_VISIT(traverse_module_state->__pyx_codeobj__16); + Py_VISIT(traverse_module_state->__pyx_codeobj__17); + Py_VISIT(traverse_module_state->__pyx_codeobj__18); + return 0; +} +#endif +/* #### Code section: module_state_defines ### */ +#define __pyx_d __pyx_mstate_global->__pyx_d +#define __pyx_b __pyx_mstate_global->__pyx_b +#define __pyx_cython_runtime __pyx_mstate_global->__pyx_cython_runtime +#define __pyx_empty_tuple __pyx_mstate_global->__pyx_empty_tuple +#define __pyx_empty_bytes __pyx_mstate_global->__pyx_empty_bytes +#define __pyx_empty_unicode __pyx_mstate_global->__pyx_empty_unicode +#ifdef __Pyx_CyFunction_USED +#define __pyx_CyFunctionType __pyx_mstate_global->__pyx_CyFunctionType +#endif +#ifdef __Pyx_FusedFunction_USED +#define __pyx_FusedFunctionType __pyx_mstate_global->__pyx_FusedFunctionType +#endif +#ifdef __Pyx_Generator_USED +#define __pyx_GeneratorType __pyx_mstate_global->__pyx_GeneratorType +#endif +#ifdef __Pyx_IterableCoroutine_USED +#define __pyx_IterableCoroutineType __pyx_mstate_global->__pyx_IterableCoroutineType +#endif +#ifdef __Pyx_Coroutine_USED +#define __pyx_CoroutineAwaitType __pyx_mstate_global->__pyx_CoroutineAwaitType +#endif +#ifdef __Pyx_Coroutine_USED +#define __pyx_CoroutineType __pyx_mstate_global->__pyx_CoroutineType +#endif +#if CYTHON_USE_MODULE_STATE +#endif +#if CYTHON_USE_MODULE_STATE +#define __pyx_type_11cython_code_7file_db_BotDb __pyx_mstate_global->__pyx_type_11cython_code_7file_db_BotDb +#define __pyx_type_11cython_code_7file_db_FileDB __pyx_mstate_global->__pyx_type_11cython_code_7file_db_FileDB +#endif +#define __pyx_ptype_11cython_code_7file_db_BotDb __pyx_mstate_global->__pyx_ptype_11cython_code_7file_db_BotDb +#define __pyx_ptype_11cython_code_7file_db_FileDB __pyx_mstate_global->__pyx_ptype_11cython_code_7file_db_FileDB +#define __pyx_n_s_BotDb __pyx_mstate_global->__pyx_n_s_BotDb +#define __pyx_n_s_BotDb___reduce_cython __pyx_mstate_global->__pyx_n_s_BotDb___reduce_cython +#define __pyx_n_s_BotDb___setstate_cython __pyx_mstate_global->__pyx_n_s_BotDb___setstate_cython +#define __pyx_n_s_BotDb_change_data __pyx_mstate_global->__pyx_n_s_BotDb_change_data +#define __pyx_n_s_BotDb_reading_db __pyx_mstate_global->__pyx_n_s_BotDb_reading_db +#define __pyx_kp_u_Created_new_file __pyx_mstate_global->__pyx_kp_u_Created_new_file +#define __pyx_kp_u_Error_reading_the_file __pyx_mstate_global->__pyx_kp_u_Error_reading_the_file +#define __pyx_kp_u_Error_updating_the_file __pyx_mstate_global->__pyx_kp_u_Error_updating_the_file +#define __pyx_kp_u_Error_writing_to_the_file __pyx_mstate_global->__pyx_kp_u_Error_writing_to_the_file +#define __pyx_n_s_FileDB __pyx_mstate_global->__pyx_n_s_FileDB +#define __pyx_n_s_FileDB___reduce_cython __pyx_mstate_global->__pyx_n_s_FileDB___reduce_cython +#define __pyx_n_s_FileDB___setstate_cython __pyx_mstate_global->__pyx_n_s_FileDB___setstate_cython +#define __pyx_n_s_FileDB_add_data __pyx_mstate_global->__pyx_n_s_FileDB_add_data +#define __pyx_n_s_FileDB_new_data __pyx_mstate_global->__pyx_n_s_FileDB_new_data +#define __pyx_n_s_FileDB_reading_db __pyx_mstate_global->__pyx_n_s_FileDB_reading_db +#define __pyx_n_s_FileNotFoundError __pyx_mstate_global->__pyx_n_s_FileNotFoundError +#define __pyx_n_s_JSONDecodeError __pyx_mstate_global->__pyx_n_s_JSONDecodeError +#define __pyx_kp_u_None __pyx_mstate_global->__pyx_kp_u_None +#define __pyx_n_s_TypeError __pyx_mstate_global->__pyx_n_s_TypeError +#define __pyx_n_s__19 __pyx_mstate_global->__pyx_n_s__19 +#define __pyx_n_s__2 __pyx_mstate_global->__pyx_n_s__2 +#define __pyx_n_s_add_data __pyx_mstate_global->__pyx_n_s_add_data +#define __pyx_n_u_ads __pyx_mstate_global->__pyx_n_u_ads +#define __pyx_n_s_asyncio_coroutines __pyx_mstate_global->__pyx_n_s_asyncio_coroutines +#define __pyx_n_s_change_data __pyx_mstate_global->__pyx_n_s_change_data +#define __pyx_n_s_chmod __pyx_mstate_global->__pyx_n_s_chmod +#define __pyx_n_s_cline_in_traceback __pyx_mstate_global->__pyx_n_s_cline_in_traceback +#define __pyx_n_s_cython_code_file_db __pyx_mstate_global->__pyx_n_s_cython_code_file_db +#define __pyx_kp_s_cython_code_file_db_pyx __pyx_mstate_global->__pyx_kp_s_cython_code_file_db_pyx +#define __pyx_n_s_data __pyx_mstate_global->__pyx_n_s_data +#define __pyx_kp_u_disable __pyx_mstate_global->__pyx_kp_u_disable +#define __pyx_n_s_dump __pyx_mstate_global->__pyx_n_s_dump +#define __pyx_kp_u_enable __pyx_mstate_global->__pyx_kp_u_enable +#define __pyx_n_s_enter __pyx_mstate_global->__pyx_n_s_enter +#define __pyx_n_s_err __pyx_mstate_global->__pyx_n_s_err +#define __pyx_n_s_error __pyx_mstate_global->__pyx_n_s_error +#define __pyx_n_s_exit __pyx_mstate_global->__pyx_n_s_exit +#define __pyx_n_s_file __pyx_mstate_global->__pyx_n_s_file +#define __pyx_kp_u_gc __pyx_mstate_global->__pyx_kp_u_gc +#define __pyx_n_s_getstate __pyx_mstate_global->__pyx_n_s_getstate +#define __pyx_n_s_import __pyx_mstate_global->__pyx_n_s_import +#define __pyx_n_s_info __pyx_mstate_global->__pyx_n_s_info +#define __pyx_n_s_initializing __pyx_mstate_global->__pyx_n_s_initializing +#define __pyx_n_s_is_coroutine __pyx_mstate_global->__pyx_n_s_is_coroutine +#define __pyx_kp_u_isenabled __pyx_mstate_global->__pyx_kp_u_isenabled +#define __pyx_n_s_join_channel __pyx_mstate_global->__pyx_n_s_join_channel +#define __pyx_n_u_join_channel __pyx_mstate_global->__pyx_n_u_join_channel +#define __pyx_n_s_json __pyx_mstate_global->__pyx_n_s_json +#define __pyx_n_s_json_file __pyx_mstate_global->__pyx_n_s_json_file +#define __pyx_n_s_key __pyx_mstate_global->__pyx_n_s_key +#define __pyx_n_s_load __pyx_mstate_global->__pyx_n_s_load +#define __pyx_n_s_logging __pyx_mstate_global->__pyx_n_s_logging +#define __pyx_n_s_main __pyx_mstate_global->__pyx_n_s_main +#define __pyx_n_s_name __pyx_mstate_global->__pyx_n_s_name +#define __pyx_n_s_new_data __pyx_mstate_global->__pyx_n_s_new_data +#define __pyx_kp_s_no_default___reduce___due_to_non __pyx_mstate_global->__pyx_kp_s_no_default___reduce___due_to_non +#define __pyx_n_s_open __pyx_mstate_global->__pyx_n_s_open +#define __pyx_n_s_os __pyx_mstate_global->__pyx_n_s_os +#define __pyx_n_s_pyx_state __pyx_mstate_global->__pyx_n_s_pyx_state +#define __pyx_n_u_r __pyx_mstate_global->__pyx_n_u_r +#define __pyx_n_s_reading_db __pyx_mstate_global->__pyx_n_s_reading_db +#define __pyx_n_s_reduce __pyx_mstate_global->__pyx_n_s_reduce +#define __pyx_n_s_reduce_cython __pyx_mstate_global->__pyx_n_s_reduce_cython +#define __pyx_n_s_reduce_ex __pyx_mstate_global->__pyx_n_s_reduce_ex +#define __pyx_n_s_self __pyx_mstate_global->__pyx_n_s_self +#define __pyx_n_s_setstate __pyx_mstate_global->__pyx_n_s_setstate +#define __pyx_n_s_setstate_cython __pyx_mstate_global->__pyx_n_s_setstate_cython +#define __pyx_n_s_spec __pyx_mstate_global->__pyx_n_s_spec +#define __pyx_kp_s_stringsource __pyx_mstate_global->__pyx_kp_s_stringsource +#define __pyx_n_s_test __pyx_mstate_global->__pyx_n_s_test +#define __pyx_n_u_w __pyx_mstate_global->__pyx_n_u_w +#define __pyx_kp_u_with_default_data __pyx_mstate_global->__pyx_kp_u_with_default_data +#define __pyx_int_511 __pyx_mstate_global->__pyx_int_511 +#define __pyx_tuple_ __pyx_mstate_global->__pyx_tuple_ +#define __pyx_tuple__3 __pyx_mstate_global->__pyx_tuple__3 +#define __pyx_tuple__5 __pyx_mstate_global->__pyx_tuple__5 +#define __pyx_tuple__7 __pyx_mstate_global->__pyx_tuple__7 +#define __pyx_tuple__9 __pyx_mstate_global->__pyx_tuple__9 +#define __pyx_tuple__11 __pyx_mstate_global->__pyx_tuple__11 +#define __pyx_tuple__13 __pyx_mstate_global->__pyx_tuple__13 +#define __pyx_tuple__15 __pyx_mstate_global->__pyx_tuple__15 +#define __pyx_codeobj__4 __pyx_mstate_global->__pyx_codeobj__4 +#define __pyx_codeobj__6 __pyx_mstate_global->__pyx_codeobj__6 +#define __pyx_codeobj__8 __pyx_mstate_global->__pyx_codeobj__8 +#define __pyx_codeobj__10 __pyx_mstate_global->__pyx_codeobj__10 +#define __pyx_codeobj__12 __pyx_mstate_global->__pyx_codeobj__12 +#define __pyx_codeobj__14 __pyx_mstate_global->__pyx_codeobj__14 +#define __pyx_codeobj__16 __pyx_mstate_global->__pyx_codeobj__16 +#define __pyx_codeobj__17 __pyx_mstate_global->__pyx_codeobj__17 +#define __pyx_codeobj__18 __pyx_mstate_global->__pyx_codeobj__18 +/* #### Code section: module_code ### */ + +/* "cython_code/file_db.pyx":11 + * cdef dict json_data + * + * def __cinit__(self, str file): # <<<<<<<<<<<<<< + * self.file = file + * try: + */ + +/* Python wrapper */ +static int __pyx_pw_11cython_code_7file_db_5BotDb_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_11cython_code_7file_db_5BotDb_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_file = 0; + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[1] = {0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1; + #endif + __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_file,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_file)) != 0)) { + (void)__Pyx_Arg_NewRef_VARARGS(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 11, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__cinit__") < 0)) __PYX_ERR(0, 11, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 1)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0); + } + __pyx_v_file = ((PyObject*)values[0]); + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 11, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.file_db.BotDb.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_file), (&PyUnicode_Type), 1, "file", 1))) __PYX_ERR(0, 11, __pyx_L1_error) + __pyx_r = __pyx_pf_11cython_code_7file_db_5BotDb___cinit__(((struct __pyx_obj_11cython_code_7file_db_BotDb *)__pyx_v_self), __pyx_v_file); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_11cython_code_7file_db_5BotDb___cinit__(struct __pyx_obj_11cython_code_7file_db_BotDb *__pyx_v_self, PyObject *__pyx_v_file) { + PyObject *__pyx_v_json_file = NULL; + PyObject *__pyx_v_data = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + unsigned int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + int __pyx_t_14; + int __pyx_t_15; + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + int __pyx_t_18; + PyObject *__pyx_t_19 = NULL; + Py_ssize_t __pyx_t_20; + Py_UCS4 __pyx_t_21; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 1); + + /* "cython_code/file_db.pyx":12 + * + * def __cinit__(self, str file): + * self.file = file # <<<<<<<<<<<<<< + * try: + * with open(self.file, "r") as json_file: + */ + __Pyx_INCREF(__pyx_v_file); + __Pyx_GIVEREF(__pyx_v_file); + __Pyx_GOTREF(__pyx_v_self->file); + __Pyx_DECREF(__pyx_v_self->file); + __pyx_v_self->file = __pyx_v_file; + + /* "cython_code/file_db.pyx":13 + * def __cinit__(self, str file): + * self.file = file + * try: # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "cython_code/file_db.pyx":14 + * self.file = file + * try: + * with open(self.file, "r") as json_file: # <<<<<<<<<<<<<< + * self.json_data = json.load(json_file) + * except (FileNotFoundError, json.JSONDecodeError): + */ + /*with:*/ { + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 14, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_self->file); + __Pyx_GIVEREF(__pyx_v_self->file); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_self->file)) __PYX_ERR(0, 14, __pyx_L3_error); + __Pyx_INCREF(__pyx_n_u_r); + __Pyx_GIVEREF(__pyx_n_u_r); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_n_u_r)) __PYX_ERR(0, 14, __pyx_L3_error); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 14, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 14, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_enter); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 14, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_8, NULL}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_9, 0+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 14, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __pyx_t_7 = __pyx_t_4; + __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + /*try:*/ { + __pyx_v_json_file = __pyx_t_7; + __pyx_t_7 = 0; + + /* "cython_code/file_db.pyx":15 + * try: + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) # <<<<<<<<<<<<<< + * except (FileNotFoundError, json.JSONDecodeError): + * data = {"join_channel": False} + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_json); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 15, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_load); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 15, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_json_file}; + __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 15, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + if (!(likely(PyDict_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_7))) __PYX_ERR(0, 15, __pyx_L13_error) + __Pyx_GIVEREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_v_self->json_data); + __Pyx_DECREF(__pyx_v_self->json_data); + __pyx_v_self->json_data = ((PyObject*)__pyx_t_7); + __pyx_t_7 = 0; + + /* "cython_code/file_db.pyx":14 + * self.file = file + * try: + * with open(self.file, "r") as json_file: # <<<<<<<<<<<<<< + * self.json_data = json.load(json_file) + * except (FileNotFoundError, json.JSONDecodeError): + */ + } + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L18_try_end; + __pyx_L13_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + /*except:*/ { + __Pyx_AddTraceback("cython_code.file_db.BotDb.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 14, __pyx_L15_except_error) + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + __pyx_t_8 = PyTuple_Pack(3, __pyx_t_7, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 14, __pyx_L15_except_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 14, __pyx_L15_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (__pyx_t_14 < 0) __PYX_ERR(0, 14, __pyx_L15_except_error) + __pyx_t_15 = (!__pyx_t_14); + if (unlikely(__pyx_t_15)) { + __Pyx_GIVEREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_ErrRestoreWithState(__pyx_t_7, __pyx_t_4, __pyx_t_5); + __pyx_t_7 = 0; __pyx_t_4 = 0; __pyx_t_5 = 0; + __PYX_ERR(0, 14, __pyx_L15_except_error) + } + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L14_exception_handled; + } + __pyx_L15_except_error:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + goto __pyx_L3_error; + __pyx_L14_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + __pyx_L18_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_6) { + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 14, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + goto __pyx_L12; + } + __pyx_L12:; + } + goto __pyx_L22; + __pyx_L9_error:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L3_error; + __pyx_L22:; + } + + /* "cython_code/file_db.pyx":13 + * def __cinit__(self, str file): + * self.file = file + * try: # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) + */ + } + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L8_try_end; + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "cython_code/file_db.pyx":16 + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) + * except (FileNotFoundError, json.JSONDecodeError): # <<<<<<<<<<<<<< + * data = {"join_channel": False} + * with open(self.file, "w") as json_file: + */ + __Pyx_ErrFetch(&__pyx_t_5, &__pyx_t_4, &__pyx_t_7); + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_FileNotFoundError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 16, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_json); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 16, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_JSONDecodeError); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 16, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_18 = __Pyx_PyErr_GivenExceptionMatches2(__pyx_t_5, __pyx_t_8, __pyx_t_17); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_ErrRestore(__pyx_t_5, __pyx_t_4, __pyx_t_7); + __pyx_t_5 = 0; __pyx_t_4 = 0; __pyx_t_7 = 0; + if (__pyx_t_18) { + __Pyx_AddTraceback("cython_code.file_db.BotDb.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 16, __pyx_L5_except_error) + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + + /* "cython_code/file_db.pyx":17 + * self.json_data = json.load(json_file) + * except (FileNotFoundError, json.JSONDecodeError): + * data = {"join_channel": False} # <<<<<<<<<<<<<< + * with open(self.file, "w") as json_file: + * json.dump(data, json_file) + */ + __pyx_t_17 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 17, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_17); + if (PyDict_SetItem(__pyx_t_17, __pyx_n_u_join_channel, Py_False) < 0) __PYX_ERR(0, 17, __pyx_L5_except_error) + __pyx_v_data = ((PyObject*)__pyx_t_17); + __pyx_t_17 = 0; + + /* "cython_code/file_db.pyx":18 + * except (FileNotFoundError, json.JSONDecodeError): + * data = {"join_channel": False} + * with open(self.file, "w") as json_file: # <<<<<<<<<<<<<< + * json.dump(data, json_file) + * os.chmod(self.file, 0o777) + */ + /*with:*/ { + __pyx_t_17 = PyTuple_New(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 18, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_INCREF(__pyx_v_self->file); + __Pyx_GIVEREF(__pyx_v_self->file); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_v_self->file)) __PYX_ERR(0, 18, __pyx_L5_except_error); + __Pyx_INCREF(__pyx_n_u_w); + __Pyx_GIVEREF(__pyx_n_u_w); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_n_u_w)) __PYX_ERR(0, 18, __pyx_L5_except_error); + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_17, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 18, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_8, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 18, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_16 = __Pyx_PyObject_LookupSpecial(__pyx_t_8, __pyx_n_s_enter); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 18, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_19 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_16))) { + __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_16); + if (likely(__pyx_t_19)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16); + __Pyx_INCREF(__pyx_t_19); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_16, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_19, NULL}; + __pyx_t_17 = __Pyx_PyObject_FastCall(__pyx_t_16, __pyx_callargs+1-__pyx_t_9, 0+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 18, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + } + __pyx_t_16 = __pyx_t_17; + __pyx_t_17 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_12, &__pyx_t_11, &__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_10); + /*try:*/ { + __Pyx_XDECREF_SET(__pyx_v_json_file, __pyx_t_16); + __pyx_t_16 = 0; + + /* "cython_code/file_db.pyx":19 + * data = {"join_channel": False} + * with open(self.file, "w") as json_file: + * json.dump(data, json_file) # <<<<<<<<<<<<<< + * os.chmod(self.file, 0o777) + * with open(self.file, "r") as json_file: + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_json); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 19, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_dump); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 19, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_17))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_17); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_17); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_17, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[3] = {__pyx_t_8, __pyx_v_data, __pyx_v_json_file}; + __pyx_t_16 = __Pyx_PyObject_FastCall(__pyx_t_17, __pyx_callargs+1-__pyx_t_9, 2+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 19, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + } + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + + /* "cython_code/file_db.pyx":20 + * with open(self.file, "w") as json_file: + * json.dump(data, json_file) + * os.chmod(self.file, 0o777) # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) + */ + __Pyx_GetModuleGlobalName(__pyx_t_17, __pyx_n_s_os); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 20, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_17); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_17, __pyx_n_s_chmod); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 20, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_17 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_17)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_17); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[3] = {__pyx_t_17, __pyx_v_self->file, __pyx_int_511}; + __pyx_t_16 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_9, 2+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 20, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + + /* "cython_code/file_db.pyx":18 + * except (FileNotFoundError, json.JSONDecodeError): + * data = {"join_channel": False} + * with open(self.file, "w") as json_file: # <<<<<<<<<<<<<< + * json.dump(data, json_file) + * os.chmod(self.file, 0o777) + */ + } + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L38_try_end; + __pyx_L31_error:; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + /*except:*/ { + __Pyx_AddTraceback("cython_code.file_db.BotDb.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_16, &__pyx_t_8, &__pyx_t_17) < 0) __PYX_ERR(0, 18, __pyx_L33_except_error) + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_17); + __pyx_t_19 = PyTuple_Pack(3, __pyx_t_16, __pyx_t_8, __pyx_t_17); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 18, __pyx_L33_except_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_19, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 18, __pyx_L33_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (__pyx_t_15 < 0) __PYX_ERR(0, 18, __pyx_L33_except_error) + __pyx_t_14 = (!__pyx_t_15); + if (unlikely(__pyx_t_14)) { + __Pyx_GIVEREF(__pyx_t_16); + __Pyx_GIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_ErrRestoreWithState(__pyx_t_16, __pyx_t_8, __pyx_t_17); + __pyx_t_16 = 0; __pyx_t_8 = 0; __pyx_t_17 = 0; + __PYX_ERR(0, 18, __pyx_L33_except_error) + } + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + goto __pyx_L32_exception_handled; + } + __pyx_L33_except_error:; + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_11, __pyx_t_10); + goto __pyx_L5_except_error; + __pyx_L32_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_11, __pyx_t_10); + __pyx_L38_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_6) { + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 18, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + goto __pyx_L30; + } + __pyx_L30:; + } + goto __pyx_L42; + __pyx_L25_error:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L5_except_error; + __pyx_L42:; + } + + /* "cython_code/file_db.pyx":21 + * json.dump(data, json_file) + * os.chmod(self.file, 0o777) + * with open(self.file, "r") as json_file: # <<<<<<<<<<<<<< + * self.json_data = json.load(json_file) + * logging.info(f'Created new file: {file} with default data') + */ + /*with:*/ { + __pyx_t_17 = PyTuple_New(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 21, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_INCREF(__pyx_v_self->file); + __Pyx_GIVEREF(__pyx_v_self->file); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_v_self->file)) __PYX_ERR(0, 21, __pyx_L5_except_error); + __Pyx_INCREF(__pyx_n_u_r); + __Pyx_GIVEREF(__pyx_n_u_r); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_n_u_r)) __PYX_ERR(0, 21, __pyx_L5_except_error); + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_17, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 21, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_8, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 21, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_16 = __Pyx_PyObject_LookupSpecial(__pyx_t_8, __pyx_n_s_enter); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 21, __pyx_L43_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_19 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_16))) { + __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_16); + if (likely(__pyx_t_19)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16); + __Pyx_INCREF(__pyx_t_19); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_16, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_19, NULL}; + __pyx_t_17 = __Pyx_PyObject_FastCall(__pyx_t_16, __pyx_callargs+1-__pyx_t_9, 0+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 21, __pyx_L43_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + } + __pyx_t_16 = __pyx_t_17; + __pyx_t_17 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + /*try:*/ { + __Pyx_XDECREF_SET(__pyx_v_json_file, __pyx_t_16); + __pyx_t_16 = 0; + + /* "cython_code/file_db.pyx":22 + * os.chmod(self.file, 0o777) + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) # <<<<<<<<<<<<<< + * logging.info(f'Created new file: {file} with default data') + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_json); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 22, __pyx_L49_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_load); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 22, __pyx_L49_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_17))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_17); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_17); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_17, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_v_json_file}; + __pyx_t_16 = __Pyx_PyObject_FastCall(__pyx_t_17, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 22, __pyx_L49_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + } + if (!(likely(PyDict_CheckExact(__pyx_t_16))||((__pyx_t_16) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_16))) __PYX_ERR(0, 22, __pyx_L49_error) + __Pyx_GIVEREF(__pyx_t_16); + __Pyx_GOTREF(__pyx_v_self->json_data); + __Pyx_DECREF(__pyx_v_self->json_data); + __pyx_v_self->json_data = ((PyObject*)__pyx_t_16); + __pyx_t_16 = 0; + + /* "cython_code/file_db.pyx":21 + * json.dump(data, json_file) + * os.chmod(self.file, 0o777) + * with open(self.file, "r") as json_file: # <<<<<<<<<<<<<< + * self.json_data = json.load(json_file) + * logging.info(f'Created new file: {file} with default data') + */ + } + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L56_try_end; + __pyx_L49_error:; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + /*except:*/ { + __Pyx_AddTraceback("cython_code.file_db.BotDb.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_16, &__pyx_t_17, &__pyx_t_8) < 0) __PYX_ERR(0, 21, __pyx_L51_except_error) + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_8); + __pyx_t_19 = PyTuple_Pack(3, __pyx_t_16, __pyx_t_17, __pyx_t_8); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 21, __pyx_L51_except_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_19, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 21, __pyx_L51_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (__pyx_t_14 < 0) __PYX_ERR(0, 21, __pyx_L51_except_error) + __pyx_t_15 = (!__pyx_t_14); + if (unlikely(__pyx_t_15)) { + __Pyx_GIVEREF(__pyx_t_16); + __Pyx_GIVEREF(__pyx_t_17); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_ErrRestoreWithState(__pyx_t_16, __pyx_t_17, __pyx_t_8); + __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_8 = 0; + __PYX_ERR(0, 21, __pyx_L51_except_error) + } + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L50_exception_handled; + } + __pyx_L51_except_error:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + goto __pyx_L5_except_error; + __pyx_L50_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + __pyx_L56_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_6) { + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 21, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + goto __pyx_L48; + } + __pyx_L48:; + } + goto __pyx_L60; + __pyx_L43_error:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L5_except_error; + __pyx_L60:; + } + + /* "cython_code/file_db.pyx":23 + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) + * logging.info(f'Created new file: {file} with default data') # <<<<<<<<<<<<<< + * + * def reading_db(self): + */ + __Pyx_GetModuleGlobalName(__pyx_t_17, __pyx_n_s_logging); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 23, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_17); + __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_17, __pyx_n_s_info); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 23, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_17 = PyTuple_New(3); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 23, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_17); + __pyx_t_20 = 0; + __pyx_t_21 = 127; + __Pyx_INCREF(__pyx_kp_u_Created_new_file); + __pyx_t_20 += 18; + __Pyx_GIVEREF(__pyx_kp_u_Created_new_file); + PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_kp_u_Created_new_file); + __pyx_t_19 = __Pyx_PyUnicode_Unicode(__pyx_v_file); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 23, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_21 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_19) > __pyx_t_21) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_19) : __pyx_t_21; + __pyx_t_20 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_19); + __Pyx_GIVEREF(__pyx_t_19); + PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_t_19); + __pyx_t_19 = 0; + __Pyx_INCREF(__pyx_kp_u_with_default_data); + __pyx_t_20 += 18; + __Pyx_GIVEREF(__pyx_kp_u_with_default_data); + PyTuple_SET_ITEM(__pyx_t_17, 2, __pyx_kp_u_with_default_data); + __pyx_t_19 = __Pyx_PyUnicode_Join(__pyx_t_17, 3, __pyx_t_20, __pyx_t_21); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 23, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_17 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_16))) { + __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_16); + if (likely(__pyx_t_17)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16); + __Pyx_INCREF(__pyx_t_17); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_16, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_17, __pyx_t_19}; + __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_16, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 23, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L4_exception_handled; + } + goto __pyx_L5_except_error; + + /* "cython_code/file_db.pyx":13 + * def __cinit__(self, str file): + * self.file = file + * try: # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) + */ + __pyx_L5_except_error:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L4_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + __pyx_L8_try_end:; + } + + /* "cython_code/file_db.pyx":11 + * cdef dict json_data + * + * def __cinit__(self, str file): # <<<<<<<<<<<<<< + * self.file = file + * try: + */ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_16); + __Pyx_XDECREF(__pyx_t_17); + __Pyx_XDECREF(__pyx_t_19); + __Pyx_AddTraceback("cython_code.file_db.BotDb.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_json_file); + __Pyx_XDECREF(__pyx_v_data); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cython_code/file_db.pyx":25 + * logging.info(f'Created new file: {file} with default data') + * + * def reading_db(self): # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * return json.load(json_file) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_7file_db_5BotDb_3reading_db(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_7file_db_5BotDb_3reading_db = {"reading_db", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_5BotDb_3reading_db, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_7file_db_5BotDb_3reading_db(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("reading_db (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + if (unlikely(__pyx_nargs > 0)) { + __Pyx_RaiseArgtupleInvalid("reading_db", 1, 0, 0, __pyx_nargs); return NULL;} + if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "reading_db", 0))) return NULL; + __pyx_r = __pyx_pf_11cython_code_7file_db_5BotDb_2reading_db(((struct __pyx_obj_11cython_code_7file_db_BotDb *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_7file_db_5BotDb_2reading_db(struct __pyx_obj_11cython_code_7file_db_BotDb *__pyx_v_self) { + PyObject *__pyx_v_json_file = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + unsigned int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + int __pyx_t_12; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("reading_db", 1); + + /* "cython_code/file_db.pyx":26 + * + * def reading_db(self): + * with open(self.file, "r") as json_file: # <<<<<<<<<<<<<< + * return json.load(json_file) + * + */ + /*with:*/ { + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_self->file); + __Pyx_GIVEREF(__pyx_v_self->file); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->file)) __PYX_ERR(0, 26, __pyx_L1_error); + __Pyx_INCREF(__pyx_n_u_r); + __Pyx_GIVEREF(__pyx_n_u_r); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_n_u_r)) __PYX_ERR(0, 26, __pyx_L1_error); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 26, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_PyObject_LookupSpecial(__pyx_t_2, __pyx_n_s_exit); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 26, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_LookupSpecial(__pyx_t_2, __pyx_n_s_enter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 26, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + __pyx_t_6 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_6 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL}; + __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __pyx_t_4 = __pyx_t_1; + __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_9); + /*try:*/ { + __pyx_v_json_file = __pyx_t_4; + __pyx_t_4 = 0; + + /* "cython_code/file_db.pyx":27 + * def reading_db(self): + * with open(self.file, "r") as json_file: + * return json.load(json_file) # <<<<<<<<<<<<<< + * + * def change_data(self, bint join_channel): + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_json); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 27, __pyx_L7_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_load); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 27, __pyx_L7_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_6 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_6 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_2, __pyx_v_json_file}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_6, 1+__pyx_t_6); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 27, __pyx_L7_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L11_try_return; + + /* "cython_code/file_db.pyx":26 + * + * def reading_db(self): + * with open(self.file, "r") as json_file: # <<<<<<<<<<<<<< + * return json.load(json_file) + * + */ + } + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + /*except:*/ { + __Pyx_AddTraceback("cython_code.file_db.BotDb.reading_db", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_1, &__pyx_t_2) < 0) __PYX_ERR(0, 26, __pyx_L9_except_error) + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __pyx_t_5 = PyTuple_Pack(3, __pyx_t_4, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 26, __pyx_L9_except_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 26, __pyx_L9_except_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_10); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (__pyx_t_11 < 0) __PYX_ERR(0, 26, __pyx_L9_except_error) + __pyx_t_12 = (!__pyx_t_11); + if (unlikely(__pyx_t_12)) { + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_1, __pyx_t_2); + __pyx_t_4 = 0; __pyx_t_1 = 0; __pyx_t_2 = 0; + __PYX_ERR(0, 26, __pyx_L9_except_error) + } + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9); + goto __pyx_L1_error; + __pyx_L11_try_return:; + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9); + goto __pyx_L4_return; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9); + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_3) { + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 26, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + goto __pyx_L6; + } + __pyx_L4_return: { + __pyx_t_9 = __pyx_r; + __pyx_r = 0; + if (__pyx_t_3) { + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 26, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __pyx_r = __pyx_t_9; + __pyx_t_9 = 0; + goto __pyx_L0; + } + __pyx_L6:; + } + goto __pyx_L16; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L16:; + } + + /* "cython_code/file_db.pyx":25 + * logging.info(f'Created new file: {file} with default data') + * + * def reading_db(self): # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * return json.load(json_file) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("cython_code.file_db.BotDb.reading_db", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_json_file); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cython_code/file_db.pyx":29 + * return json.load(json_file) + * + * def change_data(self, bint join_channel): # <<<<<<<<<<<<<< + * self.json_data['join_channel'] = join_channel + * with open(self.file, "w") as json_file: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_7file_db_5BotDb_5change_data(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_7file_db_5BotDb_5change_data = {"change_data", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_5BotDb_5change_data, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_7file_db_5BotDb_5change_data(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + int __pyx_v_join_channel; + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[1] = {0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("change_data (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_join_channel,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_join_channel)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 29, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "change_data") < 0)) __PYX_ERR(0, 29, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 1)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + } + __pyx_v_join_channel = __Pyx_PyObject_IsTrue(values[0]); if (unlikely((__pyx_v_join_channel == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 29, __pyx_L3_error) + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("change_data", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 29, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.file_db.BotDb.change_data", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_11cython_code_7file_db_5BotDb_4change_data(((struct __pyx_obj_11cython_code_7file_db_BotDb *)__pyx_v_self), __pyx_v_join_channel); + + /* function exit code */ + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_7file_db_5BotDb_4change_data(struct __pyx_obj_11cython_code_7file_db_BotDb *__pyx_v_self, int __pyx_v_join_channel) { + PyObject *__pyx_v_json_file = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + unsigned int __pyx_t_6; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + int __pyx_t_11; + int __pyx_t_12; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("change_data", 1); + + /* "cython_code/file_db.pyx":30 + * + * def change_data(self, bint join_channel): + * self.json_data['join_channel'] = join_channel # <<<<<<<<<<<<<< + * with open(self.file, "w") as json_file: + * json.dump(self.json_data, json_file) + */ + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_join_channel); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 30, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (unlikely(__pyx_v_self->json_data == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 30, __pyx_L1_error) + } + if (unlikely((PyDict_SetItem(__pyx_v_self->json_data, __pyx_n_u_join_channel, __pyx_t_1) < 0))) __PYX_ERR(0, 30, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "cython_code/file_db.pyx":31 + * def change_data(self, bint join_channel): + * self.json_data['join_channel'] = join_channel + * with open(self.file, "w") as json_file: # <<<<<<<<<<<<<< + * json.dump(self.json_data, json_file) + * + */ + /*with:*/ { + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 31, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_self->file); + __Pyx_GIVEREF(__pyx_v_self->file); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->file)) __PYX_ERR(0, 31, __pyx_L1_error); + __Pyx_INCREF(__pyx_n_u_w); + __Pyx_GIVEREF(__pyx_n_u_w); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_n_u_w)) __PYX_ERR(0, 31, __pyx_L1_error); + __pyx_t_2 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_1, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_3 = __Pyx_PyObject_LookupSpecial(__pyx_t_2, __pyx_n_s_exit); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 31, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_LookupSpecial(__pyx_t_2, __pyx_n_s_enter); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 31, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + __pyx_t_6 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_6 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL}; + __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_6, 0+__pyx_t_6); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 31, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __pyx_t_4 = __pyx_t_1; + __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_7, &__pyx_t_8, &__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_9); + /*try:*/ { + __pyx_v_json_file = __pyx_t_4; + __pyx_t_4 = 0; + + /* "cython_code/file_db.pyx":32 + * self.json_data['join_channel'] = join_channel + * with open(self.file, "w") as json_file: + * json.dump(self.json_data, json_file) # <<<<<<<<<<<<<< + * + * cdef class FileDB: + */ + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_json); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 32, __pyx_L7_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_2, __pyx_n_s_dump); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 32, __pyx_L7_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = NULL; + __pyx_t_6 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_2 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_2)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_2); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_6 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[3] = {__pyx_t_2, __pyx_v_self->json_data, __pyx_v_json_file}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_6, 2+__pyx_t_6); + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 32, __pyx_L7_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "cython_code/file_db.pyx":31 + * def change_data(self, bint join_channel): + * self.json_data['join_channel'] = join_channel + * with open(self.file, "w") as json_file: # <<<<<<<<<<<<<< + * json.dump(self.json_data, json_file) + * + */ + } + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L12_try_end; + __pyx_L7_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + /*except:*/ { + __Pyx_AddTraceback("cython_code.file_db.BotDb.change_data", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_1, &__pyx_t_2) < 0) __PYX_ERR(0, 31, __pyx_L9_except_error) + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __pyx_t_5 = PyTuple_Pack(3, __pyx_t_4, __pyx_t_1, __pyx_t_2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 31, __pyx_L9_except_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_t_5, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 31, __pyx_L9_except_error) + __Pyx_GOTREF(__pyx_t_10); + __pyx_t_11 = __Pyx_PyObject_IsTrue(__pyx_t_10); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + if (__pyx_t_11 < 0) __PYX_ERR(0, 31, __pyx_L9_except_error) + __pyx_t_12 = (!__pyx_t_11); + if (unlikely(__pyx_t_12)) { + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_1, __pyx_t_2); + __pyx_t_4 = 0; __pyx_t_1 = 0; __pyx_t_2 = 0; + __PYX_ERR(0, 31, __pyx_L9_except_error) + } + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + goto __pyx_L8_exception_handled; + } + __pyx_L9_except_error:; + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9); + goto __pyx_L1_error; + __pyx_L8_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_ExceptionReset(__pyx_t_7, __pyx_t_8, __pyx_t_9); + __pyx_L12_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_3) { + __pyx_t_9 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 31, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + goto __pyx_L6; + } + __pyx_L6:; + } + goto __pyx_L16; + __pyx_L3_error:; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L1_error; + __pyx_L16:; + } + + /* "cython_code/file_db.pyx":29 + * return json.load(json_file) + * + * def change_data(self, bint join_channel): # <<<<<<<<<<<<<< + * self.json_data['join_channel'] = join_channel + * with open(self.file, "w") as json_file: + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("cython_code.file_db.BotDb.change_data", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_json_file); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_7file_db_5BotDb_7__reduce_cython__(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_7file_db_5BotDb_7__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_5BotDb_7__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_7file_db_5BotDb_7__reduce_cython__(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + if (unlikely(__pyx_nargs > 0)) { + __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;} + if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL; + __pyx_r = __pyx_pf_11cython_code_7file_db_5BotDb_6__reduce_cython__(((struct __pyx_obj_11cython_code_7file_db_BotDb *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_7file_db_5BotDb_6__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_11cython_code_7file_db_BotDb *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__reduce_cython__", 1); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + */ + __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_no_default___reduce___due_to_non, 0, 0); + __PYX_ERR(1, 2, __pyx_L1_error) + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("cython_code.file_db.BotDb.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_7file_db_5BotDb_9__setstate_cython__(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_7file_db_5BotDb_9__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_5BotDb_9__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_7file_db_5BotDb_9__setstate_cython__(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + CYTHON_UNUSED PyObject *__pyx_v___pyx_state = 0; + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[1] = {0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 3, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(1, 3, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 1)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + } + __pyx_v___pyx_state = values[0]; + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(1, 3, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.file_db.BotDb.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_11cython_code_7file_db_5BotDb_8__setstate_cython__(((struct __pyx_obj_11cython_code_7file_db_BotDb *)__pyx_v_self), __pyx_v___pyx_state); + + /* function exit code */ + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_7file_db_5BotDb_8__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_11cython_code_7file_db_BotDb *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__setstate_cython__", 1); + + /* "(tree fragment)":4 + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" # <<<<<<<<<<<<<< + */ + __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_no_default___reduce___due_to_non, 0, 0); + __PYX_ERR(1, 4, __pyx_L1_error) + + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("cython_code.file_db.BotDb.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cython_code/file_db.pyx":38 + * cdef dict json_data + * + * def __cinit__(self, str file): # <<<<<<<<<<<<<< + * self.file = file + * try: + */ + +/* Python wrapper */ +static int __pyx_pw_11cython_code_7file_db_6FileDB_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_11cython_code_7file_db_6FileDB_1__cinit__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_file = 0; + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[1] = {0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__cinit__ (wrapper)", 0); + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1; + #endif + __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_file,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_file)) != 0)) { + (void)__Pyx_Arg_NewRef_VARARGS(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 38, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__cinit__") < 0)) __PYX_ERR(0, 38, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 1)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0); + } + __pyx_v_file = ((PyObject*)values[0]); + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__cinit__", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 38, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.file_db.FileDB.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_file), (&PyUnicode_Type), 1, "file", 1))) __PYX_ERR(0, 38, __pyx_L1_error) + __pyx_r = __pyx_pf_11cython_code_7file_db_6FileDB___cinit__(((struct __pyx_obj_11cython_code_7file_db_FileDB *)__pyx_v_self), __pyx_v_file); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_11cython_code_7file_db_6FileDB___cinit__(struct __pyx_obj_11cython_code_7file_db_FileDB *__pyx_v_self, PyObject *__pyx_v_file) { + PyObject *__pyx_v_json_file = NULL; + PyObject *__pyx_v_data = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + unsigned int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + int __pyx_t_14; + int __pyx_t_15; + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + int __pyx_t_18; + PyObject *__pyx_t_19 = NULL; + Py_ssize_t __pyx_t_20; + Py_UCS4 __pyx_t_21; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__cinit__", 1); + + /* "cython_code/file_db.pyx":39 + * + * def __cinit__(self, str file): + * self.file = file # <<<<<<<<<<<<<< + * try: + * with open(self.file, "r") as json_file: + */ + __Pyx_INCREF(__pyx_v_file); + __Pyx_GIVEREF(__pyx_v_file); + __Pyx_GOTREF(__pyx_v_self->file); + __Pyx_DECREF(__pyx_v_self->file); + __pyx_v_self->file = __pyx_v_file; + + /* "cython_code/file_db.pyx":40 + * def __cinit__(self, str file): + * self.file = file + * try: # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "cython_code/file_db.pyx":41 + * self.file = file + * try: + * with open(self.file, "r") as json_file: # <<<<<<<<<<<<<< + * self.json_data = json.load(json_file) + * except (FileNotFoundError, json.JSONDecodeError): + */ + /*with:*/ { + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 41, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_self->file); + __Pyx_GIVEREF(__pyx_v_self->file); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_self->file)) __PYX_ERR(0, 41, __pyx_L3_error); + __Pyx_INCREF(__pyx_n_u_r); + __Pyx_GIVEREF(__pyx_n_u_r); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_n_u_r)) __PYX_ERR(0, 41, __pyx_L3_error); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 41, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 41, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_enter); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 41, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_8, NULL}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_9, 0+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 41, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __pyx_t_7 = __pyx_t_4; + __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + /*try:*/ { + __pyx_v_json_file = __pyx_t_7; + __pyx_t_7 = 0; + + /* "cython_code/file_db.pyx":42 + * try: + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) # <<<<<<<<<<<<<< + * except (FileNotFoundError, json.JSONDecodeError): + * data = {"ads": False, + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_json); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 42, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_load); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 42, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_json_file}; + __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 42, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + if (!(likely(PyDict_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_7))) __PYX_ERR(0, 42, __pyx_L13_error) + __Pyx_GIVEREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_v_self->json_data); + __Pyx_DECREF(__pyx_v_self->json_data); + __pyx_v_self->json_data = ((PyObject*)__pyx_t_7); + __pyx_t_7 = 0; + + /* "cython_code/file_db.pyx":41 + * self.file = file + * try: + * with open(self.file, "r") as json_file: # <<<<<<<<<<<<<< + * self.json_data = json.load(json_file) + * except (FileNotFoundError, json.JSONDecodeError): + */ + } + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L18_try_end; + __pyx_L13_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + /*except:*/ { + __Pyx_AddTraceback("cython_code.file_db.FileDB.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 41, __pyx_L15_except_error) + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + __pyx_t_8 = PyTuple_Pack(3, __pyx_t_7, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 41, __pyx_L15_except_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 41, __pyx_L15_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (__pyx_t_14 < 0) __PYX_ERR(0, 41, __pyx_L15_except_error) + __pyx_t_15 = (!__pyx_t_14); + if (unlikely(__pyx_t_15)) { + __Pyx_GIVEREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_ErrRestoreWithState(__pyx_t_7, __pyx_t_4, __pyx_t_5); + __pyx_t_7 = 0; __pyx_t_4 = 0; __pyx_t_5 = 0; + __PYX_ERR(0, 41, __pyx_L15_except_error) + } + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L14_exception_handled; + } + __pyx_L15_except_error:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + goto __pyx_L3_error; + __pyx_L14_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + __pyx_L18_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_6) { + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 41, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + goto __pyx_L12; + } + __pyx_L12:; + } + goto __pyx_L22; + __pyx_L9_error:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L3_error; + __pyx_L22:; + } + + /* "cython_code/file_db.pyx":40 + * def __cinit__(self, str file): + * self.file = file + * try: # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) + */ + } + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L8_try_end; + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "cython_code/file_db.pyx":43 + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) + * except (FileNotFoundError, json.JSONDecodeError): # <<<<<<<<<<<<<< + * data = {"ads": False, + * "join_channel": False} + */ + __Pyx_ErrFetch(&__pyx_t_5, &__pyx_t_4, &__pyx_t_7); + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_FileNotFoundError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 43, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_json); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 43, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_JSONDecodeError); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 43, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_18 = __Pyx_PyErr_GivenExceptionMatches2(__pyx_t_5, __pyx_t_8, __pyx_t_17); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_ErrRestore(__pyx_t_5, __pyx_t_4, __pyx_t_7); + __pyx_t_5 = 0; __pyx_t_4 = 0; __pyx_t_7 = 0; + if (__pyx_t_18) { + __Pyx_AddTraceback("cython_code.file_db.FileDB.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 43, __pyx_L5_except_error) + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + + /* "cython_code/file_db.pyx":44 + * self.json_data = json.load(json_file) + * except (FileNotFoundError, json.JSONDecodeError): + * data = {"ads": False, # <<<<<<<<<<<<<< + * "join_channel": False} + * with open(self.file, "w") as json_file: + */ + __pyx_t_17 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 44, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_17); + if (PyDict_SetItem(__pyx_t_17, __pyx_n_u_ads, Py_False) < 0) __PYX_ERR(0, 44, __pyx_L5_except_error) + + /* "cython_code/file_db.pyx":45 + * except (FileNotFoundError, json.JSONDecodeError): + * data = {"ads": False, + * "join_channel": False} # <<<<<<<<<<<<<< + * with open(self.file, "w") as json_file: + * json.dump(data, json_file) + */ + if (PyDict_SetItem(__pyx_t_17, __pyx_n_u_join_channel, Py_False) < 0) __PYX_ERR(0, 44, __pyx_L5_except_error) + __pyx_v_data = ((PyObject*)__pyx_t_17); + __pyx_t_17 = 0; + + /* "cython_code/file_db.pyx":46 + * data = {"ads": False, + * "join_channel": False} + * with open(self.file, "w") as json_file: # <<<<<<<<<<<<<< + * json.dump(data, json_file) + * os.chmod(self.file, 0o777) + */ + /*with:*/ { + __pyx_t_17 = PyTuple_New(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 46, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_INCREF(__pyx_v_self->file); + __Pyx_GIVEREF(__pyx_v_self->file); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_v_self->file)) __PYX_ERR(0, 46, __pyx_L5_except_error); + __Pyx_INCREF(__pyx_n_u_w); + __Pyx_GIVEREF(__pyx_n_u_w); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_n_u_w)) __PYX_ERR(0, 46, __pyx_L5_except_error); + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_17, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 46, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_8, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 46, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_16 = __Pyx_PyObject_LookupSpecial(__pyx_t_8, __pyx_n_s_enter); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 46, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_19 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_16))) { + __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_16); + if (likely(__pyx_t_19)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16); + __Pyx_INCREF(__pyx_t_19); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_16, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_19, NULL}; + __pyx_t_17 = __Pyx_PyObject_FastCall(__pyx_t_16, __pyx_callargs+1-__pyx_t_9, 0+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 46, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + } + __pyx_t_16 = __pyx_t_17; + __pyx_t_17 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_12, &__pyx_t_11, &__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_10); + /*try:*/ { + __Pyx_XDECREF_SET(__pyx_v_json_file, __pyx_t_16); + __pyx_t_16 = 0; + + /* "cython_code/file_db.pyx":47 + * "join_channel": False} + * with open(self.file, "w") as json_file: + * json.dump(data, json_file) # <<<<<<<<<<<<<< + * os.chmod(self.file, 0o777) + * with open(self.file, "r") as json_file: + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_json); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 47, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_dump); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 47, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_17))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_17); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_17); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_17, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[3] = {__pyx_t_8, __pyx_v_data, __pyx_v_json_file}; + __pyx_t_16 = __Pyx_PyObject_FastCall(__pyx_t_17, __pyx_callargs+1-__pyx_t_9, 2+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 47, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + } + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + + /* "cython_code/file_db.pyx":48 + * with open(self.file, "w") as json_file: + * json.dump(data, json_file) + * os.chmod(self.file, 0o777) # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) + */ + __Pyx_GetModuleGlobalName(__pyx_t_17, __pyx_n_s_os); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 48, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_17); + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_17, __pyx_n_s_chmod); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 48, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_17 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_8))) { + __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_8); + if (likely(__pyx_t_17)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_8); + __Pyx_INCREF(__pyx_t_17); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_8, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[3] = {__pyx_t_17, __pyx_v_self->file, __pyx_int_511}; + __pyx_t_16 = __Pyx_PyObject_FastCall(__pyx_t_8, __pyx_callargs+1-__pyx_t_9, 2+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 48, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + + /* "cython_code/file_db.pyx":46 + * data = {"ads": False, + * "join_channel": False} + * with open(self.file, "w") as json_file: # <<<<<<<<<<<<<< + * json.dump(data, json_file) + * os.chmod(self.file, 0o777) + */ + } + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L38_try_end; + __pyx_L31_error:; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + /*except:*/ { + __Pyx_AddTraceback("cython_code.file_db.FileDB.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_16, &__pyx_t_8, &__pyx_t_17) < 0) __PYX_ERR(0, 46, __pyx_L33_except_error) + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_17); + __pyx_t_19 = PyTuple_Pack(3, __pyx_t_16, __pyx_t_8, __pyx_t_17); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 46, __pyx_L33_except_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_19, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 46, __pyx_L33_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (__pyx_t_15 < 0) __PYX_ERR(0, 46, __pyx_L33_except_error) + __pyx_t_14 = (!__pyx_t_15); + if (unlikely(__pyx_t_14)) { + __Pyx_GIVEREF(__pyx_t_16); + __Pyx_GIVEREF(__pyx_t_8); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_ErrRestoreWithState(__pyx_t_16, __pyx_t_8, __pyx_t_17); + __pyx_t_16 = 0; __pyx_t_8 = 0; __pyx_t_17 = 0; + __PYX_ERR(0, 46, __pyx_L33_except_error) + } + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + goto __pyx_L32_exception_handled; + } + __pyx_L33_except_error:; + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_11, __pyx_t_10); + goto __pyx_L5_except_error; + __pyx_L32_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_11, __pyx_t_10); + __pyx_L38_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_6) { + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 46, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + goto __pyx_L30; + } + __pyx_L30:; + } + goto __pyx_L42; + __pyx_L25_error:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L5_except_error; + __pyx_L42:; + } + + /* "cython_code/file_db.pyx":49 + * json.dump(data, json_file) + * os.chmod(self.file, 0o777) + * with open(self.file, "r") as json_file: # <<<<<<<<<<<<<< + * self.json_data = json.load(json_file) + * logging.info(f'Created new file: {file} with default data') + */ + /*with:*/ { + __pyx_t_17 = PyTuple_New(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 49, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_INCREF(__pyx_v_self->file); + __Pyx_GIVEREF(__pyx_v_self->file); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_v_self->file)) __PYX_ERR(0, 49, __pyx_L5_except_error); + __Pyx_INCREF(__pyx_n_u_r); + __Pyx_GIVEREF(__pyx_n_u_r); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_n_u_r)) __PYX_ERR(0, 49, __pyx_L5_except_error); + __pyx_t_8 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_17, NULL); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 49, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_8, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 49, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_16 = __Pyx_PyObject_LookupSpecial(__pyx_t_8, __pyx_n_s_enter); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 49, __pyx_L43_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_19 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_16))) { + __pyx_t_19 = PyMethod_GET_SELF(__pyx_t_16); + if (likely(__pyx_t_19)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16); + __Pyx_INCREF(__pyx_t_19); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_16, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_19, NULL}; + __pyx_t_17 = __Pyx_PyObject_FastCall(__pyx_t_16, __pyx_callargs+1-__pyx_t_9, 0+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 49, __pyx_L43_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + } + __pyx_t_16 = __pyx_t_17; + __pyx_t_17 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + /*try:*/ { + __Pyx_XDECREF_SET(__pyx_v_json_file, __pyx_t_16); + __pyx_t_16 = 0; + + /* "cython_code/file_db.pyx":50 + * os.chmod(self.file, 0o777) + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) # <<<<<<<<<<<<<< + * logging.info(f'Created new file: {file} with default data') + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_json); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 50, __pyx_L49_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_load); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 50, __pyx_L49_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_17))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_17); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_17); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_17, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_8, __pyx_v_json_file}; + __pyx_t_16 = __Pyx_PyObject_FastCall(__pyx_t_17, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 50, __pyx_L49_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + } + if (!(likely(PyDict_CheckExact(__pyx_t_16))||((__pyx_t_16) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_16))) __PYX_ERR(0, 50, __pyx_L49_error) + __Pyx_GIVEREF(__pyx_t_16); + __Pyx_GOTREF(__pyx_v_self->json_data); + __Pyx_DECREF(__pyx_v_self->json_data); + __pyx_v_self->json_data = ((PyObject*)__pyx_t_16); + __pyx_t_16 = 0; + + /* "cython_code/file_db.pyx":49 + * json.dump(data, json_file) + * os.chmod(self.file, 0o777) + * with open(self.file, "r") as json_file: # <<<<<<<<<<<<<< + * self.json_data = json.load(json_file) + * logging.info(f'Created new file: {file} with default data') + */ + } + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L56_try_end; + __pyx_L49_error:; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + /*except:*/ { + __Pyx_AddTraceback("cython_code.file_db.FileDB.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_16, &__pyx_t_17, &__pyx_t_8) < 0) __PYX_ERR(0, 49, __pyx_L51_except_error) + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_8); + __pyx_t_19 = PyTuple_Pack(3, __pyx_t_16, __pyx_t_17, __pyx_t_8); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 49, __pyx_L51_except_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_19, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 49, __pyx_L51_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (__pyx_t_14 < 0) __PYX_ERR(0, 49, __pyx_L51_except_error) + __pyx_t_15 = (!__pyx_t_14); + if (unlikely(__pyx_t_15)) { + __Pyx_GIVEREF(__pyx_t_16); + __Pyx_GIVEREF(__pyx_t_17); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_ErrRestoreWithState(__pyx_t_16, __pyx_t_17, __pyx_t_8); + __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_8 = 0; + __PYX_ERR(0, 49, __pyx_L51_except_error) + } + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L50_exception_handled; + } + __pyx_L51_except_error:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + goto __pyx_L5_except_error; + __pyx_L50_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + __pyx_L56_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_6) { + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 49, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + goto __pyx_L48; + } + __pyx_L48:; + } + goto __pyx_L60; + __pyx_L43_error:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L5_except_error; + __pyx_L60:; + } + + /* "cython_code/file_db.pyx":51 + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) + * logging.info(f'Created new file: {file} with default data') # <<<<<<<<<<<<<< + * + * def reading_db(self): + */ + __Pyx_GetModuleGlobalName(__pyx_t_17, __pyx_n_s_logging); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 51, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_17); + __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_17, __pyx_n_s_info); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 51, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_17 = PyTuple_New(3); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 51, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_17); + __pyx_t_20 = 0; + __pyx_t_21 = 127; + __Pyx_INCREF(__pyx_kp_u_Created_new_file); + __pyx_t_20 += 18; + __Pyx_GIVEREF(__pyx_kp_u_Created_new_file); + PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_kp_u_Created_new_file); + __pyx_t_19 = __Pyx_PyUnicode_Unicode(__pyx_v_file); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 51, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_21 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_19) > __pyx_t_21) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_19) : __pyx_t_21; + __pyx_t_20 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_19); + __Pyx_GIVEREF(__pyx_t_19); + PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_t_19); + __pyx_t_19 = 0; + __Pyx_INCREF(__pyx_kp_u_with_default_data); + __pyx_t_20 += 18; + __Pyx_GIVEREF(__pyx_kp_u_with_default_data); + PyTuple_SET_ITEM(__pyx_t_17, 2, __pyx_kp_u_with_default_data); + __pyx_t_19 = __Pyx_PyUnicode_Join(__pyx_t_17, 3, __pyx_t_20, __pyx_t_21); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 51, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_17 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_16))) { + __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_16); + if (likely(__pyx_t_17)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16); + __Pyx_INCREF(__pyx_t_17); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_16, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_17, __pyx_t_19}; + __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_16, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 51, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L4_exception_handled; + } + goto __pyx_L5_except_error; + + /* "cython_code/file_db.pyx":40 + * def __cinit__(self, str file): + * self.file = file + * try: # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) + */ + __pyx_L5_except_error:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L4_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + __pyx_L8_try_end:; + } + + /* "cython_code/file_db.pyx":38 + * cdef dict json_data + * + * def __cinit__(self, str file): # <<<<<<<<<<<<<< + * self.file = file + * try: + */ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_16); + __Pyx_XDECREF(__pyx_t_17); + __Pyx_XDECREF(__pyx_t_19); + __Pyx_AddTraceback("cython_code.file_db.FileDB.__cinit__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_json_file); + __Pyx_XDECREF(__pyx_v_data); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cython_code/file_db.pyx":53 + * logging.info(f'Created new file: {file} with default data') + * + * def reading_db(self): # <<<<<<<<<<<<<< + * try: + * with open(self.file, "r") as json_file: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_7file_db_6FileDB_3reading_db(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_7file_db_6FileDB_3reading_db = {"reading_db", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_6FileDB_3reading_db, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_7file_db_6FileDB_3reading_db(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("reading_db (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + if (unlikely(__pyx_nargs > 0)) { + __Pyx_RaiseArgtupleInvalid("reading_db", 1, 0, 0, __pyx_nargs); return NULL;} + if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "reading_db", 0))) return NULL; + __pyx_r = __pyx_pf_11cython_code_7file_db_6FileDB_2reading_db(((struct __pyx_obj_11cython_code_7file_db_FileDB *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_7file_db_6FileDB_2reading_db(struct __pyx_obj_11cython_code_7file_db_FileDB *__pyx_v_self) { + PyObject *__pyx_v_json_file = NULL; + PyObject *__pyx_v_err = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + unsigned int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + int __pyx_t_14; + int __pyx_t_15; + int __pyx_t_16; + PyObject *__pyx_t_17 = NULL; + PyObject *__pyx_t_18 = NULL; + PyObject *__pyx_t_19 = NULL; + int __pyx_t_20; + char const *__pyx_t_21; + PyObject *__pyx_t_22 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("reading_db", 1); + + /* "cython_code/file_db.pyx":54 + * + * def reading_db(self): + * try: # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * return json.load(json_file) + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "cython_code/file_db.pyx":55 + * def reading_db(self): + * try: + * with open(self.file, "r") as json_file: # <<<<<<<<<<<<<< + * return json.load(json_file) + * except Exception as err: + */ + /*with:*/ { + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 55, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_self->file); + __Pyx_GIVEREF(__pyx_v_self->file); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_self->file)) __PYX_ERR(0, 55, __pyx_L3_error); + __Pyx_INCREF(__pyx_n_u_r); + __Pyx_GIVEREF(__pyx_n_u_r); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_n_u_r)) __PYX_ERR(0, 55, __pyx_L3_error); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 55, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 55, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_enter); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 55, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_8, NULL}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_9, 0+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 55, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __pyx_t_7 = __pyx_t_4; + __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + /*try:*/ { + __pyx_v_json_file = __pyx_t_7; + __pyx_t_7 = 0; + + /* "cython_code/file_db.pyx":56 + * try: + * with open(self.file, "r") as json_file: + * return json.load(json_file) # <<<<<<<<<<<<<< + * except Exception as err: + * logging.info(f'Error reading the file: {err}') + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_json); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 56, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_load); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 56, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_json_file}; + __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 56, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __pyx_r = __pyx_t_7; + __pyx_t_7 = 0; + goto __pyx_L17_try_return; + + /* "cython_code/file_db.pyx":55 + * def reading_db(self): + * try: + * with open(self.file, "r") as json_file: # <<<<<<<<<<<<<< + * return json.load(json_file) + * except Exception as err: + */ + } + __pyx_L13_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + /*except:*/ { + __Pyx_AddTraceback("cython_code.file_db.FileDB.reading_db", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 55, __pyx_L15_except_error) + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + __pyx_t_8 = PyTuple_Pack(3, __pyx_t_7, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 55, __pyx_L15_except_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 55, __pyx_L15_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (__pyx_t_14 < 0) __PYX_ERR(0, 55, __pyx_L15_except_error) + __pyx_t_15 = (!__pyx_t_14); + if (unlikely(__pyx_t_15)) { + __Pyx_GIVEREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_ErrRestoreWithState(__pyx_t_7, __pyx_t_4, __pyx_t_5); + __pyx_t_7 = 0; __pyx_t_4 = 0; __pyx_t_5 = 0; + __PYX_ERR(0, 55, __pyx_L15_except_error) + } + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L14_exception_handled; + } + __pyx_L15_except_error:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + goto __pyx_L3_error; + __pyx_L17_try_return:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + goto __pyx_L10_return; + __pyx_L14_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_6) { + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 55, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + goto __pyx_L12; + } + __pyx_L10_return: { + __pyx_t_12 = __pyx_r; + __pyx_r = 0; + if (__pyx_t_6) { + __pyx_t_11 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 55, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __pyx_r = __pyx_t_12; + __pyx_t_12 = 0; + goto __pyx_L7_try_return; + } + __pyx_L12:; + } + goto __pyx_L22; + __pyx_L9_error:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L3_error; + __pyx_L22:; + } + + /* "cython_code/file_db.pyx":54 + * + * def reading_db(self): + * try: # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * return json.load(json_file) + */ + } + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L8_try_end; + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "cython_code/file_db.pyx":57 + * with open(self.file, "r") as json_file: + * return json.load(json_file) + * except Exception as err: # <<<<<<<<<<<<<< + * logging.info(f'Error reading the file: {err}') + * + */ + __pyx_t_16 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); + if (__pyx_t_16) { + __Pyx_AddTraceback("cython_code.file_db.FileDB.reading_db", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_4, &__pyx_t_7) < 0) __PYX_ERR(0, 57, __pyx_L5_except_error) + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_4); + __pyx_v_err = __pyx_t_4; + /*try:*/ { + + /* "cython_code/file_db.pyx":58 + * return json.load(json_file) + * except Exception as err: + * logging.info(f'Error reading the file: {err}') # <<<<<<<<<<<<<< + * + * def add_data(self, data, str key): + */ + __Pyx_GetModuleGlobalName(__pyx_t_17, __pyx_n_s_logging); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 58, __pyx_L28_error) + __Pyx_GOTREF(__pyx_t_17); + __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_t_17, __pyx_n_s_info); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 58, __pyx_L28_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_17 = __Pyx_PyObject_FormatSimple(__pyx_v_err, __pyx_empty_unicode); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 58, __pyx_L28_error) + __Pyx_GOTREF(__pyx_t_17); + __pyx_t_19 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Error_reading_the_file, __pyx_t_17); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 58, __pyx_L28_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_17 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_18))) { + __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_18); + if (likely(__pyx_t_17)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_18); + __Pyx_INCREF(__pyx_t_17); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_18, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_17, __pyx_t_19}; + __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_18, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 58, __pyx_L28_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + + /* "cython_code/file_db.pyx":57 + * with open(self.file, "r") as json_file: + * return json.load(json_file) + * except Exception as err: # <<<<<<<<<<<<<< + * logging.info(f'Error reading the file: {err}') + * + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + goto __pyx_L29; + } + __pyx_L28_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_6 = 0; __pyx_t_12 = 0; __pyx_t_11 = 0; __pyx_t_10 = 0; __pyx_t_13 = 0; __pyx_t_22 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_10, &__pyx_t_13, &__pyx_t_22); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_6, &__pyx_t_12, &__pyx_t_11) < 0)) __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_12, &__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_13); + __Pyx_XGOTREF(__pyx_t_22); + __pyx_t_16 = __pyx_lineno; __pyx_t_20 = __pyx_clineno; __pyx_t_21 = __pyx_filename; + { + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_XGIVEREF(__pyx_t_22); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_13, __pyx_t_22); + } + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ErrRestore(__pyx_t_6, __pyx_t_12, __pyx_t_11); + __pyx_t_6 = 0; __pyx_t_12 = 0; __pyx_t_11 = 0; __pyx_t_10 = 0; __pyx_t_13 = 0; __pyx_t_22 = 0; + __pyx_lineno = __pyx_t_16; __pyx_clineno = __pyx_t_20; __pyx_filename = __pyx_t_21; + goto __pyx_L5_except_error; + } + __pyx_L29:; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L4_exception_handled; + } + goto __pyx_L5_except_error; + + /* "cython_code/file_db.pyx":54 + * + * def reading_db(self): + * try: # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * return json.load(json_file) + */ + __pyx_L5_except_error:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L7_try_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; + __pyx_L4_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + __pyx_L8_try_end:; + } + + /* "cython_code/file_db.pyx":53 + * logging.info(f'Created new file: {file} with default data') + * + * def reading_db(self): # <<<<<<<<<<<<<< + * try: + * with open(self.file, "r") as json_file: + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_17); + __Pyx_XDECREF(__pyx_t_18); + __Pyx_XDECREF(__pyx_t_19); + __Pyx_AddTraceback("cython_code.file_db.FileDB.reading_db", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_json_file); + __Pyx_XDECREF(__pyx_v_err); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cython_code/file_db.pyx":60 + * logging.info(f'Error reading the file: {err}') + * + * def add_data(self, data, str key): # <<<<<<<<<<<<<< + * try: + * with open(self.file, "r") as json_file: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_7file_db_6FileDB_5add_data(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_7file_db_6FileDB_5add_data = {"add_data", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_6FileDB_5add_data, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_7file_db_6FileDB_5add_data(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + PyObject *__pyx_v_data = 0; + PyObject *__pyx_v_key = 0; + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[2] = {0,0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("add_data (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_data,&__pyx_n_s_key,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_data)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 60, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_key)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[1]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 60, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("add_data", 1, 2, 2, 1); __PYX_ERR(0, 60, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "add_data") < 0)) __PYX_ERR(0, 60, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 2)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + } + __pyx_v_data = values[0]; + __pyx_v_key = ((PyObject*)values[1]); + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("add_data", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 60, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.file_db.FileDB.add_data", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_key), (&PyUnicode_Type), 1, "key", 1))) __PYX_ERR(0, 60, __pyx_L1_error) + __pyx_r = __pyx_pf_11cython_code_7file_db_6FileDB_4add_data(((struct __pyx_obj_11cython_code_7file_db_FileDB *)__pyx_v_self), __pyx_v_data, __pyx_v_key); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_7file_db_6FileDB_4add_data(struct __pyx_obj_11cython_code_7file_db_FileDB *__pyx_v_self, PyObject *__pyx_v_data, PyObject *__pyx_v_key) { + PyObject *__pyx_v_json_file = NULL; + PyObject *__pyx_v_err = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + unsigned int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + int __pyx_t_18; + int __pyx_t_19; + int __pyx_t_20; + PyObject *__pyx_t_21 = NULL; + PyObject *__pyx_t_22 = NULL; + PyObject *__pyx_t_23 = NULL; + int __pyx_t_24; + char const *__pyx_t_25; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("add_data", 1); + + /* "cython_code/file_db.pyx":61 + * + * def add_data(self, data, str key): + * try: # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "cython_code/file_db.pyx":62 + * def add_data(self, data, str key): + * try: + * with open(self.file, "r") as json_file: # <<<<<<<<<<<<<< + * self.json_data = json.load(json_file) + * self.json_data[str(key)] = data + */ + /*with:*/ { + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 62, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_self->file); + __Pyx_GIVEREF(__pyx_v_self->file); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_self->file)) __PYX_ERR(0, 62, __pyx_L3_error); + __Pyx_INCREF(__pyx_n_u_r); + __Pyx_GIVEREF(__pyx_n_u_r); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_n_u_r)) __PYX_ERR(0, 62, __pyx_L3_error); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 62, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 62, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_enter); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 62, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_8, NULL}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_9, 0+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 62, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __pyx_t_7 = __pyx_t_4; + __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + /*try:*/ { + __pyx_v_json_file = __pyx_t_7; + __pyx_t_7 = 0; + + /* "cython_code/file_db.pyx":63 + * try: + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) # <<<<<<<<<<<<<< + * self.json_data[str(key)] = data + * with open(self.file, "w") as json_file: + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_json); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 63, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_load); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 63, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_json_file}; + __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 63, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + if (!(likely(PyDict_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_7))) __PYX_ERR(0, 63, __pyx_L13_error) + __Pyx_GIVEREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_v_self->json_data); + __Pyx_DECREF(__pyx_v_self->json_data); + __pyx_v_self->json_data = ((PyObject*)__pyx_t_7); + __pyx_t_7 = 0; + + /* "cython_code/file_db.pyx":64 + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) + * self.json_data[str(key)] = data # <<<<<<<<<<<<<< + * with open(self.file, "w") as json_file: + * json.dump(self.json_data, json_file) + */ + if (unlikely(__pyx_v_self->json_data == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 64, __pyx_L13_error) + } + __pyx_t_7 = __Pyx_PyUnicode_Unicode(__pyx_v_key); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 64, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_7); + if (unlikely((PyDict_SetItem(__pyx_v_self->json_data, __pyx_t_7, __pyx_v_data) < 0))) __PYX_ERR(0, 64, __pyx_L13_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "cython_code/file_db.pyx":65 + * self.json_data = json.load(json_file) + * self.json_data[str(key)] = data + * with open(self.file, "w") as json_file: # <<<<<<<<<<<<<< + * json.dump(self.json_data, json_file) + * except Exception as err: + */ + /*with:*/ { + __pyx_t_7 = PyTuple_New(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 65, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_v_self->file); + __Pyx_GIVEREF(__pyx_v_self->file); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 0, __pyx_v_self->file)) __PYX_ERR(0, 65, __pyx_L13_error); + __Pyx_INCREF(__pyx_n_u_w); + __Pyx_GIVEREF(__pyx_n_u_w); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_7, 1, __pyx_n_u_w)) __PYX_ERR(0, 65, __pyx_L13_error); + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_7, NULL); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 65, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_13 = __Pyx_PyObject_LookupSpecial(__pyx_t_4, __pyx_n_s_exit); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 65, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_5 = __Pyx_PyObject_LookupSpecial(__pyx_t_4, __pyx_n_s_enter); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 65, __pyx_L19_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_8, NULL}; + __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_9, 0+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 65, __pyx_L19_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __pyx_t_5 = __pyx_t_7; + __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_16); + /*try:*/ { + __Pyx_DECREF_SET(__pyx_v_json_file, __pyx_t_5); + __pyx_t_5 = 0; + + /* "cython_code/file_db.pyx":66 + * self.json_data[str(key)] = data + * with open(self.file, "w") as json_file: + * json.dump(self.json_data, json_file) # <<<<<<<<<<<<<< + * except Exception as err: + * logging.error(f'Error updating the file: {err}') + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_json); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 66, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_dump); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 66, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[3] = {__pyx_t_4, __pyx_v_self->json_data, __pyx_v_json_file}; + __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_9, 2+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 66, __pyx_L23_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "cython_code/file_db.pyx":65 + * self.json_data = json.load(json_file) + * self.json_data[str(key)] = data + * with open(self.file, "w") as json_file: # <<<<<<<<<<<<<< + * json.dump(self.json_data, json_file) + * except Exception as err: + */ + } + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + goto __pyx_L28_try_end; + __pyx_L23_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + /*except:*/ { + __Pyx_AddTraceback("cython_code.file_db.FileDB.add_data", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_7, &__pyx_t_4) < 0) __PYX_ERR(0, 65, __pyx_L25_except_error) + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_4); + __pyx_t_8 = PyTuple_Pack(3, __pyx_t_5, __pyx_t_7, __pyx_t_4); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 65, __pyx_L25_except_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_17 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_8, NULL); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 65, __pyx_L25_except_error) + __Pyx_GOTREF(__pyx_t_17); + __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_17); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + if (__pyx_t_18 < 0) __PYX_ERR(0, 65, __pyx_L25_except_error) + __pyx_t_19 = (!__pyx_t_18); + if (unlikely(__pyx_t_19)) { + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_4); + __Pyx_ErrRestoreWithState(__pyx_t_5, __pyx_t_7, __pyx_t_4); + __pyx_t_5 = 0; __pyx_t_7 = 0; __pyx_t_4 = 0; + __PYX_ERR(0, 65, __pyx_L25_except_error) + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L24_exception_handled; + } + __pyx_L25_except_error:; + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16); + goto __pyx_L13_error; + __pyx_L24_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16); + __pyx_L28_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_13) { + __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 65, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + } + goto __pyx_L22; + } + __pyx_L22:; + } + goto __pyx_L32; + __pyx_L19_error:; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L13_error; + __pyx_L32:; + } + + /* "cython_code/file_db.pyx":62 + * def add_data(self, data, str key): + * try: + * with open(self.file, "r") as json_file: # <<<<<<<<<<<<<< + * self.json_data = json.load(json_file) + * self.json_data[str(key)] = data + */ + } + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L18_try_end; + __pyx_L13_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + /*except:*/ { + __Pyx_AddTraceback("cython_code.file_db.FileDB.add_data", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_7, &__pyx_t_5) < 0) __PYX_ERR(0, 62, __pyx_L15_except_error) + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_5); + __pyx_t_8 = PyTuple_Pack(3, __pyx_t_4, __pyx_t_7, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 62, __pyx_L15_except_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 62, __pyx_L15_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_19 = __Pyx_PyObject_IsTrue(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (__pyx_t_19 < 0) __PYX_ERR(0, 62, __pyx_L15_except_error) + __pyx_t_18 = (!__pyx_t_19); + if (unlikely(__pyx_t_18)) { + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_ErrRestoreWithState(__pyx_t_4, __pyx_t_7, __pyx_t_5); + __pyx_t_4 = 0; __pyx_t_7 = 0; __pyx_t_5 = 0; + __PYX_ERR(0, 62, __pyx_L15_except_error) + } + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L14_exception_handled; + } + __pyx_L15_except_error:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + goto __pyx_L3_error; + __pyx_L14_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + __pyx_L18_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_6) { + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 62, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + goto __pyx_L12; + } + __pyx_L12:; + } + goto __pyx_L36; + __pyx_L9_error:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L3_error; + __pyx_L36:; + } + + /* "cython_code/file_db.pyx":61 + * + * def add_data(self, data, str key): + * try: # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) + */ + } + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L8_try_end; + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "cython_code/file_db.pyx":67 + * with open(self.file, "w") as json_file: + * json.dump(self.json_data, json_file) + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(f'Error updating the file: {err}') + * + */ + __pyx_t_20 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); + if (__pyx_t_20) { + __Pyx_AddTraceback("cython_code.file_db.FileDB.add_data", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_7, &__pyx_t_4) < 0) __PYX_ERR(0, 67, __pyx_L5_except_error) + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_7); + __pyx_v_err = __pyx_t_7; + /*try:*/ { + + /* "cython_code/file_db.pyx":68 + * json.dump(self.json_data, json_file) + * except Exception as err: + * logging.error(f'Error updating the file: {err}') # <<<<<<<<<<<<<< + * + * def new_data(self, dict data): + */ + __Pyx_GetModuleGlobalName(__pyx_t_21, __pyx_n_s_logging); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 68, __pyx_L42_error) + __Pyx_GOTREF(__pyx_t_21); + __pyx_t_22 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_error); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 68, __pyx_L42_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + __pyx_t_21 = __Pyx_PyObject_FormatSimple(__pyx_v_err, __pyx_empty_unicode); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 68, __pyx_L42_error) + __Pyx_GOTREF(__pyx_t_21); + __pyx_t_23 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Error_updating_the_file, __pyx_t_21); if (unlikely(!__pyx_t_23)) __PYX_ERR(0, 68, __pyx_L42_error) + __Pyx_GOTREF(__pyx_t_23); + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + __pyx_t_21 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_22))) { + __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_22); + if (likely(__pyx_t_21)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_22); + __Pyx_INCREF(__pyx_t_21); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_22, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_21, __pyx_t_23}; + __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_22, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 68, __pyx_L42_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + + /* "cython_code/file_db.pyx":67 + * with open(self.file, "w") as json_file: + * json.dump(self.json_data, json_file) + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(f'Error updating the file: {err}') + * + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + goto __pyx_L43; + } + __pyx_L42_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_6 = 0; __pyx_t_12 = 0; __pyx_t_11 = 0; __pyx_t_10 = 0; __pyx_t_13 = 0; __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_XDECREF(__pyx_t_23); __pyx_t_23 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_10, &__pyx_t_13, &__pyx_t_16); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_6, &__pyx_t_12, &__pyx_t_11) < 0)) __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_12, &__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_13); + __Pyx_XGOTREF(__pyx_t_16); + __pyx_t_20 = __pyx_lineno; __pyx_t_24 = __pyx_clineno; __pyx_t_25 = __pyx_filename; + { + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_13, __pyx_t_16); + } + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ErrRestore(__pyx_t_6, __pyx_t_12, __pyx_t_11); + __pyx_t_6 = 0; __pyx_t_12 = 0; __pyx_t_11 = 0; __pyx_t_10 = 0; __pyx_t_13 = 0; __pyx_t_16 = 0; + __pyx_lineno = __pyx_t_20; __pyx_clineno = __pyx_t_24; __pyx_filename = __pyx_t_25; + goto __pyx_L5_except_error; + } + __pyx_L43:; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L4_exception_handled; + } + goto __pyx_L5_except_error; + + /* "cython_code/file_db.pyx":61 + * + * def add_data(self, data, str key): + * try: # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * self.json_data = json.load(json_file) + */ + __pyx_L5_except_error:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L4_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + __pyx_L8_try_end:; + } + + /* "cython_code/file_db.pyx":60 + * logging.info(f'Error reading the file: {err}') + * + * def add_data(self, data, str key): # <<<<<<<<<<<<<< + * try: + * with open(self.file, "r") as json_file: + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_21); + __Pyx_XDECREF(__pyx_t_22); + __Pyx_XDECREF(__pyx_t_23); + __Pyx_AddTraceback("cython_code.file_db.FileDB.add_data", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_json_file); + __Pyx_XDECREF(__pyx_v_err); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cython_code/file_db.pyx":70 + * logging.error(f'Error updating the file: {err}') + * + * def new_data(self, dict data): # <<<<<<<<<<<<<< + * try: + * with open(self.file, "w") as json_file: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_7file_db_6FileDB_7new_data(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_7file_db_6FileDB_7new_data = {"new_data", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_6FileDB_7new_data, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_7file_db_6FileDB_7new_data(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + PyObject *__pyx_v_data = 0; + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[1] = {0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("new_data (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_data,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_data)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 70, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "new_data") < 0)) __PYX_ERR(0, 70, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 1)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + } + __pyx_v_data = ((PyObject*)values[0]); + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("new_data", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 70, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.file_db.FileDB.new_data", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_data), (&PyDict_Type), 1, "data", 1))) __PYX_ERR(0, 70, __pyx_L1_error) + __pyx_r = __pyx_pf_11cython_code_7file_db_6FileDB_6new_data(((struct __pyx_obj_11cython_code_7file_db_FileDB *)__pyx_v_self), __pyx_v_data); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_7file_db_6FileDB_6new_data(struct __pyx_obj_11cython_code_7file_db_FileDB *__pyx_v_self, PyObject *__pyx_v_data) { + PyObject *__pyx_v_json_file = NULL; + PyObject *__pyx_v_err = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + unsigned int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + int __pyx_t_14; + int __pyx_t_15; + int __pyx_t_16; + PyObject *__pyx_t_17 = NULL; + PyObject *__pyx_t_18 = NULL; + PyObject *__pyx_t_19 = NULL; + int __pyx_t_20; + char const *__pyx_t_21; + PyObject *__pyx_t_22 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("new_data", 1); + + /* "cython_code/file_db.pyx":71 + * + * def new_data(self, dict data): + * try: # <<<<<<<<<<<<<< + * with open(self.file, "w") as json_file: + * json.dump(data, json_file) + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "cython_code/file_db.pyx":72 + * def new_data(self, dict data): + * try: + * with open(self.file, "w") as json_file: # <<<<<<<<<<<<<< + * json.dump(data, json_file) + * except Exception as err: + */ + /*with:*/ { + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 72, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_self->file); + __Pyx_GIVEREF(__pyx_v_self->file); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_self->file)) __PYX_ERR(0, 72, __pyx_L3_error); + __Pyx_INCREF(__pyx_n_u_w); + __Pyx_GIVEREF(__pyx_n_u_w); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_n_u_w)) __PYX_ERR(0, 72, __pyx_L3_error); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 72, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 72, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_enter); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 72, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_8, NULL}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_9, 0+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 72, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __pyx_t_7 = __pyx_t_4; + __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + /*try:*/ { + __pyx_v_json_file = __pyx_t_7; + __pyx_t_7 = 0; + + /* "cython_code/file_db.pyx":73 + * try: + * with open(self.file, "w") as json_file: + * json.dump(data, json_file) # <<<<<<<<<<<<<< + * except Exception as err: + * logging.error(f'Error writing to the file: {err}') + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_json); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 73, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_dump); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 73, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[3] = {__pyx_t_5, __pyx_v_data, __pyx_v_json_file}; + __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_9, 2+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 73, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "cython_code/file_db.pyx":72 + * def new_data(self, dict data): + * try: + * with open(self.file, "w") as json_file: # <<<<<<<<<<<<<< + * json.dump(data, json_file) + * except Exception as err: + */ + } + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L18_try_end; + __pyx_L13_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + /*except:*/ { + __Pyx_AddTraceback("cython_code.file_db.FileDB.new_data", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 72, __pyx_L15_except_error) + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + __pyx_t_8 = PyTuple_Pack(3, __pyx_t_7, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 72, __pyx_L15_except_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 72, __pyx_L15_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (__pyx_t_14 < 0) __PYX_ERR(0, 72, __pyx_L15_except_error) + __pyx_t_15 = (!__pyx_t_14); + if (unlikely(__pyx_t_15)) { + __Pyx_GIVEREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_ErrRestoreWithState(__pyx_t_7, __pyx_t_4, __pyx_t_5); + __pyx_t_7 = 0; __pyx_t_4 = 0; __pyx_t_5 = 0; + __PYX_ERR(0, 72, __pyx_L15_except_error) + } + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L14_exception_handled; + } + __pyx_L15_except_error:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + goto __pyx_L3_error; + __pyx_L14_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + __pyx_L18_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_6) { + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 72, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + goto __pyx_L12; + } + __pyx_L12:; + } + goto __pyx_L22; + __pyx_L9_error:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L3_error; + __pyx_L22:; + } + + /* "cython_code/file_db.pyx":71 + * + * def new_data(self, dict data): + * try: # <<<<<<<<<<<<<< + * with open(self.file, "w") as json_file: + * json.dump(data, json_file) + */ + } + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L8_try_end; + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "cython_code/file_db.pyx":74 + * with open(self.file, "w") as json_file: + * json.dump(data, json_file) + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(f'Error writing to the file: {err}') + */ + __pyx_t_16 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); + if (__pyx_t_16) { + __Pyx_AddTraceback("cython_code.file_db.FileDB.new_data", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_4, &__pyx_t_7) < 0) __PYX_ERR(0, 74, __pyx_L5_except_error) + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_4); + __pyx_v_err = __pyx_t_4; + /*try:*/ { + + /* "cython_code/file_db.pyx":75 + * json.dump(data, json_file) + * except Exception as err: + * logging.error(f'Error writing to the file: {err}') # <<<<<<<<<<<<<< + */ + __Pyx_GetModuleGlobalName(__pyx_t_17, __pyx_n_s_logging); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 75, __pyx_L28_error) + __Pyx_GOTREF(__pyx_t_17); + __pyx_t_18 = __Pyx_PyObject_GetAttrStr(__pyx_t_17, __pyx_n_s_error); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 75, __pyx_L28_error) + __Pyx_GOTREF(__pyx_t_18); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_17 = __Pyx_PyObject_FormatSimple(__pyx_v_err, __pyx_empty_unicode); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 75, __pyx_L28_error) + __Pyx_GOTREF(__pyx_t_17); + __pyx_t_19 = __Pyx_PyUnicode_Concat(__pyx_kp_u_Error_writing_to_the_file, __pyx_t_17); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 75, __pyx_L28_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_17 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_18))) { + __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_18); + if (likely(__pyx_t_17)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_18); + __Pyx_INCREF(__pyx_t_17); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_18, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_17, __pyx_t_19}; + __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_18, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 75, __pyx_L28_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_18); __pyx_t_18 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + + /* "cython_code/file_db.pyx":74 + * with open(self.file, "w") as json_file: + * json.dump(data, json_file) + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(f'Error writing to the file: {err}') + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + goto __pyx_L29; + } + __pyx_L28_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_6 = 0; __pyx_t_12 = 0; __pyx_t_11 = 0; __pyx_t_10 = 0; __pyx_t_13 = 0; __pyx_t_22 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_18); __pyx_t_18 = 0; + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_10, &__pyx_t_13, &__pyx_t_22); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_6, &__pyx_t_12, &__pyx_t_11) < 0)) __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_12, &__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_13); + __Pyx_XGOTREF(__pyx_t_22); + __pyx_t_16 = __pyx_lineno; __pyx_t_20 = __pyx_clineno; __pyx_t_21 = __pyx_filename; + { + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_XGIVEREF(__pyx_t_22); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_13, __pyx_t_22); + } + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ErrRestore(__pyx_t_6, __pyx_t_12, __pyx_t_11); + __pyx_t_6 = 0; __pyx_t_12 = 0; __pyx_t_11 = 0; __pyx_t_10 = 0; __pyx_t_13 = 0; __pyx_t_22 = 0; + __pyx_lineno = __pyx_t_16; __pyx_clineno = __pyx_t_20; __pyx_filename = __pyx_t_21; + goto __pyx_L5_except_error; + } + __pyx_L29:; + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L4_exception_handled; + } + goto __pyx_L5_except_error; + + /* "cython_code/file_db.pyx":71 + * + * def new_data(self, dict data): + * try: # <<<<<<<<<<<<<< + * with open(self.file, "w") as json_file: + * json.dump(data, json_file) + */ + __pyx_L5_except_error:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L4_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + __pyx_L8_try_end:; + } + + /* "cython_code/file_db.pyx":70 + * logging.error(f'Error updating the file: {err}') + * + * def new_data(self, dict data): # <<<<<<<<<<<<<< + * try: + * with open(self.file, "w") as json_file: + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_17); + __Pyx_XDECREF(__pyx_t_18); + __Pyx_XDECREF(__pyx_t_19); + __Pyx_AddTraceback("cython_code.file_db.FileDB.new_data", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_json_file); + __Pyx_XDECREF(__pyx_v_err); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_7file_db_6FileDB_9__reduce_cython__(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_7file_db_6FileDB_9__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_6FileDB_9__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_7file_db_6FileDB_9__reduce_cython__(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + if (unlikely(__pyx_nargs > 0)) { + __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;} + if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL; + __pyx_r = __pyx_pf_11cython_code_7file_db_6FileDB_8__reduce_cython__(((struct __pyx_obj_11cython_code_7file_db_FileDB *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_7file_db_6FileDB_8__reduce_cython__(CYTHON_UNUSED struct __pyx_obj_11cython_code_7file_db_FileDB *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__reduce_cython__", 1); + + /* "(tree fragment)":2 + * def __reduce_cython__(self): + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + */ + __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_no_default___reduce___due_to_non, 0, 0); + __PYX_ERR(1, 2, __pyx_L1_error) + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("cython_code.file_db.FileDB.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_7file_db_6FileDB_11__setstate_cython__(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_7file_db_6FileDB_11__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_6FileDB_11__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_7file_db_6FileDB_11__setstate_cython__(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + CYTHON_UNUSED PyObject *__pyx_v___pyx_state = 0; + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[1] = {0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 3, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(1, 3, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 1)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + } + __pyx_v___pyx_state = values[0]; + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(1, 3, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.file_db.FileDB.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_11cython_code_7file_db_6FileDB_10__setstate_cython__(((struct __pyx_obj_11cython_code_7file_db_FileDB *)__pyx_v_self), __pyx_v___pyx_state); + + /* function exit code */ + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_7file_db_6FileDB_10__setstate_cython__(CYTHON_UNUSED struct __pyx_obj_11cython_code_7file_db_FileDB *__pyx_v_self, CYTHON_UNUSED PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__setstate_cython__", 1); + + /* "(tree fragment)":4 + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" # <<<<<<<<<<<<<< + */ + __Pyx_Raise(__pyx_builtin_TypeError, __pyx_kp_s_no_default___reduce___due_to_non, 0, 0); + __PYX_ERR(1, 4, __pyx_L1_error) + + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("cython_code.file_db.FileDB.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_tp_new_11cython_code_7file_db_BotDb(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_11cython_code_7file_db_BotDb *p; + PyObject *o; + #if CYTHON_COMPILING_IN_LIMITED_API + allocfunc alloc_func = (allocfunc)PyType_GetSlot(t, Py_tp_alloc); + o = alloc_func(t, 0); + #else + if (likely(!__Pyx_PyType_HasFeature(t, Py_TPFLAGS_IS_ABSTRACT))) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + #endif + p = ((struct __pyx_obj_11cython_code_7file_db_BotDb *)o); + p->file = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->json_data = ((PyObject*)Py_None); Py_INCREF(Py_None); + if (unlikely(__pyx_pw_11cython_code_7file_db_5BotDb_1__cinit__(o, a, k) < 0)) goto bad; + return o; + bad: + Py_DECREF(o); o = 0; + return NULL; +} + +static void __pyx_tp_dealloc_11cython_code_7file_db_BotDb(PyObject *o) { + struct __pyx_obj_11cython_code_7file_db_BotDb *p = (struct __pyx_obj_11cython_code_7file_db_BotDb *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && !__Pyx_PyObject_GC_IsFinalized(o)) { + if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_11cython_code_7file_db_BotDb) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->file); + Py_CLEAR(p->json_data); + #if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY + (*Py_TYPE(o)->tp_free)(o); + #else + { + freefunc tp_free = (freefunc)PyType_GetSlot(Py_TYPE(o), Py_tp_free); + if (tp_free) tp_free(o); + } + #endif +} + +static int __pyx_tp_traverse_11cython_code_7file_db_BotDb(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_11cython_code_7file_db_BotDb *p = (struct __pyx_obj_11cython_code_7file_db_BotDb *)o; + if (p->json_data) { + e = (*v)(p->json_data, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_11cython_code_7file_db_BotDb(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_11cython_code_7file_db_BotDb *p = (struct __pyx_obj_11cython_code_7file_db_BotDb *)o; + tmp = ((PyObject*)p->json_data); + p->json_data = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_11cython_code_7file_db_BotDb[] = { + {"reading_db", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_5BotDb_3reading_db, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {"change_data", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_5BotDb_5change_data, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_5BotDb_7__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_5BotDb_9__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {0, 0, 0, 0} +}; +#if CYTHON_USE_TYPE_SPECS +static PyType_Slot __pyx_type_11cython_code_7file_db_BotDb_slots[] = { + {Py_tp_dealloc, (void *)__pyx_tp_dealloc_11cython_code_7file_db_BotDb}, + {Py_tp_traverse, (void *)__pyx_tp_traverse_11cython_code_7file_db_BotDb}, + {Py_tp_clear, (void *)__pyx_tp_clear_11cython_code_7file_db_BotDb}, + {Py_tp_methods, (void *)__pyx_methods_11cython_code_7file_db_BotDb}, + {Py_tp_new, (void *)__pyx_tp_new_11cython_code_7file_db_BotDb}, + {0, 0}, +}; +static PyType_Spec __pyx_type_11cython_code_7file_db_BotDb_spec = { + "cython_code.file_db.BotDb", + sizeof(struct __pyx_obj_11cython_code_7file_db_BotDb), + 0, + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, + __pyx_type_11cython_code_7file_db_BotDb_slots, +}; +#else + +static PyTypeObject __pyx_type_11cython_code_7file_db_BotDb = { + PyVarObject_HEAD_INIT(0, 0) + "cython_code.file_db.""BotDb", /*tp_name*/ + sizeof(struct __pyx_obj_11cython_code_7file_db_BotDb), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_11cython_code_7file_db_BotDb, /*tp_dealloc*/ + #if PY_VERSION_HEX < 0x030800b4 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 + 0, /*tp_vectorcall_offset*/ + #endif + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_11cython_code_7file_db_BotDb, /*tp_traverse*/ + __pyx_tp_clear_11cython_code_7file_db_BotDb, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_11cython_code_7file_db_BotDb, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + #if !CYTHON_USE_TYPE_SPECS + 0, /*tp_dictoffset*/ + #endif + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_11cython_code_7file_db_BotDb, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + #if CYTHON_USE_TP_FINALIZE + 0, /*tp_finalize*/ + #else + NULL, /*tp_finalize*/ + #endif + #endif + #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) + 0, /*tp_vectorcall*/ + #endif + #if __PYX_NEED_TP_PRINT_SLOT == 1 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030C0000 + 0, /*tp_watched*/ + #endif + #if PY_VERSION_HEX >= 0x030d00A4 + 0, /*tp_versions_used*/ + #endif + #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 + 0, /*tp_pypy_flags*/ + #endif +}; +#endif + +static PyObject *__pyx_tp_new_11cython_code_7file_db_FileDB(PyTypeObject *t, PyObject *a, PyObject *k) { + struct __pyx_obj_11cython_code_7file_db_FileDB *p; + PyObject *o; + #if CYTHON_COMPILING_IN_LIMITED_API + allocfunc alloc_func = (allocfunc)PyType_GetSlot(t, Py_tp_alloc); + o = alloc_func(t, 0); + #else + if (likely(!__Pyx_PyType_HasFeature(t, Py_TPFLAGS_IS_ABSTRACT))) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + #endif + p = ((struct __pyx_obj_11cython_code_7file_db_FileDB *)o); + p->file = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->json_data = ((PyObject*)Py_None); Py_INCREF(Py_None); + if (unlikely(__pyx_pw_11cython_code_7file_db_6FileDB_1__cinit__(o, a, k) < 0)) goto bad; + return o; + bad: + Py_DECREF(o); o = 0; + return NULL; +} + +static void __pyx_tp_dealloc_11cython_code_7file_db_FileDB(PyObject *o) { + struct __pyx_obj_11cython_code_7file_db_FileDB *p = (struct __pyx_obj_11cython_code_7file_db_FileDB *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && !__Pyx_PyObject_GC_IsFinalized(o)) { + if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_11cython_code_7file_db_FileDB) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->file); + Py_CLEAR(p->json_data); + #if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY + (*Py_TYPE(o)->tp_free)(o); + #else + { + freefunc tp_free = (freefunc)PyType_GetSlot(Py_TYPE(o), Py_tp_free); + if (tp_free) tp_free(o); + } + #endif +} + +static int __pyx_tp_traverse_11cython_code_7file_db_FileDB(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_11cython_code_7file_db_FileDB *p = (struct __pyx_obj_11cython_code_7file_db_FileDB *)o; + if (p->json_data) { + e = (*v)(p->json_data, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_11cython_code_7file_db_FileDB(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_11cython_code_7file_db_FileDB *p = (struct __pyx_obj_11cython_code_7file_db_FileDB *)o; + tmp = ((PyObject*)p->json_data); + p->json_data = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_11cython_code_7file_db_FileDB[] = { + {"reading_db", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_6FileDB_3reading_db, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {"add_data", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_6FileDB_5add_data, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {"new_data", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_6FileDB_7new_data, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_6FileDB_9__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_7file_db_6FileDB_11__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {0, 0, 0, 0} +}; +#if CYTHON_USE_TYPE_SPECS +static PyType_Slot __pyx_type_11cython_code_7file_db_FileDB_slots[] = { + {Py_tp_dealloc, (void *)__pyx_tp_dealloc_11cython_code_7file_db_FileDB}, + {Py_tp_traverse, (void *)__pyx_tp_traverse_11cython_code_7file_db_FileDB}, + {Py_tp_clear, (void *)__pyx_tp_clear_11cython_code_7file_db_FileDB}, + {Py_tp_methods, (void *)__pyx_methods_11cython_code_7file_db_FileDB}, + {Py_tp_new, (void *)__pyx_tp_new_11cython_code_7file_db_FileDB}, + {0, 0}, +}; +static PyType_Spec __pyx_type_11cython_code_7file_db_FileDB_spec = { + "cython_code.file_db.FileDB", + sizeof(struct __pyx_obj_11cython_code_7file_db_FileDB), + 0, + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, + __pyx_type_11cython_code_7file_db_FileDB_slots, +}; +#else + +static PyTypeObject __pyx_type_11cython_code_7file_db_FileDB = { + PyVarObject_HEAD_INIT(0, 0) + "cython_code.file_db.""FileDB", /*tp_name*/ + sizeof(struct __pyx_obj_11cython_code_7file_db_FileDB), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_11cython_code_7file_db_FileDB, /*tp_dealloc*/ + #if PY_VERSION_HEX < 0x030800b4 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 + 0, /*tp_vectorcall_offset*/ + #endif + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_11cython_code_7file_db_FileDB, /*tp_traverse*/ + __pyx_tp_clear_11cython_code_7file_db_FileDB, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_11cython_code_7file_db_FileDB, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + #if !CYTHON_USE_TYPE_SPECS + 0, /*tp_dictoffset*/ + #endif + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_11cython_code_7file_db_FileDB, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + #if CYTHON_USE_TP_FINALIZE + 0, /*tp_finalize*/ + #else + NULL, /*tp_finalize*/ + #endif + #endif + #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) + 0, /*tp_vectorcall*/ + #endif + #if __PYX_NEED_TP_PRINT_SLOT == 1 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030C0000 + 0, /*tp_watched*/ + #endif + #if PY_VERSION_HEX >= 0x030d00A4 + 0, /*tp_versions_used*/ + #endif + #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 + 0, /*tp_pypy_flags*/ + #endif +}; +#endif + +static PyMethodDef __pyx_methods[] = { + {0, 0, 0, 0} +}; +#ifndef CYTHON_SMALL_CODE +#if defined(__clang__) + #define CYTHON_SMALL_CODE +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) + #define CYTHON_SMALL_CODE __attribute__((cold)) +#else + #define CYTHON_SMALL_CODE +#endif +#endif +/* #### Code section: pystring_table ### */ + +static int __Pyx_CreateStringTabAndInitStrings(void) { + __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_n_s_BotDb, __pyx_k_BotDb, sizeof(__pyx_k_BotDb), 0, 0, 1, 1}, + {&__pyx_n_s_BotDb___reduce_cython, __pyx_k_BotDb___reduce_cython, sizeof(__pyx_k_BotDb___reduce_cython), 0, 0, 1, 1}, + {&__pyx_n_s_BotDb___setstate_cython, __pyx_k_BotDb___setstate_cython, sizeof(__pyx_k_BotDb___setstate_cython), 0, 0, 1, 1}, + {&__pyx_n_s_BotDb_change_data, __pyx_k_BotDb_change_data, sizeof(__pyx_k_BotDb_change_data), 0, 0, 1, 1}, + {&__pyx_n_s_BotDb_reading_db, __pyx_k_BotDb_reading_db, sizeof(__pyx_k_BotDb_reading_db), 0, 0, 1, 1}, + {&__pyx_kp_u_Created_new_file, __pyx_k_Created_new_file, sizeof(__pyx_k_Created_new_file), 0, 1, 0, 0}, + {&__pyx_kp_u_Error_reading_the_file, __pyx_k_Error_reading_the_file, sizeof(__pyx_k_Error_reading_the_file), 0, 1, 0, 0}, + {&__pyx_kp_u_Error_updating_the_file, __pyx_k_Error_updating_the_file, sizeof(__pyx_k_Error_updating_the_file), 0, 1, 0, 0}, + {&__pyx_kp_u_Error_writing_to_the_file, __pyx_k_Error_writing_to_the_file, sizeof(__pyx_k_Error_writing_to_the_file), 0, 1, 0, 0}, + {&__pyx_n_s_FileDB, __pyx_k_FileDB, sizeof(__pyx_k_FileDB), 0, 0, 1, 1}, + {&__pyx_n_s_FileDB___reduce_cython, __pyx_k_FileDB___reduce_cython, sizeof(__pyx_k_FileDB___reduce_cython), 0, 0, 1, 1}, + {&__pyx_n_s_FileDB___setstate_cython, __pyx_k_FileDB___setstate_cython, sizeof(__pyx_k_FileDB___setstate_cython), 0, 0, 1, 1}, + {&__pyx_n_s_FileDB_add_data, __pyx_k_FileDB_add_data, sizeof(__pyx_k_FileDB_add_data), 0, 0, 1, 1}, + {&__pyx_n_s_FileDB_new_data, __pyx_k_FileDB_new_data, sizeof(__pyx_k_FileDB_new_data), 0, 0, 1, 1}, + {&__pyx_n_s_FileDB_reading_db, __pyx_k_FileDB_reading_db, sizeof(__pyx_k_FileDB_reading_db), 0, 0, 1, 1}, + {&__pyx_n_s_FileNotFoundError, __pyx_k_FileNotFoundError, sizeof(__pyx_k_FileNotFoundError), 0, 0, 1, 1}, + {&__pyx_n_s_JSONDecodeError, __pyx_k_JSONDecodeError, sizeof(__pyx_k_JSONDecodeError), 0, 0, 1, 1}, + {&__pyx_kp_u_None, __pyx_k_None, sizeof(__pyx_k_None), 0, 1, 0, 0}, + {&__pyx_n_s_TypeError, __pyx_k_TypeError, sizeof(__pyx_k_TypeError), 0, 0, 1, 1}, + {&__pyx_n_s__19, __pyx_k__19, sizeof(__pyx_k__19), 0, 0, 1, 1}, + {&__pyx_n_s__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 0, 1, 1}, + {&__pyx_n_s_add_data, __pyx_k_add_data, sizeof(__pyx_k_add_data), 0, 0, 1, 1}, + {&__pyx_n_u_ads, __pyx_k_ads, sizeof(__pyx_k_ads), 0, 1, 0, 1}, + {&__pyx_n_s_asyncio_coroutines, __pyx_k_asyncio_coroutines, sizeof(__pyx_k_asyncio_coroutines), 0, 0, 1, 1}, + {&__pyx_n_s_change_data, __pyx_k_change_data, sizeof(__pyx_k_change_data), 0, 0, 1, 1}, + {&__pyx_n_s_chmod, __pyx_k_chmod, sizeof(__pyx_k_chmod), 0, 0, 1, 1}, + {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, + {&__pyx_n_s_cython_code_file_db, __pyx_k_cython_code_file_db, sizeof(__pyx_k_cython_code_file_db), 0, 0, 1, 1}, + {&__pyx_kp_s_cython_code_file_db_pyx, __pyx_k_cython_code_file_db_pyx, sizeof(__pyx_k_cython_code_file_db_pyx), 0, 0, 1, 0}, + {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1}, + {&__pyx_kp_u_disable, __pyx_k_disable, sizeof(__pyx_k_disable), 0, 1, 0, 0}, + {&__pyx_n_s_dump, __pyx_k_dump, sizeof(__pyx_k_dump), 0, 0, 1, 1}, + {&__pyx_kp_u_enable, __pyx_k_enable, sizeof(__pyx_k_enable), 0, 1, 0, 0}, + {&__pyx_n_s_enter, __pyx_k_enter, sizeof(__pyx_k_enter), 0, 0, 1, 1}, + {&__pyx_n_s_err, __pyx_k_err, sizeof(__pyx_k_err), 0, 0, 1, 1}, + {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1}, + {&__pyx_n_s_exit, __pyx_k_exit, sizeof(__pyx_k_exit), 0, 0, 1, 1}, + {&__pyx_n_s_file, __pyx_k_file, sizeof(__pyx_k_file), 0, 0, 1, 1}, + {&__pyx_kp_u_gc, __pyx_k_gc, sizeof(__pyx_k_gc), 0, 1, 0, 0}, + {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, + {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, + {&__pyx_n_s_info, __pyx_k_info, sizeof(__pyx_k_info), 0, 0, 1, 1}, + {&__pyx_n_s_initializing, __pyx_k_initializing, sizeof(__pyx_k_initializing), 0, 0, 1, 1}, + {&__pyx_n_s_is_coroutine, __pyx_k_is_coroutine, sizeof(__pyx_k_is_coroutine), 0, 0, 1, 1}, + {&__pyx_kp_u_isenabled, __pyx_k_isenabled, sizeof(__pyx_k_isenabled), 0, 1, 0, 0}, + {&__pyx_n_s_join_channel, __pyx_k_join_channel, sizeof(__pyx_k_join_channel), 0, 0, 1, 1}, + {&__pyx_n_u_join_channel, __pyx_k_join_channel, sizeof(__pyx_k_join_channel), 0, 1, 0, 1}, + {&__pyx_n_s_json, __pyx_k_json, sizeof(__pyx_k_json), 0, 0, 1, 1}, + {&__pyx_n_s_json_file, __pyx_k_json_file, sizeof(__pyx_k_json_file), 0, 0, 1, 1}, + {&__pyx_n_s_key, __pyx_k_key, sizeof(__pyx_k_key), 0, 0, 1, 1}, + {&__pyx_n_s_load, __pyx_k_load, sizeof(__pyx_k_load), 0, 0, 1, 1}, + {&__pyx_n_s_logging, __pyx_k_logging, sizeof(__pyx_k_logging), 0, 0, 1, 1}, + {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, + {&__pyx_n_s_new_data, __pyx_k_new_data, sizeof(__pyx_k_new_data), 0, 0, 1, 1}, + {&__pyx_kp_s_no_default___reduce___due_to_non, __pyx_k_no_default___reduce___due_to_non, sizeof(__pyx_k_no_default___reduce___due_to_non), 0, 0, 1, 0}, + {&__pyx_n_s_open, __pyx_k_open, sizeof(__pyx_k_open), 0, 0, 1, 1}, + {&__pyx_n_s_os, __pyx_k_os, sizeof(__pyx_k_os), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1}, + {&__pyx_n_u_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 1, 0, 1}, + {&__pyx_n_s_reading_db, __pyx_k_reading_db, sizeof(__pyx_k_reading_db), 0, 0, 1, 1}, + {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1}, + {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, + {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, + {&__pyx_n_s_self, __pyx_k_self, sizeof(__pyx_k_self), 0, 0, 1, 1}, + {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1}, + {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1}, + {&__pyx_n_s_spec, __pyx_k_spec, sizeof(__pyx_k_spec), 0, 0, 1, 1}, + {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0}, + {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {&__pyx_n_u_w, __pyx_k_w, sizeof(__pyx_k_w), 0, 1, 0, 1}, + {&__pyx_kp_u_with_default_data, __pyx_k_with_default_data, sizeof(__pyx_k_with_default_data), 0, 1, 0, 0}, + {0, 0, 0, 0, 0, 0, 0} + }; + return __Pyx_InitStrings(__pyx_string_tab); +} +/* #### Code section: cached_builtins ### */ +static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_open = __Pyx_GetBuiltinName(__pyx_n_s_open); if (!__pyx_builtin_open) __PYX_ERR(0, 14, __pyx_L1_error) + __pyx_builtin_TypeError = __Pyx_GetBuiltinName(__pyx_n_s_TypeError); if (!__pyx_builtin_TypeError) __PYX_ERR(1, 2, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} +/* #### Code section: cached_constants ### */ + +static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "cython_code/file_db.pyx":14 + * self.file = file + * try: + * with open(self.file, "r") as json_file: # <<<<<<<<<<<<<< + * self.json_data = json.load(json_file) + * except (FileNotFoundError, json.JSONDecodeError): + */ + __pyx_tuple_ = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple_); + __Pyx_GIVEREF(__pyx_tuple_); + + /* "cython_code/file_db.pyx":25 + * logging.info(f'Created new file: {file} with default data') + * + * def reading_db(self): # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * return json.load(json_file) + */ + __pyx_tuple__3 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_json_file); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 25, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__3); + __Pyx_GIVEREF(__pyx_tuple__3); + __pyx_codeobj__4 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__3, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cython_code_file_db_pyx, __pyx_n_s_reading_db, 25, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__4)) __PYX_ERR(0, 25, __pyx_L1_error) + + /* "cython_code/file_db.pyx":29 + * return json.load(json_file) + * + * def change_data(self, bint join_channel): # <<<<<<<<<<<<<< + * self.json_data['join_channel'] = join_channel + * with open(self.file, "w") as json_file: + */ + __pyx_tuple__5 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_join_channel, __pyx_n_s_json_file); if (unlikely(!__pyx_tuple__5)) __PYX_ERR(0, 29, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__5); + __Pyx_GIVEREF(__pyx_tuple__5); + __pyx_codeobj__6 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__5, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cython_code_file_db_pyx, __pyx_n_s_change_data, 29, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__6)) __PYX_ERR(0, 29, __pyx_L1_error) + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): + */ + __pyx_tuple__7 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__7); + __Pyx_GIVEREF(__pyx_tuple__7); + __pyx_codeobj__8 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__7, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__8)) __PYX_ERR(1, 1, __pyx_L1_error) + + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + */ + __pyx_tuple__9 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_pyx_state); if (unlikely(!__pyx_tuple__9)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__9); + __Pyx_GIVEREF(__pyx_tuple__9); + __pyx_codeobj__10 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__9, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 3, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__10)) __PYX_ERR(1, 3, __pyx_L1_error) + + /* "cython_code/file_db.pyx":53 + * logging.info(f'Created new file: {file} with default data') + * + * def reading_db(self): # <<<<<<<<<<<<<< + * try: + * with open(self.file, "r") as json_file: + */ + __pyx_tuple__11 = PyTuple_Pack(3, __pyx_n_s_self, __pyx_n_s_json_file, __pyx_n_s_err); if (unlikely(!__pyx_tuple__11)) __PYX_ERR(0, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__11); + __Pyx_GIVEREF(__pyx_tuple__11); + __pyx_codeobj__12 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 3, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__11, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cython_code_file_db_pyx, __pyx_n_s_reading_db, 53, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__12)) __PYX_ERR(0, 53, __pyx_L1_error) + + /* "cython_code/file_db.pyx":60 + * logging.info(f'Error reading the file: {err}') + * + * def add_data(self, data, str key): # <<<<<<<<<<<<<< + * try: + * with open(self.file, "r") as json_file: + */ + __pyx_tuple__13 = PyTuple_Pack(5, __pyx_n_s_self, __pyx_n_s_data, __pyx_n_s_key, __pyx_n_s_json_file, __pyx_n_s_err); if (unlikely(!__pyx_tuple__13)) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__13); + __Pyx_GIVEREF(__pyx_tuple__13); + __pyx_codeobj__14 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__13, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cython_code_file_db_pyx, __pyx_n_s_add_data, 60, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__14)) __PYX_ERR(0, 60, __pyx_L1_error) + + /* "cython_code/file_db.pyx":70 + * logging.error(f'Error updating the file: {err}') + * + * def new_data(self, dict data): # <<<<<<<<<<<<<< + * try: + * with open(self.file, "w") as json_file: + */ + __pyx_tuple__15 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_data, __pyx_n_s_json_file, __pyx_n_s_err); if (unlikely(!__pyx_tuple__15)) __PYX_ERR(0, 70, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__15); + __Pyx_GIVEREF(__pyx_tuple__15); + __pyx_codeobj__16 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__15, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cython_code_file_db_pyx, __pyx_n_s_new_data, 70, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__16)) __PYX_ERR(0, 70, __pyx_L1_error) + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): + */ + __pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__7, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) __PYX_ERR(1, 1, __pyx_L1_error) + + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + */ + __pyx_codeobj__18 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__9, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 3, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__18)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} +/* #### Code section: init_constants ### */ + +static CYTHON_SMALL_CODE int __Pyx_InitConstants(void) { + if (__Pyx_CreateStringTabAndInitStrings() < 0) __PYX_ERR(0, 1, __pyx_L1_error); + __pyx_int_511 = PyInt_FromLong(511); if (unlikely(!__pyx_int_511)) __PYX_ERR(0, 1, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} +/* #### Code section: init_globals ### */ + +static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { + return 0; +} +/* #### Code section: init_module ### */ + +static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/ + +static int __Pyx_modinit_global_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); + /*--- Global init code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); + /*--- Variable export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); + /*--- Function export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_type_init_code(void) { + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); + /*--- Type init code ---*/ + #if CYTHON_USE_TYPE_SPECS + __pyx_ptype_11cython_code_7file_db_BotDb = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_11cython_code_7file_db_BotDb_spec, NULL); if (unlikely(!__pyx_ptype_11cython_code_7file_db_BotDb)) __PYX_ERR(0, 7, __pyx_L1_error) + if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_11cython_code_7file_db_BotDb_spec, __pyx_ptype_11cython_code_7file_db_BotDb) < 0) __PYX_ERR(0, 7, __pyx_L1_error) + #else + __pyx_ptype_11cython_code_7file_db_BotDb = &__pyx_type_11cython_code_7file_db_BotDb; + #endif + #if !CYTHON_COMPILING_IN_LIMITED_API + #endif + #if !CYTHON_USE_TYPE_SPECS + if (__Pyx_PyType_Ready(__pyx_ptype_11cython_code_7file_db_BotDb) < 0) __PYX_ERR(0, 7, __pyx_L1_error) + #endif + #if PY_MAJOR_VERSION < 3 + __pyx_ptype_11cython_code_7file_db_BotDb->tp_print = 0; + #endif + #if !CYTHON_COMPILING_IN_LIMITED_API + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_11cython_code_7file_db_BotDb->tp_dictoffset && __pyx_ptype_11cython_code_7file_db_BotDb->tp_getattro == PyObject_GenericGetAttr)) { + __pyx_ptype_11cython_code_7file_db_BotDb->tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + #endif + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_BotDb, (PyObject *) __pyx_ptype_11cython_code_7file_db_BotDb) < 0) __PYX_ERR(0, 7, __pyx_L1_error) + #if !CYTHON_COMPILING_IN_LIMITED_API + if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_11cython_code_7file_db_BotDb) < 0) __PYX_ERR(0, 7, __pyx_L1_error) + #endif + #if CYTHON_USE_TYPE_SPECS + __pyx_ptype_11cython_code_7file_db_FileDB = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_11cython_code_7file_db_FileDB_spec, NULL); if (unlikely(!__pyx_ptype_11cython_code_7file_db_FileDB)) __PYX_ERR(0, 34, __pyx_L1_error) + if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_11cython_code_7file_db_FileDB_spec, __pyx_ptype_11cython_code_7file_db_FileDB) < 0) __PYX_ERR(0, 34, __pyx_L1_error) + #else + __pyx_ptype_11cython_code_7file_db_FileDB = &__pyx_type_11cython_code_7file_db_FileDB; + #endif + #if !CYTHON_COMPILING_IN_LIMITED_API + #endif + #if !CYTHON_USE_TYPE_SPECS + if (__Pyx_PyType_Ready(__pyx_ptype_11cython_code_7file_db_FileDB) < 0) __PYX_ERR(0, 34, __pyx_L1_error) + #endif + #if PY_MAJOR_VERSION < 3 + __pyx_ptype_11cython_code_7file_db_FileDB->tp_print = 0; + #endif + #if !CYTHON_COMPILING_IN_LIMITED_API + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_11cython_code_7file_db_FileDB->tp_dictoffset && __pyx_ptype_11cython_code_7file_db_FileDB->tp_getattro == PyObject_GenericGetAttr)) { + __pyx_ptype_11cython_code_7file_db_FileDB->tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + #endif + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_FileDB, (PyObject *) __pyx_ptype_11cython_code_7file_db_FileDB) < 0) __PYX_ERR(0, 34, __pyx_L1_error) + #if !CYTHON_COMPILING_IN_LIMITED_API + if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_11cython_code_7file_db_FileDB) < 0) __PYX_ERR(0, 34, __pyx_L1_error) + #endif + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_modinit_type_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); + /*--- Type import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); + /*--- Variable import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); + /*--- Function import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + + +#if PY_MAJOR_VERSION >= 3 +#if CYTHON_PEP489_MULTI_PHASE_INIT +static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ +static int __pyx_pymod_exec_file_db(PyObject* module); /*proto*/ +static PyModuleDef_Slot __pyx_moduledef_slots[] = { + {Py_mod_create, (void*)__pyx_pymod_create}, + {Py_mod_exec, (void*)__pyx_pymod_exec_file_db}, + {0, NULL} +}; +#endif + +#ifdef __cplusplus +namespace { + struct PyModuleDef __pyx_moduledef = + #else + static struct PyModuleDef __pyx_moduledef = + #endif + { + PyModuleDef_HEAD_INIT, + "file_db", + 0, /* m_doc */ + #if CYTHON_PEP489_MULTI_PHASE_INIT + 0, /* m_size */ + #elif CYTHON_USE_MODULE_STATE + sizeof(__pyx_mstate), /* m_size */ + #else + -1, /* m_size */ + #endif + __pyx_methods /* m_methods */, + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_moduledef_slots, /* m_slots */ + #else + NULL, /* m_reload */ + #endif + #if CYTHON_USE_MODULE_STATE + __pyx_m_traverse, /* m_traverse */ + __pyx_m_clear, /* m_clear */ + NULL /* m_free */ + #else + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ + #endif + }; + #ifdef __cplusplus +} /* anonymous namespace */ +#endif +#endif + +#ifndef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#elif PY_MAJOR_VERSION < 3 +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" void +#else +#define __Pyx_PyMODINIT_FUNC void +#endif +#else +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" PyObject * +#else +#define __Pyx_PyMODINIT_FUNC PyObject * +#endif +#endif + + +#if PY_MAJOR_VERSION < 3 +__Pyx_PyMODINIT_FUNC initfile_db(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC initfile_db(void) +#else +__Pyx_PyMODINIT_FUNC PyInit_file_db(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC PyInit_file_db(void) +#if CYTHON_PEP489_MULTI_PHASE_INIT +{ + return PyModuleDef_Init(&__pyx_moduledef); +} +static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { + #if PY_VERSION_HEX >= 0x030700A1 + static PY_INT64_T main_interpreter_id = -1; + PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); + if (main_interpreter_id == -1) { + main_interpreter_id = current_id; + return (unlikely(current_id == -1)) ? -1 : 0; + } else if (unlikely(main_interpreter_id != current_id)) + #else + static PyInterpreterState *main_interpreter = NULL; + PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; + if (!main_interpreter) { + main_interpreter = current_interpreter; + } else if (unlikely(main_interpreter != current_interpreter)) + #endif + { + PyErr_SetString( + PyExc_ImportError, + "Interpreter change detected - this module can only be loaded into one interpreter per process."); + return -1; + } + return 0; +} +#if CYTHON_COMPILING_IN_LIMITED_API +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *module, const char* from_name, const char* to_name, int allow_none) +#else +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) +#endif +{ + PyObject *value = PyObject_GetAttrString(spec, from_name); + int result = 0; + if (likely(value)) { + if (allow_none || value != Py_None) { +#if CYTHON_COMPILING_IN_LIMITED_API + result = PyModule_AddObject(module, to_name, value); +#else + result = PyDict_SetItemString(moddict, to_name, value); +#endif + } + Py_DECREF(value); + } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + } else { + result = -1; + } + return result; +} +static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def) { + PyObject *module = NULL, *moddict, *modname; + CYTHON_UNUSED_VAR(def); + if (__Pyx_check_single_interpreter()) + return NULL; + if (__pyx_m) + return __Pyx_NewRef(__pyx_m); + modname = PyObject_GetAttrString(spec, "name"); + if (unlikely(!modname)) goto bad; + module = PyModule_NewObject(modname); + Py_DECREF(modname); + if (unlikely(!module)) goto bad; +#if CYTHON_COMPILING_IN_LIMITED_API + moddict = module; +#else + moddict = PyModule_GetDict(module); + if (unlikely(!moddict)) goto bad; +#endif + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; + return module; +bad: + Py_XDECREF(module); + return NULL; +} + + +static CYTHON_SMALL_CODE int __pyx_pymod_exec_file_db(PyObject *__pyx_pyinit_module) +#endif +#endif +{ + int stringtab_initialized = 0; + #if CYTHON_USE_MODULE_STATE + int pystate_addmodule_run = 0; + #endif + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannyDeclarations + #if CYTHON_PEP489_MULTI_PHASE_INIT + if (__pyx_m) { + if (__pyx_m == __pyx_pyinit_module) return 0; + PyErr_SetString(PyExc_RuntimeError, "Module 'file_db' has already been imported. Re-initialisation is not supported."); + return -1; + } + #elif PY_MAJOR_VERSION >= 3 + if (__pyx_m) return __Pyx_NewRef(__pyx_m); + #endif + /*--- Module creation code ---*/ + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_m = __pyx_pyinit_module; + Py_INCREF(__pyx_m); + #else + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4("file_db", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #elif CYTHON_USE_MODULE_STATE + __pyx_t_1 = PyModule_Create(&__pyx_moduledef); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) + { + int add_module_result = PyState_AddModule(__pyx_t_1, &__pyx_moduledef); + __pyx_t_1 = 0; /* transfer ownership from __pyx_t_1 to "file_db" pseudovariable */ + if (unlikely((add_module_result < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + pystate_addmodule_run = 1; + } + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #endif + CYTHON_UNUSED_VAR(__pyx_t_1); + __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_d); + __pyx_b = __Pyx_PyImport_AddModuleRef(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_cython_runtime = __Pyx_PyImport_AddModuleRef((const char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if CYTHON_REFNANNY +__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); +if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); +} +#endif + __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_file_db(void)", 0); + if (__Pyx_check_binary_version(__PYX_LIMITED_VERSION_HEX, __Pyx_get_runtime_version(), CYTHON_COMPILING_IN_LIMITED_API) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pxy_PyFrame_Initialize_Offsets + __Pxy_PyFrame_Initialize_Offsets(); + #endif + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pyx_CyFunction_USED + if (__pyx_CyFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_FusedFunction_USED + if (__pyx_FusedFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Coroutine_USED + if (__pyx_Coroutine_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Generator_USED + if (__pyx_Generator_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_AsyncGen_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_StopAsyncIteration_USED + if (__pyx_StopAsyncIteration_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + /*--- Library function declarations ---*/ + /*--- Threads initialization code ---*/ + #if defined(WITH_THREAD) && PY_VERSION_HEX < 0x030700F0 && defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + PyEval_InitThreads(); + #endif + /*--- Initialize various global constants etc. ---*/ + if (__Pyx_InitConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + stringtab_initialized = 1; + if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) + if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + if (__pyx_module_is_main_cython_code__file_db) { + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + } + #if PY_MAJOR_VERSION >= 3 + { + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) + if (!PyDict_GetItemString(modules, "cython_code.file_db")) { + if (unlikely((PyDict_SetItemString(modules, "cython_code.file_db", __pyx_m) < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + } + } + #endif + /*--- Builtin init code ---*/ + if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Constants init code ---*/ + if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Global type/function init code ---*/ + (void)__Pyx_modinit_global_init_code(); + (void)__Pyx_modinit_variable_export_code(); + (void)__Pyx_modinit_function_export_code(); + if (unlikely((__Pyx_modinit_type_init_code() < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + (void)__Pyx_modinit_type_import_code(); + (void)__Pyx_modinit_variable_import_code(); + (void)__Pyx_modinit_function_import_code(); + /*--- Execution code ---*/ + #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + + /* "cython_code/file_db.pyx":2 + * # file_db.pyx + * import json # <<<<<<<<<<<<<< + * import logging + * import os + */ + __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_json, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_json, __pyx_t_2) < 0) __PYX_ERR(0, 2, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/file_db.pyx":3 + * # file_db.pyx + * import json + * import logging # <<<<<<<<<<<<<< + * import os + * from cython cimport bint, dict + */ + __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_logging, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_logging, __pyx_t_2) < 0) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/file_db.pyx":4 + * import json + * import logging + * import os # <<<<<<<<<<<<<< + * from cython cimport bint, dict + * + */ + __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_os, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_os, __pyx_t_2) < 0) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/file_db.pyx":25 + * logging.info(f'Created new file: {file} with default data') + * + * def reading_db(self): # <<<<<<<<<<<<<< + * with open(self.file, "r") as json_file: + * return json.load(json_file) + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_7file_db_5BotDb_3reading_db, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_BotDb_reading_db, NULL, __pyx_n_s_cython_code_file_db, __pyx_d, ((PyObject *)__pyx_codeobj__4)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 25, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_11cython_code_7file_db_BotDb, __pyx_n_s_reading_db, __pyx_t_2) < 0) __PYX_ERR(0, 25, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyType_Modified(__pyx_ptype_11cython_code_7file_db_BotDb); + + /* "cython_code/file_db.pyx":29 + * return json.load(json_file) + * + * def change_data(self, bint join_channel): # <<<<<<<<<<<<<< + * self.json_data['join_channel'] = join_channel + * with open(self.file, "w") as json_file: + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_7file_db_5BotDb_5change_data, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_BotDb_change_data, NULL, __pyx_n_s_cython_code_file_db, __pyx_d, ((PyObject *)__pyx_codeobj__6)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 29, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_11cython_code_7file_db_BotDb, __pyx_n_s_change_data, __pyx_t_2) < 0) __PYX_ERR(0, 29, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyType_Modified(__pyx_ptype_11cython_code_7file_db_BotDb); + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_7file_db_5BotDb_7__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_BotDb___reduce_cython, NULL, __pyx_n_s_cython_code_file_db, __pyx_d, ((PyObject *)__pyx_codeobj__8)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_7file_db_5BotDb_9__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_BotDb___setstate_cython, NULL, __pyx_n_s_cython_code_file_db, __pyx_d, ((PyObject *)__pyx_codeobj__10)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/file_db.pyx":53 + * logging.info(f'Created new file: {file} with default data') + * + * def reading_db(self): # <<<<<<<<<<<<<< + * try: + * with open(self.file, "r") as json_file: + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_7file_db_6FileDB_3reading_db, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_FileDB_reading_db, NULL, __pyx_n_s_cython_code_file_db, __pyx_d, ((PyObject *)__pyx_codeobj__12)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_11cython_code_7file_db_FileDB, __pyx_n_s_reading_db, __pyx_t_2) < 0) __PYX_ERR(0, 53, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyType_Modified(__pyx_ptype_11cython_code_7file_db_FileDB); + + /* "cython_code/file_db.pyx":60 + * logging.info(f'Error reading the file: {err}') + * + * def add_data(self, data, str key): # <<<<<<<<<<<<<< + * try: + * with open(self.file, "r") as json_file: + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_7file_db_6FileDB_5add_data, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_FileDB_add_data, NULL, __pyx_n_s_cython_code_file_db, __pyx_d, ((PyObject *)__pyx_codeobj__14)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_11cython_code_7file_db_FileDB, __pyx_n_s_add_data, __pyx_t_2) < 0) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyType_Modified(__pyx_ptype_11cython_code_7file_db_FileDB); + + /* "cython_code/file_db.pyx":70 + * logging.error(f'Error updating the file: {err}') + * + * def new_data(self, dict data): # <<<<<<<<<<<<<< + * try: + * with open(self.file, "w") as json_file: + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_7file_db_6FileDB_7new_data, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_FileDB_new_data, NULL, __pyx_n_s_cython_code_file_db, __pyx_d, ((PyObject *)__pyx_codeobj__16)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 70, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_11cython_code_7file_db_FileDB, __pyx_n_s_new_data, __pyx_t_2) < 0) __PYX_ERR(0, 70, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyType_Modified(__pyx_ptype_11cython_code_7file_db_FileDB); + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_7file_db_6FileDB_9__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_FileDB___reduce_cython, NULL, __pyx_n_s_cython_code_file_db, __pyx_d, ((PyObject *)__pyx_codeobj__17)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "(tree fragment)":3 + * def __reduce_cython__(self): + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * raise TypeError, "no default __reduce__ due to non-trivial __cinit__" + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_7file_db_6FileDB_11__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_FileDB___setstate_cython, NULL, __pyx_n_s_cython_code_file_db, __pyx_d, ((PyObject *)__pyx_codeobj__18)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(1, 3, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/file_db.pyx":1 + * # file_db.pyx # <<<<<<<<<<<<<< + * import json + * import logging + */ + __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /*--- Wrapped vars code ---*/ + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + if (__pyx_m) { + if (__pyx_d && stringtab_initialized) { + __Pyx_AddTraceback("init cython_code.file_db", __pyx_clineno, __pyx_lineno, __pyx_filename); + } + #if !CYTHON_USE_MODULE_STATE + Py_CLEAR(__pyx_m); + #else + Py_DECREF(__pyx_m); + if (pystate_addmodule_run) { + PyObject *tp, *value, *tb; + PyErr_Fetch(&tp, &value, &tb); + PyState_RemoveModule(&__pyx_moduledef); + PyErr_Restore(tp, value, tb); + } + #endif + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init cython_code.file_db"); + } + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + #if CYTHON_PEP489_MULTI_PHASE_INIT + return (__pyx_m != NULL) ? 0 : -1; + #elif PY_MAJOR_VERSION >= 3 + return __pyx_m; + #else + return; + #endif +} +/* #### Code section: cleanup_globals ### */ +/* #### Code section: cleanup_module ### */ +/* #### Code section: main_method ### */ +/* #### Code section: utility_code_pragmas ### */ +#ifdef _MSC_VER +#pragma warning( push ) +/* Warning 4127: conditional expression is constant + * Cython uses constant conditional expressions to allow in inline functions to be optimized at + * compile-time, so this warning is not useful + */ +#pragma warning( disable : 4127 ) +#endif + + + +/* #### Code section: utility_code_def ### */ + +/* --- Runtime support code --- */ +/* Refnanny */ +#if CYTHON_REFNANNY +static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { + PyObject *m = NULL, *p = NULL; + void *r = NULL; + m = PyImport_ImportModule(modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, "RefNannyAPI"); + if (!p) goto end; + r = PyLong_AsVoidPtr(p); +end: + Py_XDECREF(p); + Py_XDECREF(m); + return (__Pyx_RefNannyAPIStruct *)r; +} +#endif + +/* PyErrExceptionMatches */ +#if CYTHON_FAST_THREAD_STATE +static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; i= 0x030C00A6 + PyObject *current_exception = tstate->current_exception; + if (unlikely(!current_exception)) return 0; + exc_type = (PyObject*) Py_TYPE(current_exception); + if (exc_type == err) return 1; +#else + exc_type = tstate->curexc_type; + if (exc_type == err) return 1; + if (unlikely(!exc_type)) return 0; +#endif + #if CYTHON_AVOID_BORROWED_REFS + Py_INCREF(exc_type); + #endif + if (unlikely(PyTuple_Check(err))) { + result = __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); + } else { + result = __Pyx_PyErr_GivenExceptionMatches(exc_type, err); + } + #if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(exc_type); + #endif + return result; +} +#endif + +/* PyErrFetchRestore */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { +#if PY_VERSION_HEX >= 0x030C00A6 + PyObject *tmp_value; + assert(type == NULL || (value != NULL && type == (PyObject*) Py_TYPE(value))); + if (value) { + #if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(((PyBaseExceptionObject*) value)->traceback != tb)) + #endif + PyException_SetTraceback(value, tb); + } + tmp_value = tstate->current_exception; + tstate->current_exception = value; + Py_XDECREF(tmp_value); + Py_XDECREF(type); + Py_XDECREF(tb); +#else + PyObject *tmp_type, *tmp_value, *tmp_tb; + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#endif +} +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { +#if PY_VERSION_HEX >= 0x030C00A6 + PyObject* exc_value; + exc_value = tstate->current_exception; + tstate->current_exception = 0; + *value = exc_value; + *type = NULL; + *tb = NULL; + if (exc_value) { + *type = (PyObject*) Py_TYPE(exc_value); + Py_INCREF(*type); + #if CYTHON_COMPILING_IN_CPYTHON + *tb = ((PyBaseExceptionObject*) exc_value)->traceback; + Py_XINCREF(*tb); + #else + *tb = PyException_GetTraceback(exc_value); + #endif + } +#else + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +#endif +} +#endif + +/* PyObjectGetAttrStr */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro)) + return tp->tp_getattro(obj, attr_name); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_getattr)) + return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); +#endif + return PyObject_GetAttr(obj, attr_name); +} +#endif + +/* PyObjectGetAttrStrNoError */ +#if __PYX_LIMITED_VERSION_HEX < 0x030d00A1 +static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + __Pyx_PyErr_Clear(); +} +#endif +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { + PyObject *result; +#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1 + (void) PyObject_GetOptionalAttr(obj, attr_name, &result); + return result; +#else +#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { + return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); + } +#endif + result = __Pyx_PyObject_GetAttrStr(obj, attr_name); + if (unlikely(!result)) { + __Pyx_PyObject_GetAttrStr_ClearAttributeError(); + } + return result; +#endif +} + +/* GetBuiltinName */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name) { + PyObject* result = __Pyx_PyObject_GetAttrStrNoError(__pyx_b, name); + if (unlikely(!result) && !PyErr_Occurred()) { + PyErr_Format(PyExc_NameError, +#if PY_MAJOR_VERSION >= 3 + "name '%U' is not defined", name); +#else + "name '%.200s' is not defined", PyString_AS_STRING(name)); +#endif + } + return result; +} + +/* TupleAndListFromArray */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE void __Pyx_copy_object_array(PyObject *const *CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) { + PyObject *v; + Py_ssize_t i; + for (i = 0; i < length; i++) { + v = dest[i] = src[i]; + Py_INCREF(v); + } +} +static CYTHON_INLINE PyObject * +__Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n) +{ + PyObject *res; + if (n <= 0) { + Py_INCREF(__pyx_empty_tuple); + return __pyx_empty_tuple; + } + res = PyTuple_New(n); + if (unlikely(res == NULL)) return NULL; + __Pyx_copy_object_array(src, ((PyTupleObject*)res)->ob_item, n); + return res; +} +static CYTHON_INLINE PyObject * +__Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n) +{ + PyObject *res; + if (n <= 0) { + return PyList_New(0); + } + res = PyList_New(n); + if (unlikely(res == NULL)) return NULL; + __Pyx_copy_object_array(src, ((PyListObject*)res)->ob_item, n); + return res; +} +#endif + +/* BytesEquals */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API + return PyObject_RichCompareBool(s1, s2, equals); +#else + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { + const char *ps1, *ps2; + Py_ssize_t length = PyBytes_GET_SIZE(s1); + if (length != PyBytes_GET_SIZE(s2)) + return (equals == Py_NE); + ps1 = PyBytes_AS_STRING(s1); + ps2 = PyBytes_AS_STRING(s2); + if (ps1[0] != ps2[0]) { + return (equals == Py_NE); + } else if (length == 1) { + return (equals == Py_EQ); + } else { + int result; +#if CYTHON_USE_UNICODE_INTERNALS && (PY_VERSION_HEX < 0x030B0000) + Py_hash_t hash1, hash2; + hash1 = ((PyBytesObject*)s1)->ob_shash; + hash2 = ((PyBytesObject*)s2)->ob_shash; + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + return (equals == Py_NE); + } +#endif + result = memcmp(ps1, ps2, (size_t)length); + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +#endif +} + +/* UnicodeEquals */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API + return PyObject_RichCompareBool(s1, s2, equals); +#else +#if PY_MAJOR_VERSION < 3 + PyObject* owned_ref = NULL; +#endif + int s1_is_unicode, s2_is_unicode; + if (s1 == s2) { + goto return_eq; + } + s1_is_unicode = PyUnicode_CheckExact(s1); + s2_is_unicode = PyUnicode_CheckExact(s2); +#if PY_MAJOR_VERSION < 3 + if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { + owned_ref = PyUnicode_FromObject(s2); + if (unlikely(!owned_ref)) + return -1; + s2 = owned_ref; + s2_is_unicode = 1; + } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { + owned_ref = PyUnicode_FromObject(s1); + if (unlikely(!owned_ref)) + return -1; + s1 = owned_ref; + s1_is_unicode = 1; + } else if (((!s2_is_unicode) & (!s1_is_unicode))) { + return __Pyx_PyBytes_Equals(s1, s2, equals); + } +#endif + if (s1_is_unicode & s2_is_unicode) { + Py_ssize_t length; + int kind; + void *data1, *data2; + if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) + return -1; + length = __Pyx_PyUnicode_GET_LENGTH(s1); + if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { + goto return_ne; + } +#if CYTHON_USE_UNICODE_INTERNALS + { + Py_hash_t hash1, hash2; + #if CYTHON_PEP393_ENABLED + hash1 = ((PyASCIIObject*)s1)->hash; + hash2 = ((PyASCIIObject*)s2)->hash; + #else + hash1 = ((PyUnicodeObject*)s1)->hash; + hash2 = ((PyUnicodeObject*)s2)->hash; + #endif + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + goto return_ne; + } + } +#endif + kind = __Pyx_PyUnicode_KIND(s1); + if (kind != __Pyx_PyUnicode_KIND(s2)) { + goto return_ne; + } + data1 = __Pyx_PyUnicode_DATA(s1); + data2 = __Pyx_PyUnicode_DATA(s2); + if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { + goto return_ne; + } else if (length == 1) { + goto return_eq; + } else { + int result = memcmp(data1, data2, (size_t)(length * kind)); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & s2_is_unicode) { + goto return_ne; + } else if ((s2 == Py_None) & s1_is_unicode) { + goto return_ne; + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +return_eq: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ); +return_ne: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_NE); +#endif +} + +/* fastcall */ +#if CYTHON_METH_FASTCALL +static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s) +{ + Py_ssize_t i, n = PyTuple_GET_SIZE(kwnames); + for (i = 0; i < n; i++) + { + if (s == PyTuple_GET_ITEM(kwnames, i)) return kwvalues[i]; + } + for (i = 0; i < n; i++) + { + int eq = __Pyx_PyUnicode_Equals(s, PyTuple_GET_ITEM(kwnames, i), Py_EQ); + if (unlikely(eq != 0)) { + if (unlikely(eq < 0)) return NULL; + return kwvalues[i]; + } + } + return NULL; +} +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000 +CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues) { + Py_ssize_t i, nkwargs = PyTuple_GET_SIZE(kwnames); + PyObject *dict; + dict = PyDict_New(); + if (unlikely(!dict)) + return NULL; + for (i=0; i= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AsString(kw_name)); + #endif +} + +/* ParseKeywords */ +static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject *const *kwvalues, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + int kwds_is_tuple = CYTHON_METH_FASTCALL && likely(PyTuple_Check(kwds)); + while (1) { + Py_XDECREF(key); key = NULL; + Py_XDECREF(value); value = NULL; + if (kwds_is_tuple) { + Py_ssize_t size; +#if CYTHON_ASSUME_SAFE_MACROS + size = PyTuple_GET_SIZE(kwds); +#else + size = PyTuple_Size(kwds); + if (size < 0) goto bad; +#endif + if (pos >= size) break; +#if CYTHON_AVOID_BORROWED_REFS + key = __Pyx_PySequence_ITEM(kwds, pos); + if (!key) goto bad; +#elif CYTHON_ASSUME_SAFE_MACROS + key = PyTuple_GET_ITEM(kwds, pos); +#else + key = PyTuple_GetItem(kwds, pos); + if (!key) goto bad; +#endif + value = kwvalues[pos]; + pos++; + } + else + { + if (!PyDict_Next(kwds, &pos, &key, &value)) break; +#if CYTHON_AVOID_BORROWED_REFS + Py_INCREF(key); +#endif + } + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; +#if CYTHON_AVOID_BORROWED_REFS + Py_INCREF(value); + Py_DECREF(key); +#endif + key = NULL; + value = NULL; + continue; + } +#if !CYTHON_AVOID_BORROWED_REFS + Py_INCREF(key); +#endif + Py_INCREF(value); + name = first_kw_arg; + #if PY_MAJOR_VERSION < 3 + if (likely(PyString_Check(key))) { + while (*name) { + if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) + && _PyString_Eq(**name, key)) { + values[name-argnames] = value; +#if CYTHON_AVOID_BORROWED_REFS + value = NULL; +#endif + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + if ((**argname == key) || ( + (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) + && _PyString_Eq(**argname, key))) { + goto arg_passed_twice; + } + argname++; + } + } + } else + #endif + if (likely(PyUnicode_Check(key))) { + while (*name) { + int cmp = ( + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : + #endif + PyUnicode_Compare(**name, key) + ); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) { + values[name-argnames] = value; +#if CYTHON_AVOID_BORROWED_REFS + value = NULL; +#endif + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + int cmp = (**argname == key) ? 0 : + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : + #endif + PyUnicode_Compare(**argname, key); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) goto arg_passed_twice; + argname++; + } + } + } else + goto invalid_keyword_type; + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; + } + } + Py_XDECREF(key); + Py_XDECREF(value); + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, key); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + #if PY_MAJOR_VERSION < 3 + PyErr_Format(PyExc_TypeError, + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + PyErr_Format(PyExc_TypeError, + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + Py_XDECREF(key); + Py_XDECREF(value); + return -1; +} + +/* RaiseArgTupleInvalid */ +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *more_or_less; + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; + } else { + num_expected = num_max; + more_or_less = "at most"; + } + if (exact) { + more_or_less = "exactly"; + } + PyErr_Format(PyExc_TypeError, + "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", + func_name, more_or_less, num_expected, + (num_expected == 1) ? "" : "s", num_found); +} + +/* ArgTypeTest */ +static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) +{ + __Pyx_TypeName type_name; + __Pyx_TypeName obj_type_name; + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; + } + else if (exact) { + #if PY_MAJOR_VERSION == 2 + if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; + #endif + } + else { + if (likely(__Pyx_TypeCheck(obj, type))) return 1; + } + type_name = __Pyx_PyType_GetName(type); + obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj)); + PyErr_Format(PyExc_TypeError, + "Argument '%.200s' has incorrect type (expected " __Pyx_FMT_TYPENAME + ", got " __Pyx_FMT_TYPENAME ")", name, type_name, obj_type_name); + __Pyx_DECREF_TypeName(type_name); + __Pyx_DECREF_TypeName(obj_type_name); + return 0; +} + +/* PyObjectCall */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *result; + ternaryfunc call = Py_TYPE(func)->tp_call; + if (unlikely(!call)) + return PyObject_Call(func, arg, kw); + #if PY_MAJOR_VERSION < 3 + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + #else + if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) + return NULL; + #endif + result = (*call)(func, arg, kw); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* PyObjectLookupSpecial */ +#if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx__PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name, int with_error) { + PyObject *res; + PyTypeObject *tp = Py_TYPE(obj); +#if PY_MAJOR_VERSION < 3 + if (unlikely(PyInstance_Check(obj))) + return with_error ? __Pyx_PyObject_GetAttrStr(obj, attr_name) : __Pyx_PyObject_GetAttrStrNoError(obj, attr_name); +#endif + res = _PyType_Lookup(tp, attr_name); + if (likely(res)) { + descrgetfunc f = Py_TYPE(res)->tp_descr_get; + if (!f) { + Py_INCREF(res); + } else { + res = f(res, obj, (PyObject *)tp); + } + } else if (with_error) { + PyErr_SetObject(PyExc_AttributeError, attr_name); + } + return res; +} +#endif + +/* PyFunctionFastCall */ +#if CYTHON_FAST_PYCALL && !CYTHON_VECTORCALL +static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na, + PyObject *globals) { + PyFrameObject *f; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject **fastlocals; + Py_ssize_t i; + PyObject *result; + assert(globals != NULL); + /* XXX Perhaps we should create a specialized + PyFrame_New() that doesn't take locals, but does + take builtins without sanity checking them. + */ + assert(tstate != NULL); + f = PyFrame_New(tstate, co, globals, NULL); + if (f == NULL) { + return NULL; + } + fastlocals = __Pyx_PyFrame_GetLocalsplus(f); + for (i = 0; i < na; i++) { + Py_INCREF(*args); + fastlocals[i] = *args++; + } + result = PyEval_EvalFrameEx(f,0); + ++tstate->recursion_depth; + Py_DECREF(f); + --tstate->recursion_depth; + return result; +} +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) { + PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); + PyObject *globals = PyFunction_GET_GLOBALS(func); + PyObject *argdefs = PyFunction_GET_DEFAULTS(func); + PyObject *closure; +#if PY_MAJOR_VERSION >= 3 + PyObject *kwdefs; +#endif + PyObject *kwtuple, **k; + PyObject **d; + Py_ssize_t nd; + Py_ssize_t nk; + PyObject *result; + assert(kwargs == NULL || PyDict_Check(kwargs)); + nk = kwargs ? PyDict_Size(kwargs) : 0; + #if PY_MAJOR_VERSION < 3 + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) { + return NULL; + } + #else + if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) { + return NULL; + } + #endif + if ( +#if PY_MAJOR_VERSION >= 3 + co->co_kwonlyargcount == 0 && +#endif + likely(kwargs == NULL || nk == 0) && + co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { + if (argdefs == NULL && co->co_argcount == nargs) { + result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals); + goto done; + } + else if (nargs == 0 && argdefs != NULL + && co->co_argcount == Py_SIZE(argdefs)) { + /* function called with no arguments, but all parameters have + a default value: use default values as arguments .*/ + args = &PyTuple_GET_ITEM(argdefs, 0); + result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals); + goto done; + } + } + if (kwargs != NULL) { + Py_ssize_t pos, i; + kwtuple = PyTuple_New(2 * nk); + if (kwtuple == NULL) { + result = NULL; + goto done; + } + k = &PyTuple_GET_ITEM(kwtuple, 0); + pos = i = 0; + while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) { + Py_INCREF(k[i]); + Py_INCREF(k[i+1]); + i += 2; + } + nk = i / 2; + } + else { + kwtuple = NULL; + k = NULL; + } + closure = PyFunction_GET_CLOSURE(func); +#if PY_MAJOR_VERSION >= 3 + kwdefs = PyFunction_GET_KW_DEFAULTS(func); +#endif + if (argdefs != NULL) { + d = &PyTuple_GET_ITEM(argdefs, 0); + nd = Py_SIZE(argdefs); + } + else { + d = NULL; + nd = 0; + } +#if PY_MAJOR_VERSION >= 3 + result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL, + args, (int)nargs, + k, (int)nk, + d, (int)nd, kwdefs, closure); +#else + result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, + args, (int)nargs, + k, (int)nk, + d, (int)nd, closure); +#endif + Py_XDECREF(kwtuple); +done: + Py_LeaveRecursiveCall(); + return result; +} +#endif + +/* PyObjectCallMethO */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) { + PyObject *self, *result; + PyCFunction cfunc; + cfunc = __Pyx_CyOrPyCFunction_GET_FUNCTION(func); + self = __Pyx_CyOrPyCFunction_GET_SELF(func); + #if PY_MAJOR_VERSION < 3 + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + #else + if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) + return NULL; + #endif + result = cfunc(self, arg); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* PyObjectFastCall */ +#if PY_VERSION_HEX < 0x03090000 || CYTHON_COMPILING_IN_LIMITED_API +static PyObject* __Pyx_PyObject_FastCall_fallback(PyObject *func, PyObject **args, size_t nargs, PyObject *kwargs) { + PyObject *argstuple; + PyObject *result = 0; + size_t i; + argstuple = PyTuple_New((Py_ssize_t)nargs); + if (unlikely(!argstuple)) return NULL; + for (i = 0; i < nargs; i++) { + Py_INCREF(args[i]); + if (__Pyx_PyTuple_SET_ITEM(argstuple, (Py_ssize_t)i, args[i]) < 0) goto bad; + } + result = __Pyx_PyObject_Call(func, argstuple, kwargs); + bad: + Py_DECREF(argstuple); + return result; +} +#endif +static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject **args, size_t _nargs, PyObject *kwargs) { + Py_ssize_t nargs = __Pyx_PyVectorcall_NARGS(_nargs); +#if CYTHON_COMPILING_IN_CPYTHON + if (nargs == 0 && kwargs == NULL) { + if (__Pyx_CyOrPyCFunction_Check(func) && likely( __Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_NOARGS)) + return __Pyx_PyObject_CallMethO(func, NULL); + } + else if (nargs == 1 && kwargs == NULL) { + if (__Pyx_CyOrPyCFunction_Check(func) && likely( __Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_O)) + return __Pyx_PyObject_CallMethO(func, args[0]); + } +#endif + #if PY_VERSION_HEX < 0x030800B1 + #if CYTHON_FAST_PYCCALL + if (PyCFunction_Check(func)) { + if (kwargs) { + return _PyCFunction_FastCallDict(func, args, nargs, kwargs); + } else { + return _PyCFunction_FastCallKeywords(func, args, nargs, NULL); + } + } + #if PY_VERSION_HEX >= 0x030700A1 + if (!kwargs && __Pyx_IS_TYPE(func, &PyMethodDescr_Type)) { + return _PyMethodDescr_FastCallKeywords(func, args, nargs, NULL); + } + #endif + #endif + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(func)) { + return __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs); + } + #endif + #endif + if (kwargs == NULL) { + #if CYTHON_VECTORCALL + #if PY_VERSION_HEX < 0x03090000 + vectorcallfunc f = _PyVectorcall_Function(func); + #else + vectorcallfunc f = PyVectorcall_Function(func); + #endif + if (f) { + return f(func, args, (size_t)nargs, NULL); + } + #elif defined(__Pyx_CyFunction_USED) && CYTHON_BACKPORT_VECTORCALL + if (__Pyx_CyFunction_CheckExact(func)) { + __pyx_vectorcallfunc f = __Pyx_CyFunction_func_vectorcall(func); + if (f) return f(func, args, (size_t)nargs, NULL); + } + #endif + } + if (nargs == 0) { + return __Pyx_PyObject_Call(func, __pyx_empty_tuple, kwargs); + } + #if PY_VERSION_HEX >= 0x03090000 && !CYTHON_COMPILING_IN_LIMITED_API + return PyObject_VectorcallDict(func, args, (size_t)nargs, kwargs); + #else + return __Pyx_PyObject_FastCall_fallback(func, args, (size_t)nargs, kwargs); + #endif +} + +/* PyDictVersioning */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { + PyObject **dictptr = NULL; + Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; + if (offset) { +#if CYTHON_COMPILING_IN_CPYTHON + dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); +#else + dictptr = _PyObject_GetDictPtr(obj); +#endif + } + return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; +} +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) + return 0; + return obj_dict_version == __Pyx_get_object_dict_version(obj); +} +#endif + +/* GetModuleGlobalName */ +#if CYTHON_USE_DICT_VERSIONS +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) +#else +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) +#endif +{ + PyObject *result; +#if !CYTHON_AVOID_BORROWED_REFS +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && PY_VERSION_HEX < 0x030d0000 + result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } else if (unlikely(PyErr_Occurred())) { + return NULL; + } +#elif CYTHON_COMPILING_IN_LIMITED_API + if (unlikely(!__pyx_m)) { + return NULL; + } + result = PyObject_GetAttr(__pyx_m, name); + if (likely(result)) { + return result; + } +#else + result = PyDict_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } +#endif +#else + result = PyObject_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } + PyErr_Clear(); +#endif + return __Pyx_GetBuiltinName(name); +} + +/* RaiseUnexpectedTypeError */ +static int +__Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj) +{ + __Pyx_TypeName obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj)); + PyErr_Format(PyExc_TypeError, "Expected %s, got " __Pyx_FMT_TYPENAME, + expected, obj_type_name); + __Pyx_DECREF_TypeName(obj_type_name); + return 0; +} + +/* GetTopmostException */ +#if CYTHON_USE_EXC_INFO_STACK && CYTHON_FAST_THREAD_STATE +static _PyErr_StackItem * +__Pyx_PyErr_GetTopmostException(PyThreadState *tstate) +{ + _PyErr_StackItem *exc_info = tstate->exc_info; + while ((exc_info->exc_value == NULL || exc_info->exc_value == Py_None) && + exc_info->previous_item != NULL) + { + exc_info = exc_info->previous_item; + } + return exc_info; +} +#endif + +/* SaveResetException */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4 + _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); + PyObject *exc_value = exc_info->exc_value; + if (exc_value == NULL || exc_value == Py_None) { + *value = NULL; + *type = NULL; + *tb = NULL; + } else { + *value = exc_value; + Py_INCREF(*value); + *type = (PyObject*) Py_TYPE(exc_value); + Py_INCREF(*type); + *tb = PyException_GetTraceback(exc_value); + } + #elif CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); + *type = exc_info->exc_type; + *value = exc_info->exc_value; + *tb = exc_info->exc_traceback; + Py_XINCREF(*type); + Py_XINCREF(*value); + Py_XINCREF(*tb); + #else + *type = tstate->exc_type; + *value = tstate->exc_value; + *tb = tstate->exc_traceback; + Py_XINCREF(*type); + Py_XINCREF(*value); + Py_XINCREF(*tb); + #endif +} +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { + #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4 + _PyErr_StackItem *exc_info = tstate->exc_info; + PyObject *tmp_value = exc_info->exc_value; + exc_info->exc_value = value; + Py_XDECREF(tmp_value); + Py_XDECREF(type); + Py_XDECREF(tb); + #else + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = type; + exc_info->exc_value = value; + exc_info->exc_traceback = tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = type; + tstate->exc_value = value; + tstate->exc_traceback = tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); + #endif +} +#endif + +/* GetException */ +#if CYTHON_FAST_THREAD_STATE +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) +#endif +{ + PyObject *local_type = NULL, *local_value, *local_tb = NULL; +#if CYTHON_FAST_THREAD_STATE + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if PY_VERSION_HEX >= 0x030C00A6 + local_value = tstate->current_exception; + tstate->current_exception = 0; + if (likely(local_value)) { + local_type = (PyObject*) Py_TYPE(local_value); + Py_INCREF(local_type); + local_tb = PyException_GetTraceback(local_value); + } + #else + local_type = tstate->curexc_type; + local_value = tstate->curexc_value; + local_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; + #endif +#else + PyErr_Fetch(&local_type, &local_value, &local_tb); +#endif + PyErr_NormalizeException(&local_type, &local_value, &local_tb); +#if CYTHON_FAST_THREAD_STATE && PY_VERSION_HEX >= 0x030C00A6 + if (unlikely(tstate->current_exception)) +#elif CYTHON_FAST_THREAD_STATE + if (unlikely(tstate->curexc_type)) +#else + if (unlikely(PyErr_Occurred())) +#endif + goto bad; + #if PY_MAJOR_VERSION >= 3 + if (local_tb) { + if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) + goto bad; + } + #endif + Py_XINCREF(local_tb); + Py_XINCREF(local_type); + Py_XINCREF(local_value); + *type = local_type; + *value = local_value; + *tb = local_tb; +#if CYTHON_FAST_THREAD_STATE + #if CYTHON_USE_EXC_INFO_STACK + { + _PyErr_StackItem *exc_info = tstate->exc_info; + #if PY_VERSION_HEX >= 0x030B00a4 + tmp_value = exc_info->exc_value; + exc_info->exc_value = local_value; + tmp_type = NULL; + tmp_tb = NULL; + Py_XDECREF(local_type); + Py_XDECREF(local_tb); + #else + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = local_type; + exc_info->exc_value = local_value; + exc_info->exc_traceback = local_tb; + #endif + } + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = local_type; + tstate->exc_value = local_value; + tstate->exc_traceback = local_tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#else + PyErr_SetExcInfo(local_type, local_value, local_tb); +#endif + return 0; +bad: + *type = 0; + *value = 0; + *tb = 0; + Py_XDECREF(local_type); + Py_XDECREF(local_value); + Py_XDECREF(local_tb); + return -1; +} + +/* FastTypeChecks */ +#if CYTHON_COMPILING_IN_CPYTHON +static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { + while (a) { + a = __Pyx_PyType_GetSlot(a, tp_base, PyTypeObject*); + if (a == b) + return 1; + } + return b == &PyBaseObject_Type; +} +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { + PyObject *mro; + if (a == b) return 1; + mro = a->tp_mro; + if (likely(mro)) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) + return 1; + } + return 0; + } + return __Pyx_InBases(a, b); +} +static CYTHON_INLINE int __Pyx_IsAnySubtype2(PyTypeObject *cls, PyTypeObject *a, PyTypeObject *b) { + PyObject *mro; + if (cls == a || cls == b) return 1; + mro = cls->tp_mro; + if (likely(mro)) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + PyObject *base = PyTuple_GET_ITEM(mro, i); + if (base == (PyObject *)a || base == (PyObject *)b) + return 1; + } + return 0; + } + return __Pyx_InBases(cls, a) || __Pyx_InBases(cls, b); +} +#if PY_MAJOR_VERSION == 2 +static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { + PyObject *exception, *value, *tb; + int res; + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&exception, &value, &tb); + res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + if (!res) { + res = PyObject_IsSubclass(err, exc_type2); + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + } + __Pyx_ErrRestore(exception, value, tb); + return res; +} +#else +static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { + if (exc_type1) { + return __Pyx_IsAnySubtype2((PyTypeObject*)err, (PyTypeObject*)exc_type1, (PyTypeObject*)exc_type2); + } else { + return __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); + } +} +#endif +static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + assert(PyExceptionClass_Check(exc_type)); + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; i> kind_shift) - ulength < char_pos)) + goto overflow; + ukind = __Pyx_PyUnicode_KIND(uval); + udata = __Pyx_PyUnicode_DATA(uval); + if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) { + memcpy((char *)result_udata + (char_pos << kind_shift), udata, (size_t) (ulength << kind_shift)); + } else { + #if PY_VERSION_HEX >= 0x030d0000 + if (unlikely(PyUnicode_CopyCharacters(result_uval, char_pos, uval, 0, ulength) < 0)) goto bad; + #elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters) + _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength); + #else + Py_ssize_t j; + for (j=0; j < ulength; j++) { + Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j); + __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar); + } + #endif + } + char_pos += ulength; + } + return result_uval; +overflow: + PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string"); +bad: + Py_DECREF(result_uval); + return NULL; +#else + CYTHON_UNUSED_VAR(max_char); + CYTHON_UNUSED_VAR(result_ulength); + CYTHON_UNUSED_VAR(value_count); + return PyUnicode_Join(__pyx_empty_unicode, value_tuple); +#endif +} + +/* KeywordStringCheck */ +static int __Pyx_CheckKeywordStrings( + PyObject *kw, + const char* function_name, + int kw_allowed) +{ + PyObject* key = 0; + Py_ssize_t pos = 0; +#if CYTHON_COMPILING_IN_PYPY + if (!kw_allowed && PyDict_Next(kw, &pos, &key, 0)) + goto invalid_keyword; + return 1; +#else + if (CYTHON_METH_FASTCALL && likely(PyTuple_Check(kw))) { + Py_ssize_t kwsize; +#if CYTHON_ASSUME_SAFE_MACROS + kwsize = PyTuple_GET_SIZE(kw); +#else + kwsize = PyTuple_Size(kw); + if (kwsize < 0) return 0; +#endif + if (unlikely(kwsize == 0)) + return 1; + if (!kw_allowed) { +#if CYTHON_ASSUME_SAFE_MACROS + key = PyTuple_GET_ITEM(kw, 0); +#else + key = PyTuple_GetItem(kw, pos); + if (!key) return 0; +#endif + goto invalid_keyword; + } +#if PY_VERSION_HEX < 0x03090000 + for (pos = 0; pos < kwsize; pos++) { +#if CYTHON_ASSUME_SAFE_MACROS + key = PyTuple_GET_ITEM(kw, pos); +#else + key = PyTuple_GetItem(kw, pos); + if (!key) return 0; +#endif + if (unlikely(!PyUnicode_Check(key))) + goto invalid_keyword_type; + } +#endif + return 1; + } + while (PyDict_Next(kw, &pos, &key, 0)) { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_Check(key))) + #endif + if (unlikely(!PyUnicode_Check(key))) + goto invalid_keyword_type; + } + if (!kw_allowed && unlikely(key)) + goto invalid_keyword; + return 1; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + return 0; +#endif +invalid_keyword: + #if PY_MAJOR_VERSION < 3 + PyErr_Format(PyExc_TypeError, + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + PyErr_Format(PyExc_TypeError, + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif + return 0; +} + +/* RaiseException */ +#if PY_MAJOR_VERSION < 3 +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + __Pyx_PyThreadState_declare + CYTHON_UNUSED_VAR(cause); + Py_XINCREF(type); + if (!value || value == Py_None) + value = NULL; + else + Py_INCREF(value); + if (!tb || tb == Py_None) + tb = NULL; + else { + Py_INCREF(tb); + if (!PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + } + if (PyType_Check(type)) { +#if CYTHON_COMPILING_IN_PYPY + if (!value) { + Py_INCREF(Py_None); + value = Py_None; + } +#endif + PyErr_NormalizeException(&type, &value, &tb); + } else { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + value = type; + type = (PyObject*) Py_TYPE(type); + Py_INCREF(type); + if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto raise_error; + } + } + __Pyx_PyThreadState_assign + __Pyx_ErrRestore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} +#else +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + PyObject* owned_instance = NULL; + if (tb == Py_None) { + tb = 0; + } else if (tb && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto bad; + } + if (value == Py_None) + value = 0; + if (PyExceptionInstance_Check(type)) { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto bad; + } + value = type; + type = (PyObject*) Py_TYPE(value); + } else if (PyExceptionClass_Check(type)) { + PyObject *instance_class = NULL; + if (value && PyExceptionInstance_Check(value)) { + instance_class = (PyObject*) Py_TYPE(value); + if (instance_class != type) { + int is_subclass = PyObject_IsSubclass(instance_class, type); + if (!is_subclass) { + instance_class = NULL; + } else if (unlikely(is_subclass == -1)) { + goto bad; + } else { + type = instance_class; + } + } + } + if (!instance_class) { + PyObject *args; + if (!value) + args = PyTuple_New(0); + else if (PyTuple_Check(value)) { + Py_INCREF(value); + args = value; + } else + args = PyTuple_Pack(1, value); + if (!args) + goto bad; + owned_instance = PyObject_Call(type, args, NULL); + Py_DECREF(args); + if (!owned_instance) + goto bad; + value = owned_instance; + if (!PyExceptionInstance_Check(value)) { + PyErr_Format(PyExc_TypeError, + "calling %R should have returned an instance of " + "BaseException, not %R", + type, Py_TYPE(value)); + goto bad; + } + } + } else { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto bad; + } + if (cause) { + PyObject *fixed_cause; + if (cause == Py_None) { + fixed_cause = NULL; + } else if (PyExceptionClass_Check(cause)) { + fixed_cause = PyObject_CallObject(cause, NULL); + if (fixed_cause == NULL) + goto bad; + } else if (PyExceptionInstance_Check(cause)) { + fixed_cause = cause; + Py_INCREF(fixed_cause); + } else { + PyErr_SetString(PyExc_TypeError, + "exception causes must derive from " + "BaseException"); + goto bad; + } + PyException_SetCause(value, fixed_cause); + } + PyErr_SetObject(type, value); + if (tb) { + #if PY_VERSION_HEX >= 0x030C00A6 + PyException_SetTraceback(value, tb); + #elif CYTHON_FAST_THREAD_STATE + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject* tmp_tb = tstate->curexc_traceback; + if (tb != tmp_tb) { + Py_INCREF(tb); + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_tb); + } +#else + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); + Py_INCREF(tb); + PyErr_Restore(tmp_type, tmp_value, tb); + Py_XDECREF(tmp_tb); +#endif + } +bad: + Py_XDECREF(owned_instance); + return; +} +#endif + +/* SwapException */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4 + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_value = exc_info->exc_value; + exc_info->exc_value = *value; + if (tmp_value == NULL || tmp_value == Py_None) { + Py_XDECREF(tmp_value); + tmp_value = NULL; + tmp_type = NULL; + tmp_tb = NULL; + } else { + tmp_type = (PyObject*) Py_TYPE(tmp_value); + Py_INCREF(tmp_type); + #if CYTHON_COMPILING_IN_CPYTHON + tmp_tb = ((PyBaseExceptionObject*) tmp_value)->traceback; + Py_XINCREF(tmp_tb); + #else + tmp_tb = PyException_GetTraceback(tmp_value); + #endif + } + #elif CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = *type; + exc_info->exc_value = *value; + exc_info->exc_traceback = *tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = *type; + tstate->exc_value = *value; + tstate->exc_traceback = *tb; + #endif + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb); + PyErr_SetExcInfo(*type, *value, *tb); + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#endif + +/* FixUpExtensionType */ +#if CYTHON_USE_TYPE_SPECS +static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type) { +#if PY_VERSION_HEX > 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + CYTHON_UNUSED_VAR(spec); + CYTHON_UNUSED_VAR(type); +#else + const PyType_Slot *slot = spec->slots; + while (slot && slot->slot && slot->slot != Py_tp_members) + slot++; + if (slot && slot->slot == Py_tp_members) { + int changed = 0; +#if !(PY_VERSION_HEX <= 0x030900b1 && CYTHON_COMPILING_IN_CPYTHON) + const +#endif + PyMemberDef *memb = (PyMemberDef*) slot->pfunc; + while (memb && memb->name) { + if (memb->name[0] == '_' && memb->name[1] == '_') { +#if PY_VERSION_HEX < 0x030900b1 + if (strcmp(memb->name, "__weaklistoffset__") == 0) { + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); + type->tp_weaklistoffset = memb->offset; + changed = 1; + } + else if (strcmp(memb->name, "__dictoffset__") == 0) { + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); + type->tp_dictoffset = memb->offset; + changed = 1; + } +#if CYTHON_METH_FASTCALL + else if (strcmp(memb->name, "__vectorcalloffset__") == 0) { + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); +#if PY_VERSION_HEX >= 0x030800b4 + type->tp_vectorcall_offset = memb->offset; +#else + type->tp_print = (printfunc) memb->offset; +#endif + changed = 1; + } +#endif +#else + if ((0)); +#endif +#if PY_VERSION_HEX <= 0x030900b1 && CYTHON_COMPILING_IN_CPYTHON + else if (strcmp(memb->name, "__module__") == 0) { + PyObject *descr; + assert(memb->type == T_OBJECT); + assert(memb->flags == 0 || memb->flags == READONLY); + descr = PyDescr_NewMember(type, memb); + if (unlikely(!descr)) + return -1; + if (unlikely(PyDict_SetItem(type->tp_dict, PyDescr_NAME(descr), descr) < 0)) { + Py_DECREF(descr); + return -1; + } + Py_DECREF(descr); + changed = 1; + } +#endif + } + memb++; + } + if (changed) + PyType_Modified(type); + } +#endif + return 0; +} +#endif + +/* PyObjectCallNoArg */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { + PyObject *arg[2] = {NULL, NULL}; + return __Pyx_PyObject_FastCall(func, arg + 1, 0 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET); +} + +/* PyObjectCallOneArg */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { + PyObject *args[2] = {NULL, arg}; + return __Pyx_PyObject_FastCall(func, args+1, 1 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET); +} + +/* PyObjectGetMethod */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) { + PyObject *attr; +#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP + __Pyx_TypeName type_name; + PyTypeObject *tp = Py_TYPE(obj); + PyObject *descr; + descrgetfunc f = NULL; + PyObject **dictptr, *dict; + int meth_found = 0; + assert (*method == NULL); + if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) { + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; + } + if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) { + return 0; + } + descr = _PyType_Lookup(tp, name); + if (likely(descr != NULL)) { + Py_INCREF(descr); +#if defined(Py_TPFLAGS_METHOD_DESCRIPTOR) && Py_TPFLAGS_METHOD_DESCRIPTOR + if (__Pyx_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR)) +#elif PY_MAJOR_VERSION >= 3 + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type))) + #endif +#else + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr))) + #endif +#endif + { + meth_found = 1; + } else { + f = Py_TYPE(descr)->tp_descr_get; + if (f != NULL && PyDescr_IsData(descr)) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + } + } + dictptr = _PyObject_GetDictPtr(obj); + if (dictptr != NULL && (dict = *dictptr) != NULL) { + Py_INCREF(dict); + attr = __Pyx_PyDict_GetItemStr(dict, name); + if (attr != NULL) { + Py_INCREF(attr); + Py_DECREF(dict); + Py_XDECREF(descr); + goto try_unpack; + } + Py_DECREF(dict); + } + if (meth_found) { + *method = descr; + return 1; + } + if (f != NULL) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + if (likely(descr != NULL)) { + *method = descr; + return 0; + } + type_name = __Pyx_PyType_GetName(tp); + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%U'", + type_name, name); +#else + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%.400s'", + type_name, PyString_AS_STRING(name)); +#endif + __Pyx_DECREF_TypeName(type_name); + return 0; +#else + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; +#endif +try_unpack: +#if CYTHON_UNPACK_METHODS + if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) { + PyObject *function = PyMethod_GET_FUNCTION(attr); + Py_INCREF(function); + Py_DECREF(attr); + *method = function; + return 1; + } +#endif + *method = attr; + return 0; +} + +/* PyObjectCallMethod0 */ +static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) { + PyObject *method = NULL, *result = NULL; + int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); + if (likely(is_method)) { + result = __Pyx_PyObject_CallOneArg(method, obj); + Py_DECREF(method); + return result; + } + if (unlikely(!method)) goto bad; + result = __Pyx_PyObject_CallNoArg(method); + Py_DECREF(method); +bad: + return result; +} + +/* ValidateBasesTuple */ +#if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS +static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases) { + Py_ssize_t i, n; +#if CYTHON_ASSUME_SAFE_MACROS + n = PyTuple_GET_SIZE(bases); +#else + n = PyTuple_Size(bases); + if (n < 0) return -1; +#endif + for (i = 1; i < n; i++) + { +#if CYTHON_AVOID_BORROWED_REFS + PyObject *b0 = PySequence_GetItem(bases, i); + if (!b0) return -1; +#elif CYTHON_ASSUME_SAFE_MACROS + PyObject *b0 = PyTuple_GET_ITEM(bases, i); +#else + PyObject *b0 = PyTuple_GetItem(bases, i); + if (!b0) return -1; +#endif + PyTypeObject *b; +#if PY_MAJOR_VERSION < 3 + if (PyClass_Check(b0)) + { + PyErr_Format(PyExc_TypeError, "base class '%.200s' is an old-style class", + PyString_AS_STRING(((PyClassObject*)b0)->cl_name)); +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + return -1; + } +#endif + b = (PyTypeObject*) b0; + if (!__Pyx_PyType_HasFeature(b, Py_TPFLAGS_HEAPTYPE)) + { + __Pyx_TypeName b_name = __Pyx_PyType_GetName(b); + PyErr_Format(PyExc_TypeError, + "base class '" __Pyx_FMT_TYPENAME "' is not a heap type", b_name); + __Pyx_DECREF_TypeName(b_name); +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + return -1; + } + if (dictoffset == 0) + { + Py_ssize_t b_dictoffset = 0; +#if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY + b_dictoffset = b->tp_dictoffset; +#else + PyObject *py_b_dictoffset = PyObject_GetAttrString((PyObject*)b, "__dictoffset__"); + if (!py_b_dictoffset) goto dictoffset_return; + b_dictoffset = PyLong_AsSsize_t(py_b_dictoffset); + Py_DECREF(py_b_dictoffset); + if (b_dictoffset == -1 && PyErr_Occurred()) goto dictoffset_return; +#endif + if (b_dictoffset) { + { + __Pyx_TypeName b_name = __Pyx_PyType_GetName(b); + PyErr_Format(PyExc_TypeError, + "extension type '%.200s' has no __dict__ slot, " + "but base type '" __Pyx_FMT_TYPENAME "' has: " + "either add 'cdef dict __dict__' to the extension type " + "or add '__slots__ = [...]' to the base type", + type_name, b_name); + __Pyx_DECREF_TypeName(b_name); + } +#if !(CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY) + dictoffset_return: +#endif +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + return -1; + } + } +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + } + return 0; +} +#endif + +/* PyType_Ready */ +static int __Pyx_PyType_Ready(PyTypeObject *t) { +#if CYTHON_USE_TYPE_SPECS || !(CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API) || defined(PYSTON_MAJOR_VERSION) + (void)__Pyx_PyObject_CallMethod0; +#if CYTHON_USE_TYPE_SPECS + (void)__Pyx_validate_bases_tuple; +#endif + return PyType_Ready(t); +#else + int r; + PyObject *bases = __Pyx_PyType_GetSlot(t, tp_bases, PyObject*); + if (bases && unlikely(__Pyx_validate_bases_tuple(t->tp_name, t->tp_dictoffset, bases) == -1)) + return -1; +#if PY_VERSION_HEX >= 0x03050000 && !defined(PYSTON_MAJOR_VERSION) + { + int gc_was_enabled; + #if PY_VERSION_HEX >= 0x030A00b1 + gc_was_enabled = PyGC_Disable(); + (void)__Pyx_PyObject_CallMethod0; + #else + PyObject *ret, *py_status; + PyObject *gc = NULL; + #if PY_VERSION_HEX >= 0x030700a1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM+0 >= 0x07030400) + gc = PyImport_GetModule(__pyx_kp_u_gc); + #endif + if (unlikely(!gc)) gc = PyImport_Import(__pyx_kp_u_gc); + if (unlikely(!gc)) return -1; + py_status = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_isenabled); + if (unlikely(!py_status)) { + Py_DECREF(gc); + return -1; + } + gc_was_enabled = __Pyx_PyObject_IsTrue(py_status); + Py_DECREF(py_status); + if (gc_was_enabled > 0) { + ret = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_disable); + if (unlikely(!ret)) { + Py_DECREF(gc); + return -1; + } + Py_DECREF(ret); + } else if (unlikely(gc_was_enabled == -1)) { + Py_DECREF(gc); + return -1; + } + #endif + t->tp_flags |= Py_TPFLAGS_HEAPTYPE; +#if PY_VERSION_HEX >= 0x030A0000 + t->tp_flags |= Py_TPFLAGS_IMMUTABLETYPE; +#endif +#else + (void)__Pyx_PyObject_CallMethod0; +#endif + r = PyType_Ready(t); +#if PY_VERSION_HEX >= 0x03050000 && !defined(PYSTON_MAJOR_VERSION) + t->tp_flags &= ~Py_TPFLAGS_HEAPTYPE; + #if PY_VERSION_HEX >= 0x030A00b1 + if (gc_was_enabled) + PyGC_Enable(); + #else + if (gc_was_enabled) { + PyObject *tp, *v, *tb; + PyErr_Fetch(&tp, &v, &tb); + ret = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_enable); + if (likely(ret || r == -1)) { + Py_XDECREF(ret); + PyErr_Restore(tp, v, tb); + } else { + Py_XDECREF(tp); + Py_XDECREF(v); + Py_XDECREF(tb); + r = -1; + } + } + Py_DECREF(gc); + #endif + } +#endif + return r; +#endif +} + +/* PyObject_GenericGetAttrNoDict */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) { + __Pyx_TypeName type_name = __Pyx_PyType_GetName(tp); + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%U'", + type_name, attr_name); +#else + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%.400s'", + type_name, PyString_AS_STRING(attr_name)); +#endif + __Pyx_DECREF_TypeName(type_name); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) { + PyObject *descr; + PyTypeObject *tp = Py_TYPE(obj); + if (unlikely(!PyString_Check(attr_name))) { + return PyObject_GenericGetAttr(obj, attr_name); + } + assert(!tp->tp_dictoffset); + descr = _PyType_Lookup(tp, attr_name); + if (unlikely(!descr)) { + return __Pyx_RaiseGenericGetAttributeError(tp, attr_name); + } + Py_INCREF(descr); + #if PY_MAJOR_VERSION < 3 + if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS))) + #endif + { + descrgetfunc f = Py_TYPE(descr)->tp_descr_get; + if (unlikely(f)) { + PyObject *res = f(descr, obj, (PyObject *)tp); + Py_DECREF(descr); + return res; + } + } + return descr; +} +#endif + +/* PyObject_GenericGetAttr */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) { + if (unlikely(Py_TYPE(obj)->tp_dictoffset)) { + return PyObject_GenericGetAttr(obj, attr_name); + } + return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name); +} +#endif + +/* SetupReduce */ +#if !CYTHON_COMPILING_IN_LIMITED_API +static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { + int ret; + PyObject *name_attr; + name_attr = __Pyx_PyObject_GetAttrStrNoError(meth, __pyx_n_s_name); + if (likely(name_attr)) { + ret = PyObject_RichCompareBool(name_attr, name, Py_EQ); + } else { + ret = -1; + } + if (unlikely(ret < 0)) { + PyErr_Clear(); + ret = 0; + } + Py_XDECREF(name_attr); + return ret; +} +static int __Pyx_setup_reduce(PyObject* type_obj) { + int ret = 0; + PyObject *object_reduce = NULL; + PyObject *object_getstate = NULL; + PyObject *object_reduce_ex = NULL; + PyObject *reduce = NULL; + PyObject *reduce_ex = NULL; + PyObject *reduce_cython = NULL; + PyObject *setstate = NULL; + PyObject *setstate_cython = NULL; + PyObject *getstate = NULL; +#if CYTHON_USE_PYTYPE_LOOKUP + getstate = _PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate); +#else + getstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_getstate); + if (!getstate && PyErr_Occurred()) { + goto __PYX_BAD; + } +#endif + if (getstate) { +#if CYTHON_USE_PYTYPE_LOOKUP + object_getstate = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_getstate); +#else + object_getstate = __Pyx_PyObject_GetAttrStrNoError((PyObject*)&PyBaseObject_Type, __pyx_n_s_getstate); + if (!object_getstate && PyErr_Occurred()) { + goto __PYX_BAD; + } +#endif + if (object_getstate != getstate) { + goto __PYX_GOOD; + } + } +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; +#else + object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; +#endif + reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_BAD; + if (reduce_ex == object_reduce_ex) { +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; +#else + object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; +#endif + reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD; + if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { + reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython); + if (likely(reduce_cython)) { + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + } else if (reduce == object_reduce || PyErr_Occurred()) { + goto __PYX_BAD; + } + setstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate); + if (!setstate) PyErr_Clear(); + if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) { + setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython); + if (likely(setstate_cython)) { + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + } else if (!setstate || PyErr_Occurred()) { + goto __PYX_BAD; + } + } + PyType_Modified((PyTypeObject*)type_obj); + } + } + goto __PYX_GOOD; +__PYX_BAD: + if (!PyErr_Occurred()) { + __Pyx_TypeName type_obj_name = + __Pyx_PyType_GetName((PyTypeObject*)type_obj); + PyErr_Format(PyExc_RuntimeError, + "Unable to initialize pickling for " __Pyx_FMT_TYPENAME, type_obj_name); + __Pyx_DECREF_TypeName(type_obj_name); + } + ret = -1; +__PYX_GOOD: +#if !CYTHON_USE_PYTYPE_LOOKUP + Py_XDECREF(object_reduce); + Py_XDECREF(object_reduce_ex); + Py_XDECREF(object_getstate); + Py_XDECREF(getstate); +#endif + Py_XDECREF(reduce); + Py_XDECREF(reduce_ex); + Py_XDECREF(reduce_cython); + Py_XDECREF(setstate); + Py_XDECREF(setstate_cython); + return ret; +} +#endif + +/* Import */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { + PyObject *module = 0; + PyObject *empty_dict = 0; + PyObject *empty_list = 0; + #if PY_MAJOR_VERSION < 3 + PyObject *py_import; + py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); + if (unlikely(!py_import)) + goto bad; + if (!from_list) { + empty_list = PyList_New(0); + if (unlikely(!empty_list)) + goto bad; + from_list = empty_list; + } + #endif + empty_dict = PyDict_New(); + if (unlikely(!empty_dict)) + goto bad; + { + #if PY_MAJOR_VERSION >= 3 + if (level == -1) { + if (strchr(__Pyx_MODULE_NAME, '.') != NULL) { + module = PyImport_ImportModuleLevelObject( + name, __pyx_d, empty_dict, from_list, 1); + if (unlikely(!module)) { + if (unlikely(!PyErr_ExceptionMatches(PyExc_ImportError))) + goto bad; + PyErr_Clear(); + } + } + level = 0; + } + #endif + if (!module) { + #if PY_MAJOR_VERSION < 3 + PyObject *py_level = PyInt_FromLong(level); + if (unlikely(!py_level)) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, __pyx_d, empty_dict, from_list, py_level, (PyObject *)NULL); + Py_DECREF(py_level); + #else + module = PyImport_ImportModuleLevelObject( + name, __pyx_d, empty_dict, from_list, level); + #endif + } + } +bad: + Py_XDECREF(empty_dict); + Py_XDECREF(empty_list); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(py_import); + #endif + return module; +} + +/* ImportDottedModule */ +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx__ImportDottedModule_Error(PyObject *name, PyObject *parts_tuple, Py_ssize_t count) { + PyObject *partial_name = NULL, *slice = NULL, *sep = NULL; + if (unlikely(PyErr_Occurred())) { + PyErr_Clear(); + } + if (likely(PyTuple_GET_SIZE(parts_tuple) == count)) { + partial_name = name; + } else { + slice = PySequence_GetSlice(parts_tuple, 0, count); + if (unlikely(!slice)) + goto bad; + sep = PyUnicode_FromStringAndSize(".", 1); + if (unlikely(!sep)) + goto bad; + partial_name = PyUnicode_Join(sep, slice); + } + PyErr_Format( +#if PY_MAJOR_VERSION < 3 + PyExc_ImportError, + "No module named '%s'", PyString_AS_STRING(partial_name)); +#else +#if PY_VERSION_HEX >= 0x030600B1 + PyExc_ModuleNotFoundError, +#else + PyExc_ImportError, +#endif + "No module named '%U'", partial_name); +#endif +bad: + Py_XDECREF(sep); + Py_XDECREF(slice); + Py_XDECREF(partial_name); + return NULL; +} +#endif +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx__ImportDottedModule_Lookup(PyObject *name) { + PyObject *imported_module; +#if PY_VERSION_HEX < 0x030700A1 || (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM < 0x07030400) + PyObject *modules = PyImport_GetModuleDict(); + if (unlikely(!modules)) + return NULL; + imported_module = __Pyx_PyDict_GetItemStr(modules, name); + Py_XINCREF(imported_module); +#else + imported_module = PyImport_GetModule(name); +#endif + return imported_module; +} +#endif +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple) { + Py_ssize_t i, nparts; + nparts = PyTuple_GET_SIZE(parts_tuple); + for (i=1; i < nparts && module; i++) { + PyObject *part, *submodule; +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + part = PyTuple_GET_ITEM(parts_tuple, i); +#else + part = PySequence_ITEM(parts_tuple, i); +#endif + submodule = __Pyx_PyObject_GetAttrStrNoError(module, part); +#if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) + Py_DECREF(part); +#endif + Py_DECREF(module); + module = submodule; + } + if (unlikely(!module)) { + return __Pyx__ImportDottedModule_Error(name, parts_tuple, i); + } + return module; +} +#endif +static PyObject *__Pyx__ImportDottedModule(PyObject *name, PyObject *parts_tuple) { +#if PY_MAJOR_VERSION < 3 + PyObject *module, *from_list, *star = __pyx_n_s__2; + CYTHON_UNUSED_VAR(parts_tuple); + from_list = PyList_New(1); + if (unlikely(!from_list)) + return NULL; + Py_INCREF(star); + PyList_SET_ITEM(from_list, 0, star); + module = __Pyx_Import(name, from_list, 0); + Py_DECREF(from_list); + return module; +#else + PyObject *imported_module; + PyObject *module = __Pyx_Import(name, NULL, 0); + if (!parts_tuple || unlikely(!module)) + return module; + imported_module = __Pyx__ImportDottedModule_Lookup(name); + if (likely(imported_module)) { + Py_DECREF(module); + return imported_module; + } + PyErr_Clear(); + return __Pyx_ImportDottedModule_WalkParts(module, name, parts_tuple); +#endif +} +static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030400B1 + PyObject *module = __Pyx__ImportDottedModule_Lookup(name); + if (likely(module)) { + PyObject *spec = __Pyx_PyObject_GetAttrStrNoError(module, __pyx_n_s_spec); + if (likely(spec)) { + PyObject *unsafe = __Pyx_PyObject_GetAttrStrNoError(spec, __pyx_n_s_initializing); + if (likely(!unsafe || !__Pyx_PyObject_IsTrue(unsafe))) { + Py_DECREF(spec); + spec = NULL; + } + Py_XDECREF(unsafe); + } + if (likely(!spec)) { + PyErr_Clear(); + return module; + } + Py_DECREF(spec); + Py_DECREF(module); + } else if (PyErr_Occurred()) { + PyErr_Clear(); + } +#endif + return __Pyx__ImportDottedModule(name, parts_tuple); +} + +/* FetchSharedCythonModule */ +static PyObject *__Pyx_FetchSharedCythonABIModule(void) { + return __Pyx_PyImport_AddModuleRef((char*) __PYX_ABI_MODULE_NAME); +} + +/* FetchCommonType */ +static int __Pyx_VerifyCachedType(PyObject *cached_type, + const char *name, + Py_ssize_t basicsize, + Py_ssize_t expected_basicsize) { + if (!PyType_Check(cached_type)) { + PyErr_Format(PyExc_TypeError, + "Shared Cython type %.200s is not a type object", name); + return -1; + } + if (basicsize != expected_basicsize) { + PyErr_Format(PyExc_TypeError, + "Shared Cython type %.200s has the wrong size, try recompiling", + name); + return -1; + } + return 0; +} +#if !CYTHON_USE_TYPE_SPECS +static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) { + PyObject* abi_module; + const char* object_name; + PyTypeObject *cached_type = NULL; + abi_module = __Pyx_FetchSharedCythonABIModule(); + if (!abi_module) return NULL; + object_name = strrchr(type->tp_name, '.'); + object_name = object_name ? object_name+1 : type->tp_name; + cached_type = (PyTypeObject*) PyObject_GetAttrString(abi_module, object_name); + if (cached_type) { + if (__Pyx_VerifyCachedType( + (PyObject *)cached_type, + object_name, + cached_type->tp_basicsize, + type->tp_basicsize) < 0) { + goto bad; + } + goto done; + } + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; + PyErr_Clear(); + if (PyType_Ready(type) < 0) goto bad; + if (PyObject_SetAttrString(abi_module, object_name, (PyObject *)type) < 0) + goto bad; + Py_INCREF(type); + cached_type = type; +done: + Py_DECREF(abi_module); + return cached_type; +bad: + Py_XDECREF(cached_type); + cached_type = NULL; + goto done; +} +#else +static PyTypeObject *__Pyx_FetchCommonTypeFromSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) { + PyObject *abi_module, *cached_type = NULL; + const char* object_name = strrchr(spec->name, '.'); + object_name = object_name ? object_name+1 : spec->name; + abi_module = __Pyx_FetchSharedCythonABIModule(); + if (!abi_module) return NULL; + cached_type = PyObject_GetAttrString(abi_module, object_name); + if (cached_type) { + Py_ssize_t basicsize; +#if CYTHON_COMPILING_IN_LIMITED_API + PyObject *py_basicsize; + py_basicsize = PyObject_GetAttrString(cached_type, "__basicsize__"); + if (unlikely(!py_basicsize)) goto bad; + basicsize = PyLong_AsSsize_t(py_basicsize); + Py_DECREF(py_basicsize); + py_basicsize = 0; + if (unlikely(basicsize == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad; +#else + basicsize = likely(PyType_Check(cached_type)) ? ((PyTypeObject*) cached_type)->tp_basicsize : -1; +#endif + if (__Pyx_VerifyCachedType( + cached_type, + object_name, + basicsize, + spec->basicsize) < 0) { + goto bad; + } + goto done; + } + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; + PyErr_Clear(); + CYTHON_UNUSED_VAR(module); + cached_type = __Pyx_PyType_FromModuleAndSpec(abi_module, spec, bases); + if (unlikely(!cached_type)) goto bad; + if (unlikely(__Pyx_fix_up_extension_type_from_spec(spec, (PyTypeObject *) cached_type) < 0)) goto bad; + if (PyObject_SetAttrString(abi_module, object_name, cached_type) < 0) goto bad; +done: + Py_DECREF(abi_module); + assert(cached_type == NULL || PyType_Check(cached_type)); + return (PyTypeObject *) cached_type; +bad: + Py_XDECREF(cached_type); + cached_type = NULL; + goto done; +} +#endif + +/* PyVectorcallFastCallDict */ +#if CYTHON_METH_FASTCALL +static PyObject *__Pyx_PyVectorcall_FastCallDict_kw(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw) +{ + PyObject *res = NULL; + PyObject *kwnames; + PyObject **newargs; + PyObject **kwvalues; + Py_ssize_t i, pos; + size_t j; + PyObject *key, *value; + unsigned long keys_are_strings; + Py_ssize_t nkw = PyDict_GET_SIZE(kw); + newargs = (PyObject **)PyMem_Malloc((nargs + (size_t)nkw) * sizeof(args[0])); + if (unlikely(newargs == NULL)) { + PyErr_NoMemory(); + return NULL; + } + for (j = 0; j < nargs; j++) newargs[j] = args[j]; + kwnames = PyTuple_New(nkw); + if (unlikely(kwnames == NULL)) { + PyMem_Free(newargs); + return NULL; + } + kwvalues = newargs + nargs; + pos = i = 0; + keys_are_strings = Py_TPFLAGS_UNICODE_SUBCLASS; + while (PyDict_Next(kw, &pos, &key, &value)) { + keys_are_strings &= Py_TYPE(key)->tp_flags; + Py_INCREF(key); + Py_INCREF(value); + PyTuple_SET_ITEM(kwnames, i, key); + kwvalues[i] = value; + i++; + } + if (unlikely(!keys_are_strings)) { + PyErr_SetString(PyExc_TypeError, "keywords must be strings"); + goto cleanup; + } + res = vc(func, newargs, nargs, kwnames); +cleanup: + Py_DECREF(kwnames); + for (i = 0; i < nkw; i++) + Py_DECREF(kwvalues[i]); + PyMem_Free(newargs); + return res; +} +static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw) +{ + if (likely(kw == NULL) || PyDict_GET_SIZE(kw) == 0) { + return vc(func, args, nargs, NULL); + } + return __Pyx_PyVectorcall_FastCallDict_kw(func, vc, args, nargs, kw); +} +#endif + +/* CythonFunctionShared */ +#if CYTHON_COMPILING_IN_LIMITED_API +static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc) { + if (__Pyx_CyFunction_Check(func)) { + return PyCFunction_GetFunction(((__pyx_CyFunctionObject*)func)->func) == (PyCFunction) cfunc; + } else if (PyCFunction_Check(func)) { + return PyCFunction_GetFunction(func) == (PyCFunction) cfunc; + } + return 0; +} +#else +static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc) { + return __Pyx_CyOrPyCFunction_Check(func) && __Pyx_CyOrPyCFunction_GET_FUNCTION(func) == (PyCFunction) cfunc; +} +#endif +static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj) { +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + __Pyx_Py_XDECREF_SET( + __Pyx_CyFunction_GetClassObj(f), + ((classobj) ? __Pyx_NewRef(classobj) : NULL)); +#else + __Pyx_Py_XDECREF_SET( + ((PyCMethodObject *) (f))->mm_class, + (PyTypeObject*)((classobj) ? __Pyx_NewRef(classobj) : NULL)); +#endif +} +static PyObject * +__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, void *closure) +{ + CYTHON_UNUSED_VAR(closure); + if (unlikely(op->func_doc == NULL)) { +#if CYTHON_COMPILING_IN_LIMITED_API + op->func_doc = PyObject_GetAttrString(op->func, "__doc__"); + if (unlikely(!op->func_doc)) return NULL; +#else + if (((PyCFunctionObject*)op)->m_ml->ml_doc) { +#if PY_MAJOR_VERSION >= 3 + op->func_doc = PyUnicode_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc); +#else + op->func_doc = PyString_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc); +#endif + if (unlikely(op->func_doc == NULL)) + return NULL; + } else { + Py_INCREF(Py_None); + return Py_None; + } +#endif + } + Py_INCREF(op->func_doc); + return op->func_doc; +} +static int +__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (value == NULL) { + value = Py_None; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_doc, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (unlikely(op->func_name == NULL)) { +#if CYTHON_COMPILING_IN_LIMITED_API + op->func_name = PyObject_GetAttrString(op->func, "__name__"); +#elif PY_MAJOR_VERSION >= 3 + op->func_name = PyUnicode_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name); +#else + op->func_name = PyString_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name); +#endif + if (unlikely(op->func_name == NULL)) + return NULL; + } + Py_INCREF(op->func_name); + return op->func_name; +} +static int +__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) +#else + if (unlikely(value == NULL || !PyString_Check(value))) +#endif + { + PyErr_SetString(PyExc_TypeError, + "__name__ must be set to a string object"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_name, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + Py_INCREF(op->func_qualname); + return op->func_qualname; +} +static int +__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) +#else + if (unlikely(value == NULL || !PyString_Check(value))) +#endif + { + PyErr_SetString(PyExc_TypeError, + "__qualname__ must be set to a string object"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_qualname, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (unlikely(op->func_dict == NULL)) { + op->func_dict = PyDict_New(); + if (unlikely(op->func_dict == NULL)) + return NULL; + } + Py_INCREF(op->func_dict); + return op->func_dict; +} +static int +__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (unlikely(value == NULL)) { + PyErr_SetString(PyExc_TypeError, + "function's dictionary may not be deleted"); + return -1; + } + if (unlikely(!PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "setting function's dictionary to a non-dict"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_dict, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + Py_INCREF(op->func_globals); + return op->func_globals; +} +static PyObject * +__Pyx_CyFunction_get_closure(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(op); + CYTHON_UNUSED_VAR(context); + Py_INCREF(Py_None); + return Py_None; +} +static PyObject * +__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op, void *context) +{ + PyObject* result = (op->func_code) ? op->func_code : Py_None; + CYTHON_UNUSED_VAR(context); + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) { + int result = 0; + PyObject *res = op->defaults_getter((PyObject *) op); + if (unlikely(!res)) + return -1; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + op->defaults_tuple = PyTuple_GET_ITEM(res, 0); + Py_INCREF(op->defaults_tuple); + op->defaults_kwdict = PyTuple_GET_ITEM(res, 1); + Py_INCREF(op->defaults_kwdict); + #else + op->defaults_tuple = __Pyx_PySequence_ITEM(res, 0); + if (unlikely(!op->defaults_tuple)) result = -1; + else { + op->defaults_kwdict = __Pyx_PySequence_ITEM(res, 1); + if (unlikely(!op->defaults_kwdict)) result = -1; + } + #endif + Py_DECREF(res); + return result; +} +static int +__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + if (!value) { + value = Py_None; + } else if (unlikely(value != Py_None && !PyTuple_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "__defaults__ must be set to a tuple object"); + return -1; + } + PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__defaults__ will not " + "currently affect the values used in function calls", 1); + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->defaults_tuple, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op, void *context) { + PyObject* result = op->defaults_tuple; + CYTHON_UNUSED_VAR(context); + if (unlikely(!result)) { + if (op->defaults_getter) { + if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL; + result = op->defaults_tuple; + } else { + result = Py_None; + } + } + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + if (!value) { + value = Py_None; + } else if (unlikely(value != Py_None && !PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "__kwdefaults__ must be set to a dict object"); + return -1; + } + PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__kwdefaults__ will not " + "currently affect the values used in function calls", 1); + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->defaults_kwdict, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op, void *context) { + PyObject* result = op->defaults_kwdict; + CYTHON_UNUSED_VAR(context); + if (unlikely(!result)) { + if (op->defaults_getter) { + if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL; + result = op->defaults_kwdict; + } else { + result = Py_None; + } + } + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + if (!value || value == Py_None) { + value = NULL; + } else if (unlikely(!PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "__annotations__ must be set to a dict object"); + return -1; + } + Py_XINCREF(value); + __Pyx_Py_XDECREF_SET(op->func_annotations, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op, void *context) { + PyObject* result = op->func_annotations; + CYTHON_UNUSED_VAR(context); + if (unlikely(!result)) { + result = PyDict_New(); + if (unlikely(!result)) return NULL; + op->func_annotations = result; + } + Py_INCREF(result); + return result; +} +static PyObject * +__Pyx_CyFunction_get_is_coroutine(__pyx_CyFunctionObject *op, void *context) { + int is_coroutine; + CYTHON_UNUSED_VAR(context); + if (op->func_is_coroutine) { + return __Pyx_NewRef(op->func_is_coroutine); + } + is_coroutine = op->flags & __Pyx_CYFUNCTION_COROUTINE; +#if PY_VERSION_HEX >= 0x03050000 + if (is_coroutine) { + PyObject *module, *fromlist, *marker = __pyx_n_s_is_coroutine; + fromlist = PyList_New(1); + if (unlikely(!fromlist)) return NULL; + Py_INCREF(marker); +#if CYTHON_ASSUME_SAFE_MACROS + PyList_SET_ITEM(fromlist, 0, marker); +#else + if (unlikely(PyList_SetItem(fromlist, 0, marker) < 0)) { + Py_DECREF(marker); + Py_DECREF(fromlist); + return NULL; + } +#endif + module = PyImport_ImportModuleLevelObject(__pyx_n_s_asyncio_coroutines, NULL, NULL, fromlist, 0); + Py_DECREF(fromlist); + if (unlikely(!module)) goto ignore; + op->func_is_coroutine = __Pyx_PyObject_GetAttrStr(module, marker); + Py_DECREF(module); + if (likely(op->func_is_coroutine)) { + return __Pyx_NewRef(op->func_is_coroutine); + } +ignore: + PyErr_Clear(); + } +#endif + op->func_is_coroutine = __Pyx_PyBool_FromLong(is_coroutine); + return __Pyx_NewRef(op->func_is_coroutine); +} +#if CYTHON_COMPILING_IN_LIMITED_API +static PyObject * +__Pyx_CyFunction_get_module(__pyx_CyFunctionObject *op, void *context) { + CYTHON_UNUSED_VAR(context); + return PyObject_GetAttrString(op->func, "__module__"); +} +static int +__Pyx_CyFunction_set_module(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + return PyObject_SetAttrString(op->func, "__module__", value); +} +#endif +static PyGetSetDef __pyx_CyFunction_getsets[] = { + {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, + {(char *) "__doc__", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, + {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, + {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, + {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0}, + {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, + {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, + {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, + {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, + {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, + {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, + {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, + {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, + {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, + {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, + {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0}, + {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0}, + {(char *) "_is_coroutine", (getter)__Pyx_CyFunction_get_is_coroutine, 0, 0, 0}, +#if CYTHON_COMPILING_IN_LIMITED_API + {"__module__", (getter)__Pyx_CyFunction_get_module, (setter)__Pyx_CyFunction_set_module, 0, 0}, +#endif + {0, 0, 0, 0, 0} +}; +static PyMemberDef __pyx_CyFunction_members[] = { +#if !CYTHON_COMPILING_IN_LIMITED_API + {(char *) "__module__", T_OBJECT, offsetof(PyCFunctionObject, m_module), 0, 0}, +#endif +#if CYTHON_USE_TYPE_SPECS + {(char *) "__dictoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_dict), READONLY, 0}, +#if CYTHON_METH_FASTCALL +#if CYTHON_BACKPORT_VECTORCALL + {(char *) "__vectorcalloffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_vectorcall), READONLY, 0}, +#else +#if !CYTHON_COMPILING_IN_LIMITED_API + {(char *) "__vectorcalloffset__", T_PYSSIZET, offsetof(PyCFunctionObject, vectorcall), READONLY, 0}, +#endif +#endif +#endif +#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API + {(char *) "__weaklistoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_weakreflist), READONLY, 0}, +#else + {(char *) "__weaklistoffset__", T_PYSSIZET, offsetof(PyCFunctionObject, m_weakreflist), READONLY, 0}, +#endif +#endif + {0, 0, 0, 0, 0} +}; +static PyObject * +__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, PyObject *args) +{ + CYTHON_UNUSED_VAR(args); +#if PY_MAJOR_VERSION >= 3 + Py_INCREF(m->func_qualname); + return m->func_qualname; +#else + return PyString_FromString(((PyCFunctionObject*)m)->m_ml->ml_name); +#endif +} +static PyMethodDef __pyx_CyFunction_methods[] = { + {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0}, + {0, 0, 0, 0} +}; +#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API +#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist) +#else +#define __Pyx_CyFunction_weakreflist(cyfunc) (((PyCFunctionObject*)cyfunc)->m_weakreflist) +#endif +static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject *op, PyMethodDef *ml, int flags, PyObject* qualname, + PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { +#if !CYTHON_COMPILING_IN_LIMITED_API + PyCFunctionObject *cf = (PyCFunctionObject*) op; +#endif + if (unlikely(op == NULL)) + return NULL; +#if CYTHON_COMPILING_IN_LIMITED_API + op->func = PyCFunction_NewEx(ml, (PyObject*)op, module); + if (unlikely(!op->func)) return NULL; +#endif + op->flags = flags; + __Pyx_CyFunction_weakreflist(op) = NULL; +#if !CYTHON_COMPILING_IN_LIMITED_API + cf->m_ml = ml; + cf->m_self = (PyObject *) op; +#endif + Py_XINCREF(closure); + op->func_closure = closure; +#if !CYTHON_COMPILING_IN_LIMITED_API + Py_XINCREF(module); + cf->m_module = module; +#endif + op->func_dict = NULL; + op->func_name = NULL; + Py_INCREF(qualname); + op->func_qualname = qualname; + op->func_doc = NULL; +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + op->func_classobj = NULL; +#else + ((PyCMethodObject*)op)->mm_class = NULL; +#endif + op->func_globals = globals; + Py_INCREF(op->func_globals); + Py_XINCREF(code); + op->func_code = code; + op->defaults_pyobjects = 0; + op->defaults_size = 0; + op->defaults = NULL; + op->defaults_tuple = NULL; + op->defaults_kwdict = NULL; + op->defaults_getter = NULL; + op->func_annotations = NULL; + op->func_is_coroutine = NULL; +#if CYTHON_METH_FASTCALL + switch (ml->ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O | METH_KEYWORDS | METH_METHOD)) { + case METH_NOARGS: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_NOARGS; + break; + case METH_O: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_O; + break; + case METH_METHOD | METH_FASTCALL | METH_KEYWORDS: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD; + break; + case METH_FASTCALL | METH_KEYWORDS: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS; + break; + case METH_VARARGS | METH_KEYWORDS: + __Pyx_CyFunction_func_vectorcall(op) = NULL; + break; + default: + PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction"); + Py_DECREF(op); + return NULL; + } +#endif + return (PyObject *) op; +} +static int +__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m) +{ + Py_CLEAR(m->func_closure); +#if CYTHON_COMPILING_IN_LIMITED_API + Py_CLEAR(m->func); +#else + Py_CLEAR(((PyCFunctionObject*)m)->m_module); +#endif + Py_CLEAR(m->func_dict); + Py_CLEAR(m->func_name); + Py_CLEAR(m->func_qualname); + Py_CLEAR(m->func_doc); + Py_CLEAR(m->func_globals); + Py_CLEAR(m->func_code); +#if !CYTHON_COMPILING_IN_LIMITED_API +#if PY_VERSION_HEX < 0x030900B1 + Py_CLEAR(__Pyx_CyFunction_GetClassObj(m)); +#else + { + PyObject *cls = (PyObject*) ((PyCMethodObject *) (m))->mm_class; + ((PyCMethodObject *) (m))->mm_class = NULL; + Py_XDECREF(cls); + } +#endif +#endif + Py_CLEAR(m->defaults_tuple); + Py_CLEAR(m->defaults_kwdict); + Py_CLEAR(m->func_annotations); + Py_CLEAR(m->func_is_coroutine); + if (m->defaults) { + PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); + int i; + for (i = 0; i < m->defaults_pyobjects; i++) + Py_XDECREF(pydefaults[i]); + PyObject_Free(m->defaults); + m->defaults = NULL; + } + return 0; +} +static void __Pyx__CyFunction_dealloc(__pyx_CyFunctionObject *m) +{ + if (__Pyx_CyFunction_weakreflist(m) != NULL) + PyObject_ClearWeakRefs((PyObject *) m); + __Pyx_CyFunction_clear(m); + __Pyx_PyHeapTypeObject_GC_Del(m); +} +static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m) +{ + PyObject_GC_UnTrack(m); + __Pyx__CyFunction_dealloc(m); +} +static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg) +{ + Py_VISIT(m->func_closure); +#if CYTHON_COMPILING_IN_LIMITED_API + Py_VISIT(m->func); +#else + Py_VISIT(((PyCFunctionObject*)m)->m_module); +#endif + Py_VISIT(m->func_dict); + Py_VISIT(m->func_name); + Py_VISIT(m->func_qualname); + Py_VISIT(m->func_doc); + Py_VISIT(m->func_globals); + Py_VISIT(m->func_code); +#if !CYTHON_COMPILING_IN_LIMITED_API + Py_VISIT(__Pyx_CyFunction_GetClassObj(m)); +#endif + Py_VISIT(m->defaults_tuple); + Py_VISIT(m->defaults_kwdict); + Py_VISIT(m->func_is_coroutine); + if (m->defaults) { + PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); + int i; + for (i = 0; i < m->defaults_pyobjects; i++) + Py_VISIT(pydefaults[i]); + } + return 0; +} +static PyObject* +__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op) +{ +#if PY_MAJOR_VERSION >= 3 + return PyUnicode_FromFormat("", + op->func_qualname, (void *)op); +#else + return PyString_FromFormat("", + PyString_AsString(op->func_qualname), (void *)op); +#endif +} +static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) { +#if CYTHON_COMPILING_IN_LIMITED_API + PyObject *f = ((__pyx_CyFunctionObject*)func)->func; + PyObject *py_name = NULL; + PyCFunction meth; + int flags; + meth = PyCFunction_GetFunction(f); + if (unlikely(!meth)) return NULL; + flags = PyCFunction_GetFlags(f); + if (unlikely(flags < 0)) return NULL; +#else + PyCFunctionObject* f = (PyCFunctionObject*)func; + PyCFunction meth = f->m_ml->ml_meth; + int flags = f->m_ml->ml_flags; +#endif + Py_ssize_t size; + switch (flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) { + case METH_VARARGS: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) + return (*meth)(self, arg); + break; + case METH_VARARGS | METH_KEYWORDS: + return (*(PyCFunctionWithKeywords)(void*)meth)(self, arg, kw); + case METH_NOARGS: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) { +#if CYTHON_ASSUME_SAFE_MACROS + size = PyTuple_GET_SIZE(arg); +#else + size = PyTuple_Size(arg); + if (unlikely(size < 0)) return NULL; +#endif + if (likely(size == 0)) + return (*meth)(self, NULL); +#if CYTHON_COMPILING_IN_LIMITED_API + py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); + if (!py_name) return NULL; + PyErr_Format(PyExc_TypeError, + "%.200S() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + py_name, size); + Py_DECREF(py_name); +#else + PyErr_Format(PyExc_TypeError, + "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + f->m_ml->ml_name, size); +#endif + return NULL; + } + break; + case METH_O: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) { +#if CYTHON_ASSUME_SAFE_MACROS + size = PyTuple_GET_SIZE(arg); +#else + size = PyTuple_Size(arg); + if (unlikely(size < 0)) return NULL; +#endif + if (likely(size == 1)) { + PyObject *result, *arg0; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + arg0 = PyTuple_GET_ITEM(arg, 0); + #else + arg0 = __Pyx_PySequence_ITEM(arg, 0); if (unlikely(!arg0)) return NULL; + #endif + result = (*meth)(self, arg0); + #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) + Py_DECREF(arg0); + #endif + return result; + } +#if CYTHON_COMPILING_IN_LIMITED_API + py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); + if (!py_name) return NULL; + PyErr_Format(PyExc_TypeError, + "%.200S() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + py_name, size); + Py_DECREF(py_name); +#else + PyErr_Format(PyExc_TypeError, + "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + f->m_ml->ml_name, size); +#endif + return NULL; + } + break; + default: + PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction"); + return NULL; + } +#if CYTHON_COMPILING_IN_LIMITED_API + py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); + if (!py_name) return NULL; + PyErr_Format(PyExc_TypeError, "%.200S() takes no keyword arguments", + py_name); + Py_DECREF(py_name); +#else + PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments", + f->m_ml->ml_name); +#endif + return NULL; +} +static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *self, *result; +#if CYTHON_COMPILING_IN_LIMITED_API + self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)func)->func); + if (unlikely(!self) && PyErr_Occurred()) return NULL; +#else + self = ((PyCFunctionObject*)func)->m_self; +#endif + result = __Pyx_CyFunction_CallMethod(func, self, arg, kw); + return result; +} +static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) { + PyObject *result; + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func; +#if CYTHON_METH_FASTCALL + __pyx_vectorcallfunc vc = __Pyx_CyFunction_func_vectorcall(cyfunc); + if (vc) { +#if CYTHON_ASSUME_SAFE_MACROS + return __Pyx_PyVectorcall_FastCallDict(func, vc, &PyTuple_GET_ITEM(args, 0), (size_t)PyTuple_GET_SIZE(args), kw); +#else + (void) &__Pyx_PyVectorcall_FastCallDict; + return PyVectorcall_Call(func, args, kw); +#endif + } +#endif + if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { + Py_ssize_t argc; + PyObject *new_args; + PyObject *self; +#if CYTHON_ASSUME_SAFE_MACROS + argc = PyTuple_GET_SIZE(args); +#else + argc = PyTuple_Size(args); + if (unlikely(!argc) < 0) return NULL; +#endif + new_args = PyTuple_GetSlice(args, 1, argc); + if (unlikely(!new_args)) + return NULL; + self = PyTuple_GetItem(args, 0); + if (unlikely(!self)) { + Py_DECREF(new_args); +#if PY_MAJOR_VERSION > 2 + PyErr_Format(PyExc_TypeError, + "unbound method %.200S() needs an argument", + cyfunc->func_qualname); +#else + PyErr_SetString(PyExc_TypeError, + "unbound method needs an argument"); +#endif + return NULL; + } + result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw); + Py_DECREF(new_args); + } else { + result = __Pyx_CyFunction_Call(func, args, kw); + } + return result; +} +#if CYTHON_METH_FASTCALL +static CYTHON_INLINE int __Pyx_CyFunction_Vectorcall_CheckArgs(__pyx_CyFunctionObject *cyfunc, Py_ssize_t nargs, PyObject *kwnames) +{ + int ret = 0; + if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { + if (unlikely(nargs < 1)) { + PyErr_Format(PyExc_TypeError, "%.200s() needs an argument", + ((PyCFunctionObject*)cyfunc)->m_ml->ml_name); + return -1; + } + ret = 1; + } + if (unlikely(kwnames) && unlikely(PyTuple_GET_SIZE(kwnames))) { + PyErr_Format(PyExc_TypeError, + "%.200s() takes no keyword arguments", ((PyCFunctionObject*)cyfunc)->m_ml->ml_name); + return -1; + } + return ret; +} +static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + if (unlikely(nargs != 0)) { + PyErr_Format(PyExc_TypeError, + "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + def->ml_name, nargs); + return NULL; + } + return def->ml_meth(self, NULL); +} +static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + if (unlikely(nargs != 1)) { + PyErr_Format(PyExc_TypeError, + "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + def->ml_name, nargs); + return NULL; + } + return def->ml_meth(self, args[0]); +} +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + return ((__Pyx_PyCFunctionFastWithKeywords)(void(*)(void))def->ml_meth)(self, args, nargs, kwnames); +} +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; + PyTypeObject *cls = (PyTypeObject *) __Pyx_CyFunction_GetClassObj(cyfunc); +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + return ((__Pyx_PyCMethod)(void(*)(void))def->ml_meth)(self, cls, args, (size_t)nargs, kwnames); +} +#endif +#if CYTHON_USE_TYPE_SPECS +static PyType_Slot __pyx_CyFunctionType_slots[] = { + {Py_tp_dealloc, (void *)__Pyx_CyFunction_dealloc}, + {Py_tp_repr, (void *)__Pyx_CyFunction_repr}, + {Py_tp_call, (void *)__Pyx_CyFunction_CallAsMethod}, + {Py_tp_traverse, (void *)__Pyx_CyFunction_traverse}, + {Py_tp_clear, (void *)__Pyx_CyFunction_clear}, + {Py_tp_methods, (void *)__pyx_CyFunction_methods}, + {Py_tp_members, (void *)__pyx_CyFunction_members}, + {Py_tp_getset, (void *)__pyx_CyFunction_getsets}, + {Py_tp_descr_get, (void *)__Pyx_PyMethod_New}, + {0, 0}, +}; +static PyType_Spec __pyx_CyFunctionType_spec = { + __PYX_TYPE_MODULE_PREFIX "cython_function_or_method", + sizeof(__pyx_CyFunctionObject), + 0, +#ifdef Py_TPFLAGS_METHOD_DESCRIPTOR + Py_TPFLAGS_METHOD_DESCRIPTOR | +#endif +#if (defined(_Py_TPFLAGS_HAVE_VECTORCALL) && CYTHON_METH_FASTCALL) + _Py_TPFLAGS_HAVE_VECTORCALL | +#endif + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, + __pyx_CyFunctionType_slots +}; +#else +static PyTypeObject __pyx_CyFunctionType_type = { + PyVarObject_HEAD_INIT(0, 0) + __PYX_TYPE_MODULE_PREFIX "cython_function_or_method", + sizeof(__pyx_CyFunctionObject), + 0, + (destructor) __Pyx_CyFunction_dealloc, +#if !CYTHON_METH_FASTCALL + 0, +#elif CYTHON_BACKPORT_VECTORCALL + (printfunc)offsetof(__pyx_CyFunctionObject, func_vectorcall), +#else + offsetof(PyCFunctionObject, vectorcall), +#endif + 0, + 0, +#if PY_MAJOR_VERSION < 3 + 0, +#else + 0, +#endif + (reprfunc) __Pyx_CyFunction_repr, + 0, + 0, + 0, + 0, + __Pyx_CyFunction_CallAsMethod, + 0, + 0, + 0, + 0, +#ifdef Py_TPFLAGS_METHOD_DESCRIPTOR + Py_TPFLAGS_METHOD_DESCRIPTOR | +#endif +#if defined(_Py_TPFLAGS_HAVE_VECTORCALL) && CYTHON_METH_FASTCALL + _Py_TPFLAGS_HAVE_VECTORCALL | +#endif + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, + 0, + (traverseproc) __Pyx_CyFunction_traverse, + (inquiry) __Pyx_CyFunction_clear, + 0, +#if PY_VERSION_HEX < 0x030500A0 + offsetof(__pyx_CyFunctionObject, func_weakreflist), +#else + offsetof(PyCFunctionObject, m_weakreflist), +#endif + 0, + 0, + __pyx_CyFunction_methods, + __pyx_CyFunction_members, + __pyx_CyFunction_getsets, + 0, + 0, + __Pyx_PyMethod_New, + 0, + offsetof(__pyx_CyFunctionObject, func_dict), + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +#if PY_VERSION_HEX >= 0x030400a1 + 0, +#endif +#if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) + 0, +#endif +#if __PYX_NEED_TP_PRINT_SLOT + 0, +#endif +#if PY_VERSION_HEX >= 0x030C0000 + 0, +#endif +#if PY_VERSION_HEX >= 0x030d00A4 + 0, +#endif +#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 + 0, +#endif +}; +#endif +static int __pyx_CyFunction_init(PyObject *module) { +#if CYTHON_USE_TYPE_SPECS + __pyx_CyFunctionType = __Pyx_FetchCommonTypeFromSpec(module, &__pyx_CyFunctionType_spec, NULL); +#else + CYTHON_UNUSED_VAR(module); + __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type); +#endif + if (unlikely(__pyx_CyFunctionType == NULL)) { + return -1; + } + return 0; +} +static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults = PyObject_Malloc(size); + if (unlikely(!m->defaults)) + return PyErr_NoMemory(); + memset(m->defaults, 0, size); + m->defaults_pyobjects = pyobjects; + m->defaults_size = size; + return m->defaults; +} +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults_tuple = tuple; + Py_INCREF(tuple); +} +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults_kwdict = dict; + Py_INCREF(dict); +} +static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->func_annotations = dict; + Py_INCREF(dict); +} + +/* CythonFunction */ +static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, int flags, PyObject* qualname, + PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { + PyObject *op = __Pyx_CyFunction_Init( + PyObject_GC_New(__pyx_CyFunctionObject, __pyx_CyFunctionType), + ml, flags, qualname, closure, module, globals, code + ); + if (likely(op)) { + PyObject_GC_Track(op); + } + return op; +} + +/* CLineInTraceback */ +#ifndef CYTHON_CLINE_IN_TRACEBACK +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line) { + PyObject *use_cline; + PyObject *ptype, *pvalue, *ptraceback; +#if CYTHON_COMPILING_IN_CPYTHON + PyObject **cython_runtime_dict; +#endif + CYTHON_MAYBE_UNUSED_VAR(tstate); + if (unlikely(!__pyx_cython_runtime)) { + return c_line; + } + __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); +#if CYTHON_COMPILING_IN_CPYTHON + cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime); + if (likely(cython_runtime_dict)) { + __PYX_PY_DICT_LOOKUP_IF_MODIFIED( + use_cline, *cython_runtime_dict, + __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback)) + } else +#endif + { + PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStrNoError(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback); + if (use_cline_obj) { + use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True; + Py_DECREF(use_cline_obj); + } else { + PyErr_Clear(); + use_cline = NULL; + } + } + if (!use_cline) { + c_line = 0; + (void) PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False); + } + else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) { + c_line = 0; + } + __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); + return c_line; +} +#endif + +/* CodeObjectCache */ +#if !CYTHON_COMPILING_IN_LIMITED_API +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { + int start = 0, mid = 0, end = count - 1; + if (end >= 0 && code_line > entries[end].code_line) { + return count; + } + while (start < end) { + mid = start + (end - start) / 2; + if (code_line < entries[mid].code_line) { + end = mid; + } else if (code_line > entries[mid].code_line) { + start = mid + 1; + } else { + return mid; + } + } + if (code_line <= entries[mid].code_line) { + return mid; + } else { + return mid + 1; + } +} +static PyCodeObject *__pyx_find_code_object(int code_line) { + PyCodeObject* code_object; + int pos; + if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { + return NULL; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { + return NULL; + } + code_object = __pyx_code_cache.entries[pos].code_object; + Py_INCREF(code_object); + return code_object; +} +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { + int pos, i; + __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; + if (unlikely(!code_line)) { + return; + } + if (unlikely(!entries)) { + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); + if (likely(entries)) { + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = 64; + __pyx_code_cache.count = 1; + entries[0].code_line = code_line; + entries[0].code_object = code_object; + Py_INCREF(code_object); + } + return; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { + PyCodeObject* tmp = entries[pos].code_object; + entries[pos].code_object = code_object; + Py_DECREF(tmp); + return; + } + if (__pyx_code_cache.count == __pyx_code_cache.max_count) { + int new_max = __pyx_code_cache.max_count + 64; + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( + __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry)); + if (unlikely(!entries)) { + return; + } + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = new_max; + } + for (i=__pyx_code_cache.count; i>pos; i--) { + entries[i] = entries[i-1]; + } + entries[pos].code_line = code_line; + entries[pos].code_object = code_object; + __pyx_code_cache.count++; + Py_INCREF(code_object); +} +#endif + +/* AddTraceback */ +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" +#if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API + #ifndef Py_BUILD_CORE + #define Py_BUILD_CORE 1 + #endif + #include "internal/pycore_frame.h" +#endif +#if CYTHON_COMPILING_IN_LIMITED_API +static PyObject *__Pyx_PyCode_Replace_For_AddTraceback(PyObject *code, PyObject *scratch_dict, + PyObject *firstlineno, PyObject *name) { + PyObject *replace = NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "co_firstlineno", firstlineno))) return NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "co_name", name))) return NULL; + replace = PyObject_GetAttrString(code, "replace"); + if (likely(replace)) { + PyObject *result; + result = PyObject_Call(replace, __pyx_empty_tuple, scratch_dict); + Py_DECREF(replace); + return result; + } + PyErr_Clear(); + #if __PYX_LIMITED_VERSION_HEX < 0x030780000 + { + PyObject *compiled = NULL, *result = NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "code", code))) return NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "type", (PyObject*)(&PyType_Type)))) return NULL; + compiled = Py_CompileString( + "out = type(code)(\n" + " code.co_argcount, code.co_kwonlyargcount, code.co_nlocals, code.co_stacksize,\n" + " code.co_flags, code.co_code, code.co_consts, code.co_names,\n" + " code.co_varnames, code.co_filename, co_name, co_firstlineno,\n" + " code.co_lnotab)\n", "", Py_file_input); + if (!compiled) return NULL; + result = PyEval_EvalCode(compiled, scratch_dict, scratch_dict); + Py_DECREF(compiled); + if (!result) PyErr_Print(); + Py_DECREF(result); + result = PyDict_GetItemString(scratch_dict, "out"); + if (result) Py_INCREF(result); + return result; + } + #else + return NULL; + #endif +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyObject *code_object = NULL, *py_py_line = NULL, *py_funcname = NULL, *dict = NULL; + PyObject *replace = NULL, *getframe = NULL, *frame = NULL; + PyObject *exc_type, *exc_value, *exc_traceback; + int success = 0; + if (c_line) { + (void) __pyx_cfilenm; + (void) __Pyx_CLineForTraceback(__Pyx_PyThreadState_Current, c_line); + } + PyErr_Fetch(&exc_type, &exc_value, &exc_traceback); + code_object = Py_CompileString("_getframe()", filename, Py_eval_input); + if (unlikely(!code_object)) goto bad; + py_py_line = PyLong_FromLong(py_line); + if (unlikely(!py_py_line)) goto bad; + py_funcname = PyUnicode_FromString(funcname); + if (unlikely(!py_funcname)) goto bad; + dict = PyDict_New(); + if (unlikely(!dict)) goto bad; + { + PyObject *old_code_object = code_object; + code_object = __Pyx_PyCode_Replace_For_AddTraceback(code_object, dict, py_py_line, py_funcname); + Py_DECREF(old_code_object); + } + if (unlikely(!code_object)) goto bad; + getframe = PySys_GetObject("_getframe"); + if (unlikely(!getframe)) goto bad; + if (unlikely(PyDict_SetItemString(dict, "_getframe", getframe))) goto bad; + frame = PyEval_EvalCode(code_object, dict, dict); + if (unlikely(!frame) || frame == Py_None) goto bad; + success = 1; + bad: + PyErr_Restore(exc_type, exc_value, exc_traceback); + Py_XDECREF(code_object); + Py_XDECREF(py_py_line); + Py_XDECREF(py_funcname); + Py_XDECREF(dict); + Py_XDECREF(replace); + if (success) { + PyTraceBack_Here( + (struct _frame*)frame); + } + Py_XDECREF(frame); +} +#else +static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( + const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = NULL; + PyObject *py_funcname = NULL; + #if PY_MAJOR_VERSION < 3 + PyObject *py_srcfile = NULL; + py_srcfile = PyString_FromString(filename); + if (!py_srcfile) goto bad; + #endif + if (c_line) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + if (!py_funcname) goto bad; + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + if (!py_funcname) goto bad; + funcname = PyUnicode_AsUTF8(py_funcname); + if (!funcname) goto bad; + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + if (!py_funcname) goto bad; + #endif + } + #if PY_MAJOR_VERSION < 3 + py_code = __Pyx_PyCode_New( + 0, + 0, + 0, + 0, + 0, + 0, + __pyx_empty_bytes, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + py_line, + __pyx_empty_bytes /*PyObject *lnotab*/ + ); + Py_DECREF(py_srcfile); + #else + py_code = PyCode_NewEmpty(filename, funcname, py_line); + #endif + Py_XDECREF(py_funcname); + return py_code; +bad: + Py_XDECREF(py_funcname); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(py_srcfile); + #endif + return NULL; +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject *ptype, *pvalue, *ptraceback; + if (c_line) { + c_line = __Pyx_CLineForTraceback(tstate, c_line); + } + py_code = __pyx_find_code_object(c_line ? -c_line : py_line); + if (!py_code) { + __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); + py_code = __Pyx_CreateCodeObjectForTraceback( + funcname, c_line, py_line, filename); + if (!py_code) { + /* If the code object creation fails, then we should clear the + fetched exception references and propagate the new exception */ + Py_XDECREF(ptype); + Py_XDECREF(pvalue); + Py_XDECREF(ptraceback); + goto bad; + } + __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); + __pyx_insert_code_object(c_line ? -c_line : py_line, py_code); + } + py_frame = PyFrame_New( + tstate, /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + __pyx_d, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + __Pyx_PyFrame_SetLineNumber(py_frame, py_line); + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} +#endif + +/* FormatTypeName */ +#if CYTHON_COMPILING_IN_LIMITED_API +static __Pyx_TypeName +__Pyx_PyType_GetName(PyTypeObject* tp) +{ + PyObject *name = __Pyx_PyObject_GetAttrStr((PyObject *)tp, + __pyx_n_s_name); + if (unlikely(name == NULL) || unlikely(!PyUnicode_Check(name))) { + PyErr_Clear(); + Py_XDECREF(name); + name = __Pyx_NewRef(__pyx_n_s__19); + } + return name; +} +#endif + +/* CIntToPy */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(long) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(long) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + unsigned char *bytes = (unsigned char *)&value; +#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4 + if (is_unsigned) { + return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1); + } else { + return PyLong_FromNativeBytes(bytes, sizeof(value), -1); + } +#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000 + int one = 1; int little = (int)*(unsigned char *)&one; + return _PyLong_FromByteArray(bytes, sizeof(long), + little, !is_unsigned); +#else + int one = 1; int little = (int)*(unsigned char *)&one; + PyObject *from_bytes, *result = NULL; + PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL; + from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes"); + if (!from_bytes) return NULL; + py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(long)); + if (!py_bytes) goto limited_bad; + order_str = PyUnicode_FromString(little ? "little" : "big"); + if (!order_str) goto limited_bad; + arg_tuple = PyTuple_Pack(2, py_bytes, order_str); + if (!arg_tuple) goto limited_bad; + if (!is_unsigned) { + kwds = PyDict_New(); + if (!kwds) goto limited_bad; + if (PyDict_SetItemString(kwds, "signed", __Pyx_NewRef(Py_True))) goto limited_bad; + } + result = PyObject_Call(from_bytes, arg_tuple, kwds); + limited_bad: + Py_XDECREF(kwds); + Py_XDECREF(arg_tuple); + Py_XDECREF(order_str); + Py_XDECREF(py_bytes); + Py_XDECREF(from_bytes); + return result; +#endif + } +} + +/* CIntFromPyVerify */ +#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) +#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) +#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ + {\ + func_type value = func_value;\ + if (sizeof(target_type) < sizeof(func_type)) {\ + if (unlikely(value != (func_type) (target_type) value)) {\ + func_type zero = 0;\ + if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ + return (target_type) -1;\ + if (is_unsigned && unlikely(value < zero))\ + goto raise_neg_overflow;\ + else\ + goto raise_overflow;\ + }\ + }\ + return (target_type) value;\ + } + +/* CIntFromPy */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if ((sizeof(long) < sizeof(long))) { + __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (long) val; + } + } +#endif + if (unlikely(!PyLong_Check(x))) { + long val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (long) -1; + val = __Pyx_PyInt_As_long(tmp); + Py_DECREF(tmp); + return val; + } + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + if (unlikely(__Pyx_PyLong_IsNeg(x))) { + goto raise_neg_overflow; + } else if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_DigitCount(x)) { + case 2: + if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) >= 2 * PyLong_SHIFT)) { + return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 3: + if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) >= 3 * PyLong_SHIFT)) { + return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 4: + if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) >= 4 * PyLong_SHIFT)) { + return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + } + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7 + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (long) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if ((sizeof(long) <= sizeof(unsigned long))) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(long) <= sizeof(unsigned PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_SignedDigitCount(x)) { + case -2: + if ((8 * sizeof(long) - 1 > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) { + return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 2: + if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) { + return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -3: + if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) { + return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 3: + if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) { + return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -4: + if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) { + return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 4: + if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) { + return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + } + } +#endif + if ((sizeof(long) <= sizeof(long))) { + __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(long) <= sizeof(PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { + long val; + int ret = -1; +#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API + Py_ssize_t bytes_copied = PyLong_AsNativeBytes( + x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0)); + if (unlikely(bytes_copied == -1)) { + } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) { + goto raise_overflow; + } else { + ret = 0; + } +#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray) + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + ret = _PyLong_AsByteArray((PyLongObject *)x, + bytes, sizeof(val), + is_little, !is_unsigned); +#else + PyObject *v; + PyObject *stepval = NULL, *mask = NULL, *shift = NULL; + int bits, remaining_bits, is_negative = 0; + int chunk_size = (sizeof(long) < 8) ? 30 : 62; + if (likely(PyLong_CheckExact(x))) { + v = __Pyx_NewRef(x); + } else { + v = PyNumber_Long(x); + if (unlikely(!v)) return (long) -1; + assert(PyLong_CheckExact(v)); + } + { + int result = PyObject_RichCompareBool(v, Py_False, Py_LT); + if (unlikely(result < 0)) { + Py_DECREF(v); + return (long) -1; + } + is_negative = result == 1; + } + if (is_unsigned && unlikely(is_negative)) { + Py_DECREF(v); + goto raise_neg_overflow; + } else if (is_negative) { + stepval = PyNumber_Invert(v); + Py_DECREF(v); + if (unlikely(!stepval)) + return (long) -1; + } else { + stepval = v; + } + v = NULL; + val = (long) 0; + mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done; + shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done; + for (bits = 0; bits < (int) sizeof(long) * 8 - chunk_size; bits += chunk_size) { + PyObject *tmp, *digit; + long idigit; + digit = PyNumber_And(stepval, mask); + if (unlikely(!digit)) goto done; + idigit = PyLong_AsLong(digit); + Py_DECREF(digit); + if (unlikely(idigit < 0)) goto done; + val |= ((long) idigit) << bits; + tmp = PyNumber_Rshift(stepval, shift); + if (unlikely(!tmp)) goto done; + Py_DECREF(stepval); stepval = tmp; + } + Py_DECREF(shift); shift = NULL; + Py_DECREF(mask); mask = NULL; + { + long idigit = PyLong_AsLong(stepval); + if (unlikely(idigit < 0)) goto done; + remaining_bits = ((int) sizeof(long) * 8) - bits - (is_unsigned ? 0 : 1); + if (unlikely(idigit >= (1L << remaining_bits))) + goto raise_overflow; + val |= ((long) idigit) << bits; + } + if (!is_unsigned) { + if (unlikely(val & (((long) 1) << (sizeof(long) * 8 - 1)))) + goto raise_overflow; + if (is_negative) + val = ~val; + } + ret = 0; + done: + Py_XDECREF(shift); + Py_XDECREF(mask); + Py_XDECREF(stepval); +#endif + if (unlikely(ret)) + return (long) -1; + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to long"); + return (long) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long) -1; +} + +/* CIntFromPy */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const int neg_one = (int) -1, const_zero = (int) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if ((sizeof(int) < sizeof(long))) { + __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (int) val; + } + } +#endif + if (unlikely(!PyLong_Check(x))) { + int val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (int) -1; + val = __Pyx_PyInt_As_int(tmp); + Py_DECREF(tmp); + return val; + } + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + if (unlikely(__Pyx_PyLong_IsNeg(x))) { + goto raise_neg_overflow; + } else if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_DigitCount(x)) { + case 2: + if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) >= 2 * PyLong_SHIFT)) { + return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 3: + if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) >= 3 * PyLong_SHIFT)) { + return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 4: + if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) >= 4 * PyLong_SHIFT)) { + return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + } + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7 + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (int) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if ((sizeof(int) <= sizeof(unsigned long))) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(int) <= sizeof(unsigned PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_SignedDigitCount(x)) { + case -2: + if ((8 * sizeof(int) - 1 > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) { + return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 2: + if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) { + return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -3: + if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) { + return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 3: + if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) { + return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -4: + if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) { + return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 4: + if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) { + return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + } + } +#endif + if ((sizeof(int) <= sizeof(long))) { + __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(int) <= sizeof(PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { + int val; + int ret = -1; +#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API + Py_ssize_t bytes_copied = PyLong_AsNativeBytes( + x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0)); + if (unlikely(bytes_copied == -1)) { + } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) { + goto raise_overflow; + } else { + ret = 0; + } +#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray) + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + ret = _PyLong_AsByteArray((PyLongObject *)x, + bytes, sizeof(val), + is_little, !is_unsigned); +#else + PyObject *v; + PyObject *stepval = NULL, *mask = NULL, *shift = NULL; + int bits, remaining_bits, is_negative = 0; + int chunk_size = (sizeof(long) < 8) ? 30 : 62; + if (likely(PyLong_CheckExact(x))) { + v = __Pyx_NewRef(x); + } else { + v = PyNumber_Long(x); + if (unlikely(!v)) return (int) -1; + assert(PyLong_CheckExact(v)); + } + { + int result = PyObject_RichCompareBool(v, Py_False, Py_LT); + if (unlikely(result < 0)) { + Py_DECREF(v); + return (int) -1; + } + is_negative = result == 1; + } + if (is_unsigned && unlikely(is_negative)) { + Py_DECREF(v); + goto raise_neg_overflow; + } else if (is_negative) { + stepval = PyNumber_Invert(v); + Py_DECREF(v); + if (unlikely(!stepval)) + return (int) -1; + } else { + stepval = v; + } + v = NULL; + val = (int) 0; + mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done; + shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done; + for (bits = 0; bits < (int) sizeof(int) * 8 - chunk_size; bits += chunk_size) { + PyObject *tmp, *digit; + long idigit; + digit = PyNumber_And(stepval, mask); + if (unlikely(!digit)) goto done; + idigit = PyLong_AsLong(digit); + Py_DECREF(digit); + if (unlikely(idigit < 0)) goto done; + val |= ((int) idigit) << bits; + tmp = PyNumber_Rshift(stepval, shift); + if (unlikely(!tmp)) goto done; + Py_DECREF(stepval); stepval = tmp; + } + Py_DECREF(shift); shift = NULL; + Py_DECREF(mask); mask = NULL; + { + long idigit = PyLong_AsLong(stepval); + if (unlikely(idigit < 0)) goto done; + remaining_bits = ((int) sizeof(int) * 8) - bits - (is_unsigned ? 0 : 1); + if (unlikely(idigit >= (1L << remaining_bits))) + goto raise_overflow; + val |= ((int) idigit) << bits; + } + if (!is_unsigned) { + if (unlikely(val & (((int) 1) << (sizeof(int) * 8 - 1)))) + goto raise_overflow; + if (is_negative) + val = ~val; + } + ret = 0; + done: + Py_XDECREF(shift); + Py_XDECREF(mask); + Py_XDECREF(stepval); +#endif + if (unlikely(ret)) + return (int) -1; + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to int"); + return (int) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int"); + return (int) -1; +} + +/* CheckBinaryVersion */ +static unsigned long __Pyx_get_runtime_version(void) { +#if __PYX_LIMITED_VERSION_HEX >= 0x030B00A4 + return Py_Version & ~0xFFUL; +#else + const char* rt_version = Py_GetVersion(); + unsigned long version = 0; + unsigned long factor = 0x01000000UL; + unsigned int digit = 0; + int i = 0; + while (factor) { + while ('0' <= rt_version[i] && rt_version[i] <= '9') { + digit = digit * 10 + (unsigned int) (rt_version[i] - '0'); + ++i; + } + version += factor * digit; + if (rt_version[i] != '.') + break; + digit = 0; + factor >>= 8; + ++i; + } + return version; +#endif +} +static int __Pyx_check_binary_version(unsigned long ct_version, unsigned long rt_version, int allow_newer) { + const unsigned long MAJOR_MINOR = 0xFFFF0000UL; + if ((rt_version & MAJOR_MINOR) == (ct_version & MAJOR_MINOR)) + return 0; + if (likely(allow_newer && (rt_version & MAJOR_MINOR) > (ct_version & MAJOR_MINOR))) + return 1; + { + char message[200]; + PyOS_snprintf(message, sizeof(message), + "compile time Python version %d.%d " + "of module '%.100s' " + "%s " + "runtime version %d.%d", + (int) (ct_version >> 24), (int) ((ct_version >> 16) & 0xFF), + __Pyx_MODULE_NAME, + (allow_newer) ? "was newer than" : "does not match", + (int) (rt_version >> 24), (int) ((rt_version >> 16) & 0xFF) + ); + return PyErr_WarnEx(NULL, message, 1); + } +} + +/* InitStrings */ +#if PY_MAJOR_VERSION >= 3 +static int __Pyx_InitString(__Pyx_StringTabEntry t, PyObject **str) { + if (t.is_unicode | t.is_str) { + if (t.intern) { + *str = PyUnicode_InternFromString(t.s); + } else if (t.encoding) { + *str = PyUnicode_Decode(t.s, t.n - 1, t.encoding, NULL); + } else { + *str = PyUnicode_FromStringAndSize(t.s, t.n - 1); + } + } else { + *str = PyBytes_FromStringAndSize(t.s, t.n - 1); + } + if (!*str) + return -1; + if (PyObject_Hash(*str) == -1) + return -1; + return 0; +} +#endif +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + #if PY_MAJOR_VERSION >= 3 + __Pyx_InitString(*t, t->p); + #else + if (t->is_unicode) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + if (!*t->p) + return -1; + if (PyObject_Hash(*t->p) == -1) + return -1; + #endif + ++t; + } + return 0; +} + +#include +static CYTHON_INLINE Py_ssize_t __Pyx_ssize_strlen(const char *s) { + size_t len = strlen(s); + if (unlikely(len > (size_t) PY_SSIZE_T_MAX)) { + PyErr_SetString(PyExc_OverflowError, "byte string is too long"); + return -1; + } + return (Py_ssize_t) len; +} +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { + Py_ssize_t len = __Pyx_ssize_strlen(c_str); + if (unlikely(len < 0)) return NULL; + return __Pyx_PyUnicode_FromStringAndSize(c_str, len); +} +static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char* c_str) { + Py_ssize_t len = __Pyx_ssize_strlen(c_str); + if (unlikely(len < 0)) return NULL; + return PyByteArray_FromStringAndSize(c_str, len); +} +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) { + Py_ssize_t ignore; + return __Pyx_PyObject_AsStringAndSize(o, &ignore); +} +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +#if !CYTHON_PEP393_ENABLED +static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + char* defenc_c; + PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); + if (!defenc) return NULL; + defenc_c = PyBytes_AS_STRING(defenc); +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + { + char* end = defenc_c + PyBytes_GET_SIZE(defenc); + char* c; + for (c = defenc_c; c < end; c++) { + if ((unsigned char) (*c) >= 128) { + PyUnicode_AsASCIIString(o); + return NULL; + } + } + } +#endif + *length = PyBytes_GET_SIZE(defenc); + return defenc_c; +} +#else +static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL; +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + if (likely(PyUnicode_IS_ASCII(o))) { + *length = PyUnicode_GET_LENGTH(o); + return PyUnicode_AsUTF8(o); + } else { + PyUnicode_AsASCIIString(o); + return NULL; + } +#else + return PyUnicode_AsUTF8AndSize(o, length); +#endif +} +#endif +#endif +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT + if ( +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + __Pyx_sys_getdefaultencoding_not_ascii && +#endif + PyUnicode_Check(o)) { + return __Pyx_PyUnicode_AsStringAndSize(o, length); + } else +#endif +#if (!CYTHON_COMPILING_IN_PYPY && !CYTHON_COMPILING_IN_LIMITED_API) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) + if (PyByteArray_Check(o)) { + *length = PyByteArray_GET_SIZE(o); + return PyByteArray_AS_STRING(o); + } else +#endif + { + char* result; + int r = PyBytes_AsStringAndSize(o, &result, length); + if (unlikely(r < 0)) { + return NULL; + } else { + return result; + } + } +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + int is_true = x == Py_True; + if (is_true | (x == Py_False) | (x == Py_None)) return is_true; + else return PyObject_IsTrue(x); +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { + int retval; + if (unlikely(!x)) return -1; + retval = __Pyx_PyObject_IsTrue(x); + Py_DECREF(x); + return retval; +} +static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) { + __Pyx_TypeName result_type_name = __Pyx_PyType_GetName(Py_TYPE(result)); +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(result)) { + if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + "__int__ returned non-int (type " __Pyx_FMT_TYPENAME "). " + "The ability to return an instance of a strict subclass of int is deprecated, " + "and may be removed in a future version of Python.", + result_type_name)) { + __Pyx_DECREF_TypeName(result_type_name); + Py_DECREF(result); + return NULL; + } + __Pyx_DECREF_TypeName(result_type_name); + return result; + } +#endif + PyErr_Format(PyExc_TypeError, + "__%.4s__ returned non-%.4s (type " __Pyx_FMT_TYPENAME ")", + type_name, type_name, result_type_name); + __Pyx_DECREF_TypeName(result_type_name); + Py_DECREF(result); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { +#if CYTHON_USE_TYPE_SLOTS + PyNumberMethods *m; +#endif + const char *name = NULL; + PyObject *res = NULL; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x) || PyLong_Check(x))) +#else + if (likely(PyLong_Check(x))) +#endif + return __Pyx_NewRef(x); +#if CYTHON_USE_TYPE_SLOTS + m = Py_TYPE(x)->tp_as_number; + #if PY_MAJOR_VERSION < 3 + if (m && m->nb_int) { + name = "int"; + res = m->nb_int(x); + } + else if (m && m->nb_long) { + name = "long"; + res = m->nb_long(x); + } + #else + if (likely(m && m->nb_int)) { + name = "int"; + res = m->nb_int(x); + } + #endif +#else + if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) { + res = PyNumber_Int(x); + } +#endif + if (likely(res)) { +#if PY_MAJOR_VERSION < 3 + if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) { +#else + if (unlikely(!PyLong_CheckExact(res))) { +#endif + return __Pyx_PyNumber_IntOrLongWrongResultType(res, name); + } + } + else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); + } + return res; +} +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject *x; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(b))) { + if (sizeof(Py_ssize_t) >= sizeof(long)) + return PyInt_AS_LONG(b); + else + return PyInt_AsSsize_t(b); + } +#endif + if (likely(PyLong_CheckExact(b))) { + #if CYTHON_USE_PYLONG_INTERNALS + if (likely(__Pyx_PyLong_IsCompact(b))) { + return __Pyx_PyLong_CompactValue(b); + } else { + const digit* digits = __Pyx_PyLong_Digits(b); + const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount(b); + switch (size) { + case 2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + } + } + #endif + return PyLong_AsSsize_t(b); + } + x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} +static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject* o) { + if (sizeof(Py_hash_t) == sizeof(Py_ssize_t)) { + return (Py_hash_t) __Pyx_PyIndex_AsSsize_t(o); +#if PY_MAJOR_VERSION < 3 + } else if (likely(PyInt_CheckExact(o))) { + return PyInt_AS_LONG(o); +#endif + } else { + Py_ssize_t ival; + PyObject *x; + x = PyNumber_Index(o); + if (!x) return -1; + ival = PyInt_AsLong(x); + Py_DECREF(x); + return ival; + } +} +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) { + return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False); +} +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { + return PyInt_FromSize_t(ival); +} + + +/* #### Code section: utility_code_pragmas_end ### */ +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + + + +/* #### Code section: end ### */ +#endif /* Py_PYTHON_H */ diff --git a/bot/build/cython_code/my_translator.c b/bot/build/cython_code/my_translator.c new file mode 100644 index 0000000..74f7883 --- /dev/null +++ b/bot/build/cython_code/my_translator.c @@ -0,0 +1,11536 @@ +/* Generated by Cython 3.0.11 */ + +/* BEGIN: Cython Metadata +{ + "distutils": { + "name": "cython_code.my_translator", + "sources": [ + "cython_code/my_translator.pyx" + ] + }, + "module_name": "cython_code.my_translator" +} +END: Cython Metadata */ + +#ifndef PY_SSIZE_T_CLEAN +#define PY_SSIZE_T_CLEAN +#endif /* PY_SSIZE_T_CLEAN */ +#if defined(CYTHON_LIMITED_API) && 0 + #ifndef Py_LIMITED_API + #if CYTHON_LIMITED_API+0 > 0x03030000 + #define Py_LIMITED_API CYTHON_LIMITED_API + #else + #define Py_LIMITED_API 0x03030000 + #endif + #endif +#endif + +#include "Python.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#elif PY_VERSION_HEX < 0x02070000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) + #error Cython requires Python 2.7+ or Python 3.3+. +#else +#if defined(CYTHON_LIMITED_API) && CYTHON_LIMITED_API +#define __PYX_EXTRA_ABI_MODULE_NAME "limited" +#else +#define __PYX_EXTRA_ABI_MODULE_NAME "" +#endif +#define CYTHON_ABI "3_0_11" __PYX_EXTRA_ABI_MODULE_NAME +#define __PYX_ABI_MODULE_NAME "_cython_" CYTHON_ABI +#define __PYX_TYPE_MODULE_PREFIX __PYX_ABI_MODULE_NAME "." +#define CYTHON_HEX_VERSION 0x03000BF0 +#define CYTHON_FUTURE_DIVISION 1 +#include +#ifndef offsetof + #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) +#endif +#if !defined(_WIN32) && !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#endif +#ifndef DL_IMPORT + #define DL_IMPORT(t) t +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif +#define __PYX_COMMA , +#ifndef HAVE_LONG_LONG + #define HAVE_LONG_LONG +#endif +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifndef Py_HUGE_VAL + #define Py_HUGE_VAL HUGE_VAL +#endif +#define __PYX_LIMITED_VERSION_HEX PY_VERSION_HEX +#if defined(GRAALVM_PYTHON) + /* For very preliminary testing purposes. Most variables are set the same as PyPy. + The existence of this section does not imply that anything works or is even tested */ + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 1 + #define CYTHON_COMPILING_IN_NOGIL 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #undef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS (PY_MAJOR_VERSION >= 3) + #endif + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #undef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #endif + #undef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 +#elif defined(PYPY_VERSION) + #define CYTHON_COMPILING_IN_PYPY 1 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #ifndef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #undef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS (PY_MAJOR_VERSION >= 3) + #endif + #if PY_VERSION_HEX < 0x03090000 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #elif !defined(CYTHON_PEP489_MULTI_PHASE_INIT) + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #undef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1 && PYPY_VERSION_NUM >= 0x07030C00) + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #endif + #undef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 +#elif defined(CYTHON_LIMITED_API) + #ifdef Py_LIMITED_API + #undef __PYX_LIMITED_VERSION_HEX + #define __PYX_LIMITED_VERSION_HEX Py_LIMITED_API + #endif + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 1 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 0 + #undef CYTHON_CLINE_IN_TRACEBACK + #define CYTHON_CLINE_IN_TRACEBACK 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 1 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #endif + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #undef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS 1 + #endif + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #undef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 1 + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #endif + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #endif + #undef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 +#elif defined(Py_GIL_DISABLED) || defined(Py_NOGIL) + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 1 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #ifndef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #ifndef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #ifndef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #ifndef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 1 + #endif + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS 1 + #endif + #ifndef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #ifndef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #endif + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 1 + #endif + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 1 + #endif + #ifndef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 + #endif +#else + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 1 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 0 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #ifndef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #endif + #ifndef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 1 + #endif + #if PY_MAJOR_VERSION < 3 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #ifndef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 1 + #endif + #ifndef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 1 + #endif + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #if PY_VERSION_HEX < 0x030300F0 || PY_VERSION_HEX >= 0x030B00A2 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #elif !defined(CYTHON_USE_UNICODE_WRITER) + #define CYTHON_USE_UNICODE_WRITER 1 + #endif + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #ifndef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 1 + #endif + #ifndef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL (PY_MAJOR_VERSION < 3 || PY_VERSION_HEX >= 0x03060000 && PY_VERSION_HEX < 0x030C00A6) + #endif + #ifndef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL (PY_VERSION_HEX >= 0x030700A1) + #endif + #ifndef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 1 + #endif + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS 1 + #endif + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #elif !defined(CYTHON_PEP489_MULTI_PHASE_INIT) + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #ifndef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #endif + #if PY_VERSION_HEX < 0x030400a1 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #elif !defined(CYTHON_USE_TP_FINALIZE) + #define CYTHON_USE_TP_FINALIZE 1 + #endif + #if PY_VERSION_HEX < 0x030600B1 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #elif !defined(CYTHON_USE_DICT_VERSIONS) + #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX < 0x030C00A5) + #endif + #if PY_VERSION_HEX < 0x030700A3 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #elif !defined(CYTHON_USE_EXC_INFO_STACK) + #define CYTHON_USE_EXC_INFO_STACK 1 + #endif + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 1 + #endif + #ifndef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 1 + #endif +#endif +#if !defined(CYTHON_FAST_PYCCALL) +#define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) +#endif +#if !defined(CYTHON_VECTORCALL) +#define CYTHON_VECTORCALL (CYTHON_FAST_PYCCALL && PY_VERSION_HEX >= 0x030800B1) +#endif +#define CYTHON_BACKPORT_VECTORCALL (CYTHON_METH_FASTCALL && PY_VERSION_HEX < 0x030800B1) +#if CYTHON_USE_PYLONG_INTERNALS + #if PY_MAJOR_VERSION < 3 + #include "longintrepr.h" + #endif + #undef SHIFT + #undef BASE + #undef MASK + #ifdef SIZEOF_VOID_P + enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; + #endif +#endif +#ifndef __has_attribute + #define __has_attribute(x) 0 +#endif +#ifndef __has_cpp_attribute + #define __has_cpp_attribute(x) 0 +#endif +#ifndef CYTHON_RESTRICT + #if defined(__GNUC__) + #define CYTHON_RESTRICT __restrict__ + #elif defined(_MSC_VER) && _MSC_VER >= 1400 + #define CYTHON_RESTRICT __restrict + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_RESTRICT restrict + #else + #define CYTHON_RESTRICT + #endif +#endif +#ifndef CYTHON_UNUSED + #if defined(__cplusplus) + /* for clang __has_cpp_attribute(maybe_unused) is true even before C++17 + * but leads to warnings with -pedantic, since it is a C++17 feature */ + #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) + #if __has_cpp_attribute(maybe_unused) + #define CYTHON_UNUSED [[maybe_unused]] + #endif + #endif + #endif +#endif +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_UNUSED_VAR +# if defined(__cplusplus) + template void CYTHON_UNUSED_VAR( const T& ) { } +# else +# define CYTHON_UNUSED_VAR(x) (void)(x) +# endif +#endif +#ifndef CYTHON_MAYBE_UNUSED_VAR + #define CYTHON_MAYBE_UNUSED_VAR(x) CYTHON_UNUSED_VAR(x) +#endif +#ifndef CYTHON_NCP_UNUSED +# if CYTHON_COMPILING_IN_CPYTHON +# define CYTHON_NCP_UNUSED +# else +# define CYTHON_NCP_UNUSED CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_USE_CPP_STD_MOVE + #if defined(__cplusplus) && (\ + __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600)) + #define CYTHON_USE_CPP_STD_MOVE 1 + #else + #define CYTHON_USE_CPP_STD_MOVE 0 + #endif +#endif +#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) +#ifdef _MSC_VER + #ifndef _MSC_STDINT_H_ + #if _MSC_VER < 1300 + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + typedef unsigned int uint32_t; + #else + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; + #endif + #endif + #if _MSC_VER < 1300 + #ifdef _WIN64 + typedef unsigned long long __pyx_uintptr_t; + #else + typedef unsigned int __pyx_uintptr_t; + #endif + #else + #ifdef _WIN64 + typedef unsigned __int64 __pyx_uintptr_t; + #else + typedef unsigned __int32 __pyx_uintptr_t; + #endif + #endif +#else + #include + typedef uintptr_t __pyx_uintptr_t; +#endif +#ifndef CYTHON_FALLTHROUGH + #if defined(__cplusplus) + /* for clang __has_cpp_attribute(fallthrough) is true even before C++17 + * but leads to warnings with -pedantic, since it is a C++17 feature */ + #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) + #if __has_cpp_attribute(fallthrough) + #define CYTHON_FALLTHROUGH [[fallthrough]] + #endif + #endif + #ifndef CYTHON_FALLTHROUGH + #if __has_cpp_attribute(clang::fallthrough) + #define CYTHON_FALLTHROUGH [[clang::fallthrough]] + #elif __has_cpp_attribute(gnu::fallthrough) + #define CYTHON_FALLTHROUGH [[gnu::fallthrough]] + #endif + #endif + #endif + #ifndef CYTHON_FALLTHROUGH + #if __has_attribute(fallthrough) + #define CYTHON_FALLTHROUGH __attribute__((fallthrough)) + #else + #define CYTHON_FALLTHROUGH + #endif + #endif + #if defined(__clang__) && defined(__apple_build_version__) + #if __apple_build_version__ < 7000000 + #undef CYTHON_FALLTHROUGH + #define CYTHON_FALLTHROUGH + #endif + #endif +#endif +#ifdef __cplusplus + template + struct __PYX_IS_UNSIGNED_IMPL {static const bool value = T(0) < T(-1);}; + #define __PYX_IS_UNSIGNED(type) (__PYX_IS_UNSIGNED_IMPL::value) +#else + #define __PYX_IS_UNSIGNED(type) (((type)-1) > 0) +#endif +#if CYTHON_COMPILING_IN_PYPY == 1 + #define __PYX_NEED_TP_PRINT_SLOT (PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x030A0000) +#else + #define __PYX_NEED_TP_PRINT_SLOT (PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000) +#endif +#define __PYX_REINTERPRET_FUNCION(func_pointer, other_pointer) ((func_pointer)(void(*)(void))(other_pointer)) + +#ifndef CYTHON_INLINE + #if defined(__clang__) + #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) + #elif defined(__GNUC__) + #define CYTHON_INLINE __inline__ + #elif defined(_MSC_VER) + #define CYTHON_INLINE __inline + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_INLINE inline + #else + #define CYTHON_INLINE + #endif +#endif + +#define __PYX_BUILD_PY_SSIZE_T "n" +#define CYTHON_FORMAT_SSIZE_T "z" +#if PY_MAJOR_VERSION < 3 + #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" + #define __Pyx_DefaultClassType PyClass_Type + #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #define __Pyx_BUILTIN_MODULE_NAME "builtins" + #define __Pyx_DefaultClassType PyType_Type +#if CYTHON_COMPILING_IN_LIMITED_API + static CYTHON_INLINE PyObject* __Pyx_PyCode_New(int a, int p, int k, int l, int s, int f, + PyObject *code, PyObject *c, PyObject* n, PyObject *v, + PyObject *fv, PyObject *cell, PyObject* fn, + PyObject *name, int fline, PyObject *lnos) { + PyObject *exception_table = NULL; + PyObject *types_module=NULL, *code_type=NULL, *result=NULL; + #if __PYX_LIMITED_VERSION_HEX < 0x030B0000 + PyObject *version_info; + PyObject *py_minor_version = NULL; + #endif + long minor_version = 0; + PyObject *type, *value, *traceback; + PyErr_Fetch(&type, &value, &traceback); + #if __PYX_LIMITED_VERSION_HEX >= 0x030B0000 + minor_version = 11; + #else + if (!(version_info = PySys_GetObject("version_info"))) goto end; + if (!(py_minor_version = PySequence_GetItem(version_info, 1))) goto end; + minor_version = PyLong_AsLong(py_minor_version); + Py_DECREF(py_minor_version); + if (minor_version == -1 && PyErr_Occurred()) goto end; + #endif + if (!(types_module = PyImport_ImportModule("types"))) goto end; + if (!(code_type = PyObject_GetAttrString(types_module, "CodeType"))) goto end; + if (minor_version <= 7) { + (void)p; + result = PyObject_CallFunction(code_type, "iiiiiOOOOOOiOO", a, k, l, s, f, code, + c, n, v, fn, name, fline, lnos, fv, cell); + } else if (minor_version <= 10) { + result = PyObject_CallFunction(code_type, "iiiiiiOOOOOOiOO", a,p, k, l, s, f, code, + c, n, v, fn, name, fline, lnos, fv, cell); + } else { + if (!(exception_table = PyBytes_FromStringAndSize(NULL, 0))) goto end; + result = PyObject_CallFunction(code_type, "iiiiiiOOOOOOOiOO", a,p, k, l, s, f, code, + c, n, v, fn, name, name, fline, lnos, exception_table, fv, cell); + } + end: + Py_XDECREF(code_type); + Py_XDECREF(exception_table); + Py_XDECREF(types_module); + if (type) { + PyErr_Restore(type, value, traceback); + } + return result; + } + #ifndef CO_OPTIMIZED + #define CO_OPTIMIZED 0x0001 + #endif + #ifndef CO_NEWLOCALS + #define CO_NEWLOCALS 0x0002 + #endif + #ifndef CO_VARARGS + #define CO_VARARGS 0x0004 + #endif + #ifndef CO_VARKEYWORDS + #define CO_VARKEYWORDS 0x0008 + #endif + #ifndef CO_ASYNC_GENERATOR + #define CO_ASYNC_GENERATOR 0x0200 + #endif + #ifndef CO_GENERATOR + #define CO_GENERATOR 0x0020 + #endif + #ifndef CO_COROUTINE + #define CO_COROUTINE 0x0080 + #endif +#elif PY_VERSION_HEX >= 0x030B0000 + static CYTHON_INLINE PyCodeObject* __Pyx_PyCode_New(int a, int p, int k, int l, int s, int f, + PyObject *code, PyObject *c, PyObject* n, PyObject *v, + PyObject *fv, PyObject *cell, PyObject* fn, + PyObject *name, int fline, PyObject *lnos) { + PyCodeObject *result; + PyObject *empty_bytes = PyBytes_FromStringAndSize("", 0); + if (!empty_bytes) return NULL; + result = + #if PY_VERSION_HEX >= 0x030C0000 + PyUnstable_Code_NewWithPosOnlyArgs + #else + PyCode_NewWithPosOnlyArgs + #endif + (a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, name, fline, lnos, empty_bytes); + Py_DECREF(empty_bytes); + return result; + } +#elif PY_VERSION_HEX >= 0x030800B2 && !CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_NewWithPosOnlyArgs(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#endif +#endif +#if PY_VERSION_HEX >= 0x030900A4 || defined(Py_IS_TYPE) + #define __Pyx_IS_TYPE(ob, type) Py_IS_TYPE(ob, type) +#else + #define __Pyx_IS_TYPE(ob, type) (((const PyObject*)ob)->ob_type == (type)) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_Is) + #define __Pyx_Py_Is(x, y) Py_Is(x, y) +#else + #define __Pyx_Py_Is(x, y) ((x) == (y)) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsNone) + #define __Pyx_Py_IsNone(ob) Py_IsNone(ob) +#else + #define __Pyx_Py_IsNone(ob) __Pyx_Py_Is((ob), Py_None) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsTrue) + #define __Pyx_Py_IsTrue(ob) Py_IsTrue(ob) +#else + #define __Pyx_Py_IsTrue(ob) __Pyx_Py_Is((ob), Py_True) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsFalse) + #define __Pyx_Py_IsFalse(ob) Py_IsFalse(ob) +#else + #define __Pyx_Py_IsFalse(ob) __Pyx_Py_Is((ob), Py_False) +#endif +#define __Pyx_NoneAsNull(obj) (__Pyx_Py_IsNone(obj) ? NULL : (obj)) +#if PY_VERSION_HEX >= 0x030900F0 && !CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyObject_GC_IsFinalized(o) PyObject_GC_IsFinalized(o) +#else + #define __Pyx_PyObject_GC_IsFinalized(o) _PyGC_FINALIZED(o) +#endif +#ifndef CO_COROUTINE + #define CO_COROUTINE 0x80 +#endif +#ifndef CO_ASYNC_GENERATOR + #define CO_ASYNC_GENERATOR 0x200 +#endif +#ifndef Py_TPFLAGS_CHECKTYPES + #define Py_TPFLAGS_CHECKTYPES 0 +#endif +#ifndef Py_TPFLAGS_HAVE_INDEX + #define Py_TPFLAGS_HAVE_INDEX 0 +#endif +#ifndef Py_TPFLAGS_HAVE_NEWBUFFER + #define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif +#ifndef Py_TPFLAGS_HAVE_FINALIZE + #define Py_TPFLAGS_HAVE_FINALIZE 0 +#endif +#ifndef Py_TPFLAGS_SEQUENCE + #define Py_TPFLAGS_SEQUENCE 0 +#endif +#ifndef Py_TPFLAGS_MAPPING + #define Py_TPFLAGS_MAPPING 0 +#endif +#ifndef METH_STACKLESS + #define METH_STACKLESS 0 +#endif +#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL) + #ifndef METH_FASTCALL + #define METH_FASTCALL 0x80 + #endif + typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs); + typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args, + Py_ssize_t nargs, PyObject *kwnames); +#else + #if PY_VERSION_HEX >= 0x030d00A4 + # define __Pyx_PyCFunctionFast PyCFunctionFast + # define __Pyx_PyCFunctionFastWithKeywords PyCFunctionFastWithKeywords + #else + # define __Pyx_PyCFunctionFast _PyCFunctionFast + # define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords + #endif +#endif +#if CYTHON_METH_FASTCALL + #define __Pyx_METH_FASTCALL METH_FASTCALL + #define __Pyx_PyCFunction_FastCall __Pyx_PyCFunctionFast + #define __Pyx_PyCFunction_FastCallWithKeywords __Pyx_PyCFunctionFastWithKeywords +#else + #define __Pyx_METH_FASTCALL METH_VARARGS + #define __Pyx_PyCFunction_FastCall PyCFunction + #define __Pyx_PyCFunction_FastCallWithKeywords PyCFunctionWithKeywords +#endif +#if CYTHON_VECTORCALL + #define __pyx_vectorcallfunc vectorcallfunc + #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET PY_VECTORCALL_ARGUMENTS_OFFSET + #define __Pyx_PyVectorcall_NARGS(n) PyVectorcall_NARGS((size_t)(n)) +#elif CYTHON_BACKPORT_VECTORCALL + typedef PyObject *(*__pyx_vectorcallfunc)(PyObject *callable, PyObject *const *args, + size_t nargsf, PyObject *kwnames); + #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET ((size_t)1 << (8 * sizeof(size_t) - 1)) + #define __Pyx_PyVectorcall_NARGS(n) ((Py_ssize_t)(((size_t)(n)) & ~__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)) +#else + #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET 0 + #define __Pyx_PyVectorcall_NARGS(n) ((Py_ssize_t)(n)) +#endif +#if PY_MAJOR_VERSION >= 0x030900B1 +#define __Pyx_PyCFunction_CheckExact(func) PyCFunction_CheckExact(func) +#else +#define __Pyx_PyCFunction_CheckExact(func) PyCFunction_Check(func) +#endif +#define __Pyx_CyOrPyCFunction_Check(func) PyCFunction_Check(func) +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_CyOrPyCFunction_GET_FUNCTION(func) (((PyCFunctionObject*)(func))->m_ml->ml_meth) +#elif !CYTHON_COMPILING_IN_LIMITED_API +#define __Pyx_CyOrPyCFunction_GET_FUNCTION(func) PyCFunction_GET_FUNCTION(func) +#endif +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_CyOrPyCFunction_GET_FLAGS(func) (((PyCFunctionObject*)(func))->m_ml->ml_flags) +static CYTHON_INLINE PyObject* __Pyx_CyOrPyCFunction_GET_SELF(PyObject *func) { + return (__Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_STATIC) ? NULL : ((PyCFunctionObject*)func)->m_self; +} +#endif +static CYTHON_INLINE int __Pyx__IsSameCFunction(PyObject *func, void *cfunc) { +#if CYTHON_COMPILING_IN_LIMITED_API + return PyCFunction_Check(func) && PyCFunction_GetFunction(func) == (PyCFunction) cfunc; +#else + return PyCFunction_Check(func) && PyCFunction_GET_FUNCTION(func) == (PyCFunction) cfunc; +#endif +} +#define __Pyx_IsSameCFunction(func, cfunc) __Pyx__IsSameCFunction(func, cfunc) +#if __PYX_LIMITED_VERSION_HEX < 0x030900B1 + #define __Pyx_PyType_FromModuleAndSpec(m, s, b) ((void)m, PyType_FromSpecWithBases(s, b)) + typedef PyObject *(*__Pyx_PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *, size_t, PyObject *); +#else + #define __Pyx_PyType_FromModuleAndSpec(m, s, b) PyType_FromModuleAndSpec(m, s, b) + #define __Pyx_PyCMethod PyCMethod +#endif +#ifndef METH_METHOD + #define METH_METHOD 0x200 +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) + #define PyObject_Malloc(s) PyMem_Malloc(s) + #define PyObject_Free(p) PyMem_Free(p) + #define PyObject_Realloc(p) PyMem_Realloc(p) +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) +#else + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_PyThreadState_Current PyThreadState_Get() +#elif !CYTHON_FAST_THREAD_STATE + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#elif PY_VERSION_HEX >= 0x030d00A1 + #define __Pyx_PyThreadState_Current PyThreadState_GetUnchecked() +#elif PY_VERSION_HEX >= 0x03060000 + #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet() +#elif PY_VERSION_HEX >= 0x03000000 + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#else + #define __Pyx_PyThreadState_Current _PyThreadState_Current +#endif +#if CYTHON_COMPILING_IN_LIMITED_API +static CYTHON_INLINE void *__Pyx_PyModule_GetState(PyObject *op) +{ + void *result; + result = PyModule_GetState(op); + if (!result) + Py_FatalError("Couldn't find the module state"); + return result; +} +#endif +#define __Pyx_PyObject_GetSlot(obj, name, func_ctype) __Pyx_PyType_GetSlot(Py_TYPE(obj), name, func_ctype) +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_PyType_GetSlot(type, name, func_ctype) ((func_ctype) PyType_GetSlot((type), Py_##name)) +#else + #define __Pyx_PyType_GetSlot(type, name, func_ctype) ((type)->name) +#endif +#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT) +#include "pythread.h" +#define Py_tss_NEEDS_INIT 0 +typedef int Py_tss_t; +static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) { + *key = PyThread_create_key(); + return 0; +} +static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) { + Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t)); + *key = Py_tss_NEEDS_INIT; + return key; +} +static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) { + PyObject_Free(key); +} +static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) { + return *key != Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) { + PyThread_delete_key(*key); + *key = Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) { + return PyThread_set_key_value(*key, value); +} +static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { + return PyThread_get_key_value(*key); +} +#endif +#if PY_MAJOR_VERSION < 3 + #if CYTHON_COMPILING_IN_PYPY + #if PYPY_VERSION_NUM < 0x07030600 + #if defined(__cplusplus) && __cplusplus >= 201402L + [[deprecated("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6")]] + #elif defined(__GNUC__) || defined(__clang__) + __attribute__ ((__deprecated__("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6"))) + #elif defined(_MSC_VER) + __declspec(deprecated("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6")) + #endif + static CYTHON_INLINE int PyGILState_Check(void) { + return 0; + } + #else // PYPY_VERSION_NUM < 0x07030600 + #endif // PYPY_VERSION_NUM < 0x07030600 + #else + static CYTHON_INLINE int PyGILState_Check(void) { + PyThreadState * tstate = _PyThreadState_Current; + return tstate && (tstate == PyGILState_GetThisThreadState()); + } + #endif +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000 || defined(_PyDict_NewPresized) +#define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n)) +#else +#define __Pyx_PyDict_NewPresized(n) PyDict_New() +#endif +#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX > 0x030600B4 && PY_VERSION_HEX < 0x030d0000 && CYTHON_USE_UNICODE_INTERNALS +#define __Pyx_PyDict_GetItemStrWithError(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash) +static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStr(PyObject *dict, PyObject *name) { + PyObject *res = __Pyx_PyDict_GetItemStrWithError(dict, name); + if (res == NULL) PyErr_Clear(); + return res; +} +#elif PY_MAJOR_VERSION >= 3 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07020000) +#define __Pyx_PyDict_GetItemStrWithError PyDict_GetItemWithError +#define __Pyx_PyDict_GetItemStr PyDict_GetItem +#else +static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict, PyObject *name) { +#if CYTHON_COMPILING_IN_PYPY + return PyDict_GetItem(dict, name); +#else + PyDictEntry *ep; + PyDictObject *mp = (PyDictObject*) dict; + long hash = ((PyStringObject *) name)->ob_shash; + assert(hash != -1); + ep = (mp->ma_lookup)(mp, name, hash); + if (ep == NULL) { + return NULL; + } + return ep->me_value; +#endif +} +#define __Pyx_PyDict_GetItemStr PyDict_GetItem +#endif +#if CYTHON_USE_TYPE_SLOTS + #define __Pyx_PyType_GetFlags(tp) (((PyTypeObject *)tp)->tp_flags) + #define __Pyx_PyType_HasFeature(type, feature) ((__Pyx_PyType_GetFlags(type) & (feature)) != 0) + #define __Pyx_PyObject_GetIterNextFunc(obj) (Py_TYPE(obj)->tp_iternext) +#else + #define __Pyx_PyType_GetFlags(tp) (PyType_GetFlags((PyTypeObject *)tp)) + #define __Pyx_PyType_HasFeature(type, feature) PyType_HasFeature(type, feature) + #define __Pyx_PyObject_GetIterNextFunc(obj) PyIter_Next +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_SetItemOnTypeDict(tp, k, v) PyObject_GenericSetAttr((PyObject*)tp, k, v) +#else + #define __Pyx_SetItemOnTypeDict(tp, k, v) PyDict_SetItem(tp->tp_dict, k, v) +#endif +#if CYTHON_USE_TYPE_SPECS && PY_VERSION_HEX >= 0x03080000 +#define __Pyx_PyHeapTypeObject_GC_Del(obj) {\ + PyTypeObject *type = Py_TYPE((PyObject*)obj);\ + assert(__Pyx_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE));\ + PyObject_GC_Del(obj);\ + Py_DECREF(type);\ +} +#else +#define __Pyx_PyHeapTypeObject_GC_Del(obj) PyObject_GC_Del(obj) +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define CYTHON_PEP393_ENABLED 1 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GetLength(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_ReadChar(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((void)u, 1114111U) + #define __Pyx_PyUnicode_KIND(u) ((void)u, (0)) + #define __Pyx_PyUnicode_DATA(u) ((void*)u) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)k, PyUnicode_ReadChar((PyObject*)(d), i)) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GetLength(u)) +#elif PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) + #define CYTHON_PEP393_ENABLED 1 + #if PY_VERSION_HEX >= 0x030C0000 + #define __Pyx_PyUnicode_READY(op) (0) + #else + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ + 0 : _PyUnicode_Ready((PyObject *)(op))) + #endif + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) + #define __Pyx_PyUnicode_KIND(u) ((int)PyUnicode_KIND(u)) + #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) + #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, (Py_UCS4) ch) + #if PY_VERSION_HEX >= 0x030C0000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) + #else + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length)) + #else + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) + #endif + #endif +#else + #define CYTHON_PEP393_ENABLED 0 + #define PyUnicode_1BYTE_KIND 1 + #define PyUnicode_2BYTE_KIND 2 + #define PyUnicode_4BYTE_KIND 4 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535U : 1114111U) + #define __Pyx_PyUnicode_KIND(u) ((int)sizeof(Py_UNICODE)) + #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = (Py_UNICODE) ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) +#endif +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) +#else + #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ + PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) +#endif +#if CYTHON_COMPILING_IN_PYPY + #if !defined(PyUnicode_DecodeUnicodeEscape) + #define PyUnicode_DecodeUnicodeEscape(s, size, errors) PyUnicode_Decode(s, size, "unicode_escape", errors) + #endif + #if !defined(PyUnicode_Contains) || (PY_MAJOR_VERSION == 2 && PYPY_VERSION_NUM < 0x07030500) + #undef PyUnicode_Contains + #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) + #endif + #if !defined(PyByteArray_Check) + #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) + #endif + #if !defined(PyObject_Format) + #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) + #endif +#endif +#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) +#else + #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) +#endif +#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) + #define PyObject_ASCII(o) PyObject_Repr(o) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBaseString_Type PyUnicode_Type + #define PyStringObject PyUnicodeObject + #define PyString_Type PyUnicode_Type + #define PyString_Check PyUnicode_Check + #define PyString_CheckExact PyUnicode_CheckExact +#ifndef PyObject_Unicode + #define PyObject_Unicode PyObject_Str +#endif +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) + #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) +#else + #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) + #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) +#endif +#if CYTHON_COMPILING_IN_CPYTHON + #define __Pyx_PySequence_ListKeepNew(obj)\ + (likely(PyList_CheckExact(obj) && Py_REFCNT(obj) == 1) ? __Pyx_NewRef(obj) : PySequence_List(obj)) +#else + #define __Pyx_PySequence_ListKeepNew(obj) PySequence_List(obj) +#endif +#ifndef PySet_CheckExact + #define PySet_CheckExact(obj) __Pyx_IS_TYPE(obj, &PySet_Type) +#endif +#if PY_VERSION_HEX >= 0x030900A4 + #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) +#else + #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) +#endif +#if CYTHON_ASSUME_SAFE_MACROS + #define __Pyx_PySequence_ITEM(o, i) PySequence_ITEM(o, i) + #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq) + #define __Pyx_PyTuple_SET_ITEM(o, i, v) (PyTuple_SET_ITEM(o, i, v), (0)) + #define __Pyx_PyList_SET_ITEM(o, i, v) (PyList_SET_ITEM(o, i, v), (0)) + #define __Pyx_PyTuple_GET_SIZE(o) PyTuple_GET_SIZE(o) + #define __Pyx_PyList_GET_SIZE(o) PyList_GET_SIZE(o) + #define __Pyx_PySet_GET_SIZE(o) PySet_GET_SIZE(o) + #define __Pyx_PyBytes_GET_SIZE(o) PyBytes_GET_SIZE(o) + #define __Pyx_PyByteArray_GET_SIZE(o) PyByteArray_GET_SIZE(o) +#else + #define __Pyx_PySequence_ITEM(o, i) PySequence_GetItem(o, i) + #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq) + #define __Pyx_PyTuple_SET_ITEM(o, i, v) PyTuple_SetItem(o, i, v) + #define __Pyx_PyList_SET_ITEM(o, i, v) PyList_SetItem(o, i, v) + #define __Pyx_PyTuple_GET_SIZE(o) PyTuple_Size(o) + #define __Pyx_PyList_GET_SIZE(o) PyList_Size(o) + #define __Pyx_PySet_GET_SIZE(o) PySet_Size(o) + #define __Pyx_PyBytes_GET_SIZE(o) PyBytes_Size(o) + #define __Pyx_PyByteArray_GET_SIZE(o) PyByteArray_Size(o) +#endif +#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1 + #define __Pyx_PyImport_AddModuleRef(name) PyImport_AddModuleRef(name) +#else + static CYTHON_INLINE PyObject *__Pyx_PyImport_AddModuleRef(const char *name) { + PyObject *module = PyImport_AddModule(name); + Py_XINCREF(module); + return module; + } +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyIntObject PyLongObject + #define PyInt_Type PyLong_Type + #define PyInt_Check(op) PyLong_Check(op) + #define PyInt_CheckExact(op) PyLong_CheckExact(op) + #define __Pyx_Py3Int_Check(op) PyLong_Check(op) + #define __Pyx_Py3Int_CheckExact(op) PyLong_CheckExact(op) + #define PyInt_FromString PyLong_FromString + #define PyInt_FromUnicode PyLong_FromUnicode + #define PyInt_FromLong PyLong_FromLong + #define PyInt_FromSize_t PyLong_FromSize_t + #define PyInt_FromSsize_t PyLong_FromSsize_t + #define PyInt_AsLong PyLong_AsLong + #define PyInt_AS_LONG PyLong_AS_LONG + #define PyInt_AsSsize_t PyLong_AsSsize_t + #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask + #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask + #define PyNumber_Int PyNumber_Long +#else + #define __Pyx_Py3Int_Check(op) (PyLong_Check(op) || PyInt_Check(op)) + #define __Pyx_Py3Int_CheckExact(op) (PyLong_CheckExact(op) || PyInt_CheckExact(op)) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBoolObject PyLongObject +#endif +#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY + #ifndef PyUnicode_InternFromString + #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) + #endif +#endif +#if PY_VERSION_HEX < 0x030200A4 + typedef long Py_hash_t; + #define __Pyx_PyInt_FromHash_t PyInt_FromLong + #define __Pyx_PyInt_AsHash_t __Pyx_PyIndex_AsHash_t +#else + #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t + #define __Pyx_PyInt_AsHash_t __Pyx_PyIndex_AsSsize_t +#endif +#if CYTHON_USE_ASYNC_SLOTS + #if PY_VERSION_HEX >= 0x030500B1 + #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods + #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) + #else + #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) + #endif +#else + #define __Pyx_PyType_AsAsync(obj) NULL +#endif +#ifndef __Pyx_PyAsyncMethodsStruct + typedef struct { + unaryfunc am_await; + unaryfunc am_aiter; + unaryfunc am_anext; + } __Pyx_PyAsyncMethodsStruct; +#endif + +#if defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS) + #if !defined(_USE_MATH_DEFINES) + #define _USE_MATH_DEFINES + #endif +#endif +#include +#ifdef NAN +#define __PYX_NAN() ((float) NAN) +#else +static CYTHON_INLINE float __PYX_NAN() { + float value; + memset(&value, 0xFF, sizeof(value)); + return value; +} +#endif +#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) +#define __Pyx_truncl trunc +#else +#define __Pyx_truncl truncl +#endif + +#define __PYX_MARK_ERR_POS(f_index, lineno) \ + { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } +#define __PYX_ERR(f_index, lineno, Ln_error) \ + { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; } + +#ifdef CYTHON_EXTERN_C + #undef __PYX_EXTERN_C + #define __PYX_EXTERN_C CYTHON_EXTERN_C +#elif defined(__PYX_EXTERN_C) + #ifdef _MSC_VER + #pragma message ("Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.") + #else + #warning Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead. + #endif +#else + #ifdef __cplusplus + #define __PYX_EXTERN_C extern "C" + #else + #define __PYX_EXTERN_C extern + #endif +#endif + +#define __PYX_HAVE__cython_code__my_translator +#define __PYX_HAVE_API__cython_code__my_translator +/* Early includes */ +#ifdef _OPENMP +#include +#endif /* _OPENMP */ + +#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS) +#define CYTHON_WITHOUT_ASSERTIONS +#endif + +typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; + const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; + +#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) +#define __PYX_DEFAULT_STRING_ENCODING "" +#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString +#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#define __Pyx_uchar_cast(c) ((unsigned char)c) +#define __Pyx_long_cast(x) ((long)x) +#define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ + (sizeof(type) < sizeof(Py_ssize_t)) ||\ + (sizeof(type) > sizeof(Py_ssize_t) &&\ + likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX) &&\ + (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ + v == (type)PY_SSIZE_T_MIN))) ||\ + (sizeof(type) == sizeof(Py_ssize_t) &&\ + (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX))) ) +static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { + return (size_t) i < (size_t) limit; +} +#if defined (__cplusplus) && __cplusplus >= 201103L + #include + #define __Pyx_sst_abs(value) std::abs(value) +#elif SIZEOF_INT >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) abs(value) +#elif SIZEOF_LONG >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) labs(value) +#elif defined (_MSC_VER) + #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value)) +#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define __Pyx_sst_abs(value) llabs(value) +#elif defined (__GNUC__) + #define __Pyx_sst_abs(value) __builtin_llabs(value) +#else + #define __Pyx_sst_abs(value) ((value<0) ? -value : value) +#endif +static CYTHON_INLINE Py_ssize_t __Pyx_ssize_strlen(const char *s); +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*); +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); +static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char*); +#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) +#define __Pyx_PyBytes_FromString PyBytes_FromString +#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); +#if PY_MAJOR_VERSION < 3 + #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#else + #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize +#endif +#define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyObject_AsWritableString(s) ((char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableSString(s) ((signed char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) +#define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) +#define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) +#define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) +#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) +#define __Pyx_PyUnicode_FromOrdinal(o) PyUnicode_FromOrdinal((int)o) +#define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode +#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) +#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b); +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*); +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); +#define __Pyx_PySequence_Tuple(obj)\ + (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj)) +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*); +#if CYTHON_ASSUME_SAFE_MACROS +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) +#else +#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) +#endif +#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) +#else +#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) +#endif +#if CYTHON_USE_PYLONG_INTERNALS + #if PY_VERSION_HEX >= 0x030C00A7 + #ifndef _PyLong_SIGN_MASK + #define _PyLong_SIGN_MASK 3 + #endif + #ifndef _PyLong_NON_SIZE_BITS + #define _PyLong_NON_SIZE_BITS 3 + #endif + #define __Pyx_PyLong_Sign(x) (((PyLongObject*)x)->long_value.lv_tag & _PyLong_SIGN_MASK) + #define __Pyx_PyLong_IsNeg(x) ((__Pyx_PyLong_Sign(x) & 2) != 0) + #define __Pyx_PyLong_IsNonNeg(x) (!__Pyx_PyLong_IsNeg(x)) + #define __Pyx_PyLong_IsZero(x) (__Pyx_PyLong_Sign(x) & 1) + #define __Pyx_PyLong_IsPos(x) (__Pyx_PyLong_Sign(x) == 0) + #define __Pyx_PyLong_CompactValueUnsigned(x) (__Pyx_PyLong_Digits(x)[0]) + #define __Pyx_PyLong_DigitCount(x) ((Py_ssize_t) (((PyLongObject*)x)->long_value.lv_tag >> _PyLong_NON_SIZE_BITS)) + #define __Pyx_PyLong_SignedDigitCount(x)\ + ((1 - (Py_ssize_t) __Pyx_PyLong_Sign(x)) * __Pyx_PyLong_DigitCount(x)) + #if defined(PyUnstable_Long_IsCompact) && defined(PyUnstable_Long_CompactValue) + #define __Pyx_PyLong_IsCompact(x) PyUnstable_Long_IsCompact((PyLongObject*) x) + #define __Pyx_PyLong_CompactValue(x) PyUnstable_Long_CompactValue((PyLongObject*) x) + #else + #define __Pyx_PyLong_IsCompact(x) (((PyLongObject*)x)->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS)) + #define __Pyx_PyLong_CompactValue(x) ((1 - (Py_ssize_t) __Pyx_PyLong_Sign(x)) * (Py_ssize_t) __Pyx_PyLong_Digits(x)[0]) + #endif + typedef Py_ssize_t __Pyx_compact_pylong; + typedef size_t __Pyx_compact_upylong; + #else + #define __Pyx_PyLong_IsNeg(x) (Py_SIZE(x) < 0) + #define __Pyx_PyLong_IsNonNeg(x) (Py_SIZE(x) >= 0) + #define __Pyx_PyLong_IsZero(x) (Py_SIZE(x) == 0) + #define __Pyx_PyLong_IsPos(x) (Py_SIZE(x) > 0) + #define __Pyx_PyLong_CompactValueUnsigned(x) ((Py_SIZE(x) == 0) ? 0 : __Pyx_PyLong_Digits(x)[0]) + #define __Pyx_PyLong_DigitCount(x) __Pyx_sst_abs(Py_SIZE(x)) + #define __Pyx_PyLong_SignedDigitCount(x) Py_SIZE(x) + #define __Pyx_PyLong_IsCompact(x) (Py_SIZE(x) == 0 || Py_SIZE(x) == 1 || Py_SIZE(x) == -1) + #define __Pyx_PyLong_CompactValue(x)\ + ((Py_SIZE(x) == 0) ? (sdigit) 0 : ((Py_SIZE(x) < 0) ? -(sdigit)__Pyx_PyLong_Digits(x)[0] : (sdigit)__Pyx_PyLong_Digits(x)[0])) + typedef sdigit __Pyx_compact_pylong; + typedef digit __Pyx_compact_upylong; + #endif + #if PY_VERSION_HEX >= 0x030C00A5 + #define __Pyx_PyLong_Digits(x) (((PyLongObject*)x)->long_value.ob_digit) + #else + #define __Pyx_PyLong_Digits(x) (((PyLongObject*)x)->ob_digit) + #endif +#endif +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII +#include +static int __Pyx_sys_getdefaultencoding_not_ascii; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + PyObject* ascii_chars_u = NULL; + PyObject* ascii_chars_b = NULL; + const char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + if (strcmp(default_encoding_c, "ascii") == 0) { + __Pyx_sys_getdefaultencoding_not_ascii = 0; + } else { + char ascii_chars[128]; + int c; + for (c = 0; c < 128; c++) { + ascii_chars[c] = (char) c; + } + __Pyx_sys_getdefaultencoding_not_ascii = 1; + ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); + if (!ascii_chars_u) goto bad; + ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); + if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { + PyErr_Format( + PyExc_ValueError, + "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", + default_encoding_c); + goto bad; + } + Py_DECREF(ascii_chars_u); + Py_DECREF(ascii_chars_b); + } + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + Py_XDECREF(ascii_chars_u); + Py_XDECREF(ascii_chars_b); + return -1; +} +#endif +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) +#else +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +#include +static char* __PYX_DEFAULT_STRING_ENCODING; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1); + if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; + strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + return -1; +} +#endif +#endif + + +/* Test for GCC > 2.95 */ +#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) +#else /* !__GNUC__ or GCC < 2.95 */ + #define likely(x) (x) + #define unlikely(x) (x) +#endif /* __GNUC__ */ +static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; } + +#if !CYTHON_USE_MODULE_STATE +static PyObject *__pyx_m = NULL; +#endif +static int __pyx_lineno; +static int __pyx_clineno = 0; +static const char * __pyx_cfilenm = __FILE__; +static const char *__pyx_filename; + +/* #### Code section: filename_table ### */ + +static const char *__pyx_f[] = { + "cython_code/my_translator.pyx", + "", +}; +/* #### Code section: utility_code_proto_before_types ### */ +/* ForceInitThreads.proto */ +#ifndef __PYX_FORCE_INIT_THREADS + #define __PYX_FORCE_INIT_THREADS 0 +#endif + +/* #### Code section: numeric_typedefs ### */ +/* #### Code section: complex_type_declarations ### */ +/* #### Code section: type_declarations ### */ + +/*--- Type declarations ---*/ +struct __pyx_obj_11cython_code_13my_translator_MyTranslator; + +/* "cython_code/my_translator.pyx":6 + * from data.config import yil_oy_kun, soat_minut_sekund + * + * cdef class MyTranslator: # <<<<<<<<<<<<<< + * cdef str file_path + * cdef str text + */ +struct __pyx_obj_11cython_code_13my_translator_MyTranslator { + PyObject_HEAD + PyObject *file_path; + PyObject *text; + PyObject *lang; + int real; + PyObject *json_data; +}; + +/* #### Code section: utility_code_proto ### */ + +/* --- Runtime support code (head) --- */ +/* Refnanny.proto */ +#ifndef CYTHON_REFNANNY + #define CYTHON_REFNANNY 0 +#endif +#if CYTHON_REFNANNY + typedef struct { + void (*INCREF)(void*, PyObject*, Py_ssize_t); + void (*DECREF)(void*, PyObject*, Py_ssize_t); + void (*GOTREF)(void*, PyObject*, Py_ssize_t); + void (*GIVEREF)(void*, PyObject*, Py_ssize_t); + void* (*SetupContext)(const char*, Py_ssize_t, const char*); + void (*FinishContext)(void**); + } __Pyx_RefNannyAPIStruct; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); + #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; +#ifdef WITH_THREAD + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + if (acquire_gil) {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__));\ + PyGILState_Release(__pyx_gilstate_save);\ + } else {\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__));\ + } + #define __Pyx_RefNannyFinishContextNogil() {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __Pyx_RefNannyFinishContext();\ + PyGILState_Release(__pyx_gilstate_save);\ + } +#else + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__)) + #define __Pyx_RefNannyFinishContextNogil() __Pyx_RefNannyFinishContext() +#endif + #define __Pyx_RefNannyFinishContextNogil() {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __Pyx_RefNannyFinishContext();\ + PyGILState_Release(__pyx_gilstate_save);\ + } + #define __Pyx_RefNannyFinishContext()\ + __Pyx_RefNanny->FinishContext(&__pyx_refnanny) + #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_XINCREF(r) do { if((r) == NULL); else {__Pyx_INCREF(r); }} while(0) + #define __Pyx_XDECREF(r) do { if((r) == NULL); else {__Pyx_DECREF(r); }} while(0) + #define __Pyx_XGOTREF(r) do { if((r) == NULL); else {__Pyx_GOTREF(r); }} while(0) + #define __Pyx_XGIVEREF(r) do { if((r) == NULL); else {__Pyx_GIVEREF(r);}} while(0) +#else + #define __Pyx_RefNannyDeclarations + #define __Pyx_RefNannySetupContext(name, acquire_gil) + #define __Pyx_RefNannyFinishContextNogil() + #define __Pyx_RefNannyFinishContext() + #define __Pyx_INCREF(r) Py_INCREF(r) + #define __Pyx_DECREF(r) Py_DECREF(r) + #define __Pyx_GOTREF(r) + #define __Pyx_GIVEREF(r) + #define __Pyx_XINCREF(r) Py_XINCREF(r) + #define __Pyx_XDECREF(r) Py_XDECREF(r) + #define __Pyx_XGOTREF(r) + #define __Pyx_XGIVEREF(r) +#endif +#define __Pyx_Py_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; Py_XDECREF(tmp);\ + } while (0) +#define __Pyx_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_XDECREF(tmp);\ + } while (0) +#define __Pyx_DECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_DECREF(tmp);\ + } while (0) +#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) +#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) + +/* PyErrExceptionMatches.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err) +static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err); +#else +#define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(err) +#endif + +/* PyThreadStateGet.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; +#define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current; +#if PY_VERSION_HEX >= 0x030C00A6 +#define __Pyx_PyErr_Occurred() (__pyx_tstate->current_exception != NULL) +#define __Pyx_PyErr_CurrentExceptionType() (__pyx_tstate->current_exception ? (PyObject*) Py_TYPE(__pyx_tstate->current_exception) : (PyObject*) NULL) +#else +#define __Pyx_PyErr_Occurred() (__pyx_tstate->curexc_type != NULL) +#define __Pyx_PyErr_CurrentExceptionType() (__pyx_tstate->curexc_type) +#endif +#else +#define __Pyx_PyThreadState_declare +#define __Pyx_PyThreadState_assign +#define __Pyx_PyErr_Occurred() (PyErr_Occurred() != NULL) +#define __Pyx_PyErr_CurrentExceptionType() PyErr_Occurred() +#endif + +/* PyErrFetchRestore.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL) +#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A6 +#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL)) +#else +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#endif +#else +#define __Pyx_PyErr_Clear() PyErr_Clear() +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) +#endif + +/* PyObjectGetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) +#endif + +/* PyObjectGetAttrStrNoError.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name); + +/* GetBuiltinName.proto */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name); + +/* TupleAndListFromArray.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n); +static CYTHON_INLINE PyObject* __Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n); +#endif + +/* IncludeStringH.proto */ +#include + +/* BytesEquals.proto */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); + +/* UnicodeEquals.proto */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); + +/* fastcall.proto */ +#if CYTHON_AVOID_BORROWED_REFS + #define __Pyx_Arg_VARARGS(args, i) PySequence_GetItem(args, i) +#elif CYTHON_ASSUME_SAFE_MACROS + #define __Pyx_Arg_VARARGS(args, i) PyTuple_GET_ITEM(args, i) +#else + #define __Pyx_Arg_VARARGS(args, i) PyTuple_GetItem(args, i) +#endif +#if CYTHON_AVOID_BORROWED_REFS + #define __Pyx_Arg_NewRef_VARARGS(arg) __Pyx_NewRef(arg) + #define __Pyx_Arg_XDECREF_VARARGS(arg) Py_XDECREF(arg) +#else + #define __Pyx_Arg_NewRef_VARARGS(arg) arg + #define __Pyx_Arg_XDECREF_VARARGS(arg) +#endif +#define __Pyx_NumKwargs_VARARGS(kwds) PyDict_Size(kwds) +#define __Pyx_KwValues_VARARGS(args, nargs) NULL +#define __Pyx_GetKwValue_VARARGS(kw, kwvalues, s) __Pyx_PyDict_GetItemStrWithError(kw, s) +#define __Pyx_KwargsAsDict_VARARGS(kw, kwvalues) PyDict_Copy(kw) +#if CYTHON_METH_FASTCALL + #define __Pyx_Arg_FASTCALL(args, i) args[i] + #define __Pyx_NumKwargs_FASTCALL(kwds) PyTuple_GET_SIZE(kwds) + #define __Pyx_KwValues_FASTCALL(args, nargs) ((args) + (nargs)) + static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s); +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000 + CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues); + #else + #define __Pyx_KwargsAsDict_FASTCALL(kw, kwvalues) _PyStack_AsDict(kwvalues, kw) + #endif + #define __Pyx_Arg_NewRef_FASTCALL(arg) arg /* no-op, __Pyx_Arg_FASTCALL is direct and this needs + to have the same reference counting */ + #define __Pyx_Arg_XDECREF_FASTCALL(arg) +#else + #define __Pyx_Arg_FASTCALL __Pyx_Arg_VARARGS + #define __Pyx_NumKwargs_FASTCALL __Pyx_NumKwargs_VARARGS + #define __Pyx_KwValues_FASTCALL __Pyx_KwValues_VARARGS + #define __Pyx_GetKwValue_FASTCALL __Pyx_GetKwValue_VARARGS + #define __Pyx_KwargsAsDict_FASTCALL __Pyx_KwargsAsDict_VARARGS + #define __Pyx_Arg_NewRef_FASTCALL(arg) __Pyx_Arg_NewRef_VARARGS(arg) + #define __Pyx_Arg_XDECREF_FASTCALL(arg) __Pyx_Arg_XDECREF_VARARGS(arg) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS +#define __Pyx_ArgsSlice_VARARGS(args, start, stop) __Pyx_PyTuple_FromArray(&__Pyx_Arg_VARARGS(args, start), stop - start) +#define __Pyx_ArgsSlice_FASTCALL(args, start, stop) __Pyx_PyTuple_FromArray(&__Pyx_Arg_FASTCALL(args, start), stop - start) +#else +#define __Pyx_ArgsSlice_VARARGS(args, start, stop) PyTuple_GetSlice(args, start, stop) +#define __Pyx_ArgsSlice_FASTCALL(args, start, stop) PyTuple_GetSlice(args, start, stop) +#endif + +/* RaiseArgTupleInvalid.proto */ +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); + +/* RaiseDoubleKeywords.proto */ +static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); + +/* ParseKeywords.proto */ +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject *const *kwvalues, + PyObject **argnames[], + PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, + const char* function_name); + +/* ArgTypeTest.proto */ +#define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\ + ((likely(__Pyx_IS_TYPE(obj, type) | (none_allowed && (obj == Py_None)))) ? 1 :\ + __Pyx__ArgTypeTest(obj, type, name, exact)) +static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact); + +/* PyObjectCall.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); +#else +#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) +#endif + +/* PyObjectLookupSpecial.proto */ +#if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS +#define __Pyx_PyObject_LookupSpecialNoError(obj, attr_name) __Pyx__PyObject_LookupSpecial(obj, attr_name, 0) +#define __Pyx_PyObject_LookupSpecial(obj, attr_name) __Pyx__PyObject_LookupSpecial(obj, attr_name, 1) +static CYTHON_INLINE PyObject* __Pyx__PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name, int with_error); +#else +#define __Pyx_PyObject_LookupSpecialNoError(o,n) __Pyx_PyObject_GetAttrStrNoError(o,n) +#define __Pyx_PyObject_LookupSpecial(o,n) __Pyx_PyObject_GetAttrStr(o,n) +#endif + +/* PyFunctionFastCall.proto */ +#if CYTHON_FAST_PYCALL +#if !CYTHON_VECTORCALL +#define __Pyx_PyFunction_FastCall(func, args, nargs)\ + __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL) +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs); +#endif +#define __Pyx_BUILD_ASSERT_EXPR(cond)\ + (sizeof(char [1 - 2*!(cond)]) - 1) +#ifndef Py_MEMBER_SIZE +#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) +#endif +#if !CYTHON_VECTORCALL +#if PY_VERSION_HEX >= 0x03080000 + #include "frameobject.h" +#if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API + #ifndef Py_BUILD_CORE + #define Py_BUILD_CORE 1 + #endif + #include "internal/pycore_frame.h" +#endif + #define __Pxy_PyFrame_Initialize_Offsets() + #define __Pyx_PyFrame_GetLocalsplus(frame) ((frame)->f_localsplus) +#else + static size_t __pyx_pyframe_localsplus_offset = 0; + #include "frameobject.h" + #define __Pxy_PyFrame_Initialize_Offsets()\ + ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ + (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) + #define __Pyx_PyFrame_GetLocalsplus(frame)\ + (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) +#endif +#endif +#endif + +/* PyObjectCallMethO.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); +#endif + +/* PyObjectFastCall.proto */ +#define __Pyx_PyObject_FastCall(func, args, nargs) __Pyx_PyObject_FastCallDict(func, args, (size_t)(nargs), NULL) +static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject **args, size_t nargs, PyObject *kwargs); + +/* PyDictVersioning.proto */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) +#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ + (version_var) = __PYX_GET_DICT_VERSION(dict);\ + (cache_var) = (value); +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ + (VAR) = __pyx_dict_cached_value;\ + } else {\ + (VAR) = __pyx_dict_cached_value = (LOOKUP);\ + __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ + }\ +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); +#else +#define __PYX_GET_DICT_VERSION(dict) (0) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); +#endif + +/* GetModuleGlobalName.proto */ +#if CYTHON_USE_DICT_VERSIONS +#define __Pyx_GetModuleGlobalName(var, name) do {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ + (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ + __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} while(0) +#define __Pyx_GetModuleGlobalNameUncached(var, name) do {\ + PY_UINT64_T __pyx_dict_version;\ + PyObject *__pyx_dict_cached_value;\ + (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} while(0) +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); +#else +#define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) +#define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); +#endif + +/* RaiseUnexpectedTypeError.proto */ +static int __Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj); + +/* GetTopmostException.proto */ +#if CYTHON_USE_EXC_INFO_STACK && CYTHON_FAST_THREAD_STATE +static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate); +#endif + +/* SaveResetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#define __Pyx_ExceptionReset(type, value, tb) __Pyx__ExceptionReset(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +#else +#define __Pyx_ExceptionSave(type, value, tb) PyErr_GetExcInfo(type, value, tb) +#define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb) +#endif + +/* GetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_GetException(type, value, tb) __Pyx__GetException(__pyx_tstate, type, value, tb) +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* FastTypeChecks.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type) +#define __Pyx_TypeCheck2(obj, type1, type2) __Pyx_IsAnySubtype2(Py_TYPE(obj), (PyTypeObject *)type1, (PyTypeObject *)type2) +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b); +static CYTHON_INLINE int __Pyx_IsAnySubtype2(PyTypeObject *cls, PyTypeObject *a, PyTypeObject *b); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2); +#else +#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) +#define __Pyx_TypeCheck2(obj, type1, type2) (PyObject_TypeCheck(obj, (PyTypeObject *)type1) || PyObject_TypeCheck(obj, (PyTypeObject *)type2)) +#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type) +#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2)) +#endif +#define __Pyx_PyErr_ExceptionMatches2(err1, err2) __Pyx_PyErr_GivenExceptionMatches2(__Pyx_PyErr_CurrentExceptionType(), err1, err2) +#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) + +/* PyObject_Unicode.proto */ +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyObject_Unicode(obj)\ + (likely(PyUnicode_CheckExact(obj)) ? __Pyx_NewRef(obj) : PyObject_Str(obj)) +#else +#define __Pyx_PyObject_Unicode(obj)\ + (likely(PyUnicode_CheckExact(obj)) ? __Pyx_NewRef(obj) : PyObject_Unicode(obj)) +#endif + +/* UnicodeConcatInPlace.proto */ +# if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_REFNANNY + #define __Pyx_PyUnicode_ConcatInPlace(left, right) __Pyx_PyUnicode_ConcatInPlaceImpl(&left, right, __pyx_refnanny) + #else + #define __Pyx_PyUnicode_ConcatInPlace(left, right) __Pyx_PyUnicode_ConcatInPlaceImpl(&left, right) + #endif + static CYTHON_INLINE PyObject *__Pyx_PyUnicode_ConcatInPlaceImpl(PyObject **p_left, PyObject *right + #if CYTHON_REFNANNY + , void* __pyx_refnanny + #endif + ); +#else +#define __Pyx_PyUnicode_ConcatInPlace __Pyx_PyUnicode_Concat +#endif +#define __Pyx_PyUnicode_ConcatInPlaceSafe(left, right) ((unlikely((left) == Py_None) || unlikely((right) == Py_None)) ?\ + PyNumber_InPlaceAdd(left, right) : __Pyx_PyUnicode_ConcatInPlace(left, right)) + +/* KeywordStringCheck.proto */ +static int __Pyx_CheckKeywordStrings(PyObject *kw, const char* function_name, int kw_allowed); + +/* DictGetItem.proto */ +#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY +static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key); +#define __Pyx_PyObject_Dict_GetItem(obj, name)\ + (likely(PyDict_CheckExact(obj)) ?\ + __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name)) +#else +#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key) +#define __Pyx_PyObject_Dict_GetItem(obj, name) PyObject_GetItem(obj, name) +#endif + +/* SwapException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* GetAttr3.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); + +/* PySequenceContains.proto */ +static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) { + int result = PySequence_Contains(seq, item); + return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); +} + +/* Import.proto */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); + +/* ImportFrom.proto */ +static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); + +/* RaiseException.proto */ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); + +/* GetItemInt.proto */ +#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\ + (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\ + __Pyx_GetItemInt_Generic(o, to_py_func(i)))) +#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ + (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ + (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, + int is_list, int wraparound, int boundscheck); + +/* GetAttr.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *); + +/* HasAttr.proto */ +static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *); + +/* IncludeStructmemberH.proto */ +#include + +/* FixUpExtensionType.proto */ +#if CYTHON_USE_TYPE_SPECS +static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type); +#endif + +/* PyObjectCallNoArg.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); + +/* PyObjectCallOneArg.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); + +/* PyObjectGetMethod.proto */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); + +/* PyObjectCallMethod0.proto */ +static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); + +/* ValidateBasesTuple.proto */ +#if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS +static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases); +#endif + +/* PyType_Ready.proto */ +CYTHON_UNUSED static int __Pyx_PyType_Ready(PyTypeObject *t); + +/* PyObject_GenericGetAttrNoDict.proto */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr +#endif + +/* PyObject_GenericGetAttr.proto */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr +#endif + +/* SetupReduce.proto */ +#if !CYTHON_COMPILING_IN_LIMITED_API +static int __Pyx_setup_reduce(PyObject* type_obj); +#endif + +/* ImportDottedModule.proto */ +static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple); +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple); +#endif + +/* FetchSharedCythonModule.proto */ +static PyObject *__Pyx_FetchSharedCythonABIModule(void); + +/* FetchCommonType.proto */ +#if !CYTHON_USE_TYPE_SPECS +static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type); +#else +static PyTypeObject* __Pyx_FetchCommonTypeFromSpec(PyObject *module, PyType_Spec *spec, PyObject *bases); +#endif + +/* PyMethodNew.proto */ +#if CYTHON_COMPILING_IN_LIMITED_API +static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) { + PyObject *typesModule=NULL, *methodType=NULL, *result=NULL; + CYTHON_UNUSED_VAR(typ); + if (!self) + return __Pyx_NewRef(func); + typesModule = PyImport_ImportModule("types"); + if (!typesModule) return NULL; + methodType = PyObject_GetAttrString(typesModule, "MethodType"); + Py_DECREF(typesModule); + if (!methodType) return NULL; + result = PyObject_CallFunctionObjArgs(methodType, func, self, NULL); + Py_DECREF(methodType); + return result; +} +#elif PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) { + CYTHON_UNUSED_VAR(typ); + if (!self) + return __Pyx_NewRef(func); + return PyMethod_New(func, self); +} +#else + #define __Pyx_PyMethod_New PyMethod_New +#endif + +/* PyVectorcallFastCallDict.proto */ +#if CYTHON_METH_FASTCALL +static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw); +#endif + +/* CythonFunctionShared.proto */ +#define __Pyx_CyFunction_USED +#define __Pyx_CYFUNCTION_STATICMETHOD 0x01 +#define __Pyx_CYFUNCTION_CLASSMETHOD 0x02 +#define __Pyx_CYFUNCTION_CCLASS 0x04 +#define __Pyx_CYFUNCTION_COROUTINE 0x08 +#define __Pyx_CyFunction_GetClosure(f)\ + (((__pyx_CyFunctionObject *) (f))->func_closure) +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_CyFunction_GetClassObj(f)\ + (((__pyx_CyFunctionObject *) (f))->func_classobj) +#else + #define __Pyx_CyFunction_GetClassObj(f)\ + ((PyObject*) ((PyCMethodObject *) (f))->mm_class) +#endif +#define __Pyx_CyFunction_SetClassObj(f, classobj)\ + __Pyx__CyFunction_SetClassObj((__pyx_CyFunctionObject *) (f), (classobj)) +#define __Pyx_CyFunction_Defaults(type, f)\ + ((type *)(((__pyx_CyFunctionObject *) (f))->defaults)) +#define __Pyx_CyFunction_SetDefaultsGetter(f, g)\ + ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g) +typedef struct { +#if CYTHON_COMPILING_IN_LIMITED_API + PyObject_HEAD + PyObject *func; +#elif PY_VERSION_HEX < 0x030900B1 + PyCFunctionObject func; +#else + PyCMethodObject func; +#endif +#if CYTHON_BACKPORT_VECTORCALL + __pyx_vectorcallfunc func_vectorcall; +#endif +#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API + PyObject *func_weakreflist; +#endif + PyObject *func_dict; + PyObject *func_name; + PyObject *func_qualname; + PyObject *func_doc; + PyObject *func_globals; + PyObject *func_code; + PyObject *func_closure; +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + PyObject *func_classobj; +#endif + void *defaults; + int defaults_pyobjects; + size_t defaults_size; + int flags; + PyObject *defaults_tuple; + PyObject *defaults_kwdict; + PyObject *(*defaults_getter)(PyObject *); + PyObject *func_annotations; + PyObject *func_is_coroutine; +} __pyx_CyFunctionObject; +#undef __Pyx_CyOrPyCFunction_Check +#define __Pyx_CyFunction_Check(obj) __Pyx_TypeCheck(obj, __pyx_CyFunctionType) +#define __Pyx_CyOrPyCFunction_Check(obj) __Pyx_TypeCheck2(obj, __pyx_CyFunctionType, &PyCFunction_Type) +#define __Pyx_CyFunction_CheckExact(obj) __Pyx_IS_TYPE(obj, __pyx_CyFunctionType) +static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc); +#undef __Pyx_IsSameCFunction +#define __Pyx_IsSameCFunction(func, cfunc) __Pyx__IsSameCyOrCFunction(func, cfunc) +static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject* op, PyMethodDef *ml, + int flags, PyObject* qualname, + PyObject *closure, + PyObject *module, PyObject *globals, + PyObject* code); +static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj); +static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m, + size_t size, + int pyobjects); +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m, + PyObject *tuple); +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m, + PyObject *dict); +static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m, + PyObject *dict); +static int __pyx_CyFunction_init(PyObject *module); +#if CYTHON_METH_FASTCALL +static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +#if CYTHON_BACKPORT_VECTORCALL +#define __Pyx_CyFunction_func_vectorcall(f) (((__pyx_CyFunctionObject*)f)->func_vectorcall) +#else +#define __Pyx_CyFunction_func_vectorcall(f) (((PyCFunctionObject*)f)->vectorcall) +#endif +#endif + +/* CythonFunction.proto */ +static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, + int flags, PyObject* qualname, + PyObject *closure, + PyObject *module, PyObject *globals, + PyObject* code); + +/* CLineInTraceback.proto */ +#ifdef CYTHON_CLINE_IN_TRACEBACK +#define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0) +#else +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line); +#endif + +/* CodeObjectCache.proto */ +#if !CYTHON_COMPILING_IN_LIMITED_API +typedef struct { + PyCodeObject* code_object; + int code_line; +} __Pyx_CodeObjectCacheEntry; +struct __Pyx_CodeObjectCache { + int count; + int max_count; + __Pyx_CodeObjectCacheEntry* entries; +}; +static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); +static PyCodeObject *__pyx_find_code_object(int code_line); +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); +#endif + +/* AddTraceback.proto */ +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename); + +/* GCCDiagnostics.proto */ +#if !defined(__INTEL_COMPILER) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +#define __Pyx_HAS_GCC_DIAGNOSTIC +#endif + +/* CIntFromPy.proto */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + +/* FormatTypeName.proto */ +#if CYTHON_COMPILING_IN_LIMITED_API +typedef PyObject *__Pyx_TypeName; +#define __Pyx_FMT_TYPENAME "%U" +static __Pyx_TypeName __Pyx_PyType_GetName(PyTypeObject* tp); +#define __Pyx_DECREF_TypeName(obj) Py_XDECREF(obj) +#else +typedef const char *__Pyx_TypeName; +#define __Pyx_FMT_TYPENAME "%.200s" +#define __Pyx_PyType_GetName(tp) ((tp)->tp_name) +#define __Pyx_DECREF_TypeName(obj) +#endif + +/* CIntFromPy.proto */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); + +/* CheckBinaryVersion.proto */ +static unsigned long __Pyx_get_runtime_version(void); +static int __Pyx_check_binary_version(unsigned long ct_version, unsigned long rt_version, int allow_newer); + +/* InitStrings.proto */ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); + +/* #### Code section: module_declarations ### */ + +/* Module declarations from "cython_code.my_translator" */ +static PyObject *__pyx_f_11cython_code_13my_translator___pyx_unpickle_MyTranslator__set_state(struct __pyx_obj_11cython_code_13my_translator_MyTranslator *, PyObject *); /*proto*/ +/* #### Code section: typeinfo ### */ +/* #### Code section: before_global_var ### */ +#define __Pyx_MODULE_NAME "cython_code.my_translator" +extern int __pyx_module_is_main_cython_code__my_translator; +int __pyx_module_is_main_cython_code__my_translator = 0; + +/* Implementation of "cython_code.my_translator" */ +/* #### Code section: global_var ### */ +static PyObject *__pyx_builtin_open; +static PyObject *__pyx_builtin_KeyError; +/* #### Code section: string_decls ### */ +static const char __pyx_k_r[] = "r"; +static const char __pyx_k_w[] = "w"; +static const char __pyx_k__2[] = " / "; +static const char __pyx_k__4[] = "."; +static const char __pyx_k__5[] = "*"; +static const char __pyx_k_gc[] = "gc"; +static const char __pyx_k__14[] = "?"; +static const char __pyx_k_err[] = "err"; +static const char __pyx_k_new[] = "__new__"; +static const char __pyx_k_auto[] = "auto"; +static const char __pyx_k_data[] = "data"; +static const char __pyx_k_date[] = "date"; +static const char __pyx_k_dict[] = "__dict__"; +static const char __pyx_k_dump[] = "dump"; +static const char __pyx_k_exit[] = "__exit__"; +static const char __pyx_k_json[] = "json"; +static const char __pyx_k_lang[] = "lang"; +static const char __pyx_k_load[] = "load"; +static const char __pyx_k_main[] = "__main__"; +static const char __pyx_k_name[] = "__name__"; +static const char __pyx_k_open[] = "open"; +static const char __pyx_k_real[] = "real"; +static const char __pyx_k_self[] = "self"; +static const char __pyx_k_spec[] = "__spec__"; +static const char __pyx_k_test[] = "__test__"; +static const char __pyx_k_text[] = "text"; +static const char __pyx_k_enter[] = "__enter__"; +static const char __pyx_k_error[] = "error"; +static const char __pyx_k_state[] = "state"; +static const char __pyx_k_dict_2[] = "_dict"; +static const char __pyx_k_enable[] = "enable"; +static const char __pyx_k_import[] = "__import__"; +static const char __pyx_k_pickle[] = "pickle"; +static const char __pyx_k_reduce[] = "__reduce__"; +static const char __pyx_k_result[] = "result"; +static const char __pyx_k_source[] = "source"; +static const char __pyx_k_target[] = "target"; +static const char __pyx_k_update[] = "update"; +static const char __pyx_k_disable[] = "disable"; +static const char __pyx_k_logging[] = "logging"; +static const char __pyx_k_KeyError[] = "KeyError"; +static const char __pyx_k_getstate[] = "__getstate__"; +static const char __pyx_k_pyx_type[] = "__pyx_type"; +static const char __pyx_k_setstate[] = "__setstate__"; +static const char __pyx_k_file_path[] = "file_path"; +static const char __pyx_k_isenabled[] = "isenabled"; +static const char __pyx_k_json_file[] = "json_file"; +static const char __pyx_k_pyx_state[] = "__pyx_state"; +static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; +static const char __pyx_k_translate[] = "translate"; +static const char __pyx_k_pyx_result[] = "__pyx_result"; +static const char __pyx_k_translator[] = "translator"; +static const char __pyx_k_yil_oy_kun[] = "yil_oy_kun"; +static const char __pyx_k_PickleError[] = "PickleError"; +static const char __pyx_k_data_config[] = "data.config"; +static const char __pyx_k_MyTranslator[] = "MyTranslator"; +static const char __pyx_k_initializing[] = "_initializing"; +static const char __pyx_k_is_coroutine[] = "_is_coroutine"; +static const char __pyx_k_pyx_checksum[] = "__pyx_checksum"; +static const char __pyx_k_stringsource[] = ""; +static const char __pyx_k_use_setstate[] = "use_setstate"; +static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; +static const char __pyx_k_JSONDecodeError[] = "JSONDecodeError"; +static const char __pyx_k_deep_translator[] = "deep_translator"; +static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError"; +static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; +static const char __pyx_k_GoogleTranslator[] = "GoogleTranslator"; +static const char __pyx_k_FileNotFoundError[] = "FileNotFoundError"; +static const char __pyx_k_soat_minut_sekund[] = "soat_minut_sekund"; +static const char __pyx_k_asyncio_coroutines[] = "asyncio.coroutines"; +static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; +static const char __pyx_k_MyTranslator_translator[] = "MyTranslator.translator"; +static const char __pyx_k_cython_code_my_translator[] = "cython_code.my_translator"; +static const char __pyx_k_pyx_unpickle_MyTranslator[] = "__pyx_unpickle_MyTranslator"; +static const char __pyx_k_MyTranslator___reduce_cython[] = "MyTranslator.__reduce_cython__"; +static const char __pyx_k_cython_code_my_translator_pyx[] = "cython_code/my_translator.pyx"; +static const char __pyx_k_MyTranslator___setstate_cython[] = "MyTranslator.__setstate_cython__"; +static const char __pyx_k_Incompatible_checksums_0x_x_vs_0[] = "Incompatible checksums (0x%x vs (0xaa02da6, 0x1c6bc4b, 0x57a17a8) = (file_path, json_data, lang, real, text))"; +/* #### Code section: decls ### */ +static int __pyx_pf_11cython_code_13my_translator_12MyTranslator___init__(struct __pyx_obj_11cython_code_13my_translator_MyTranslator *__pyx_v_self, PyObject *__pyx_v_file_path, PyObject *__pyx_v_text, PyObject *__pyx_v_lang, int __pyx_v_real); /* proto */ +static PyObject *__pyx_pf_11cython_code_13my_translator_12MyTranslator_2translator(struct __pyx_obj_11cython_code_13my_translator_MyTranslator *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_11cython_code_13my_translator_12MyTranslator_4__reduce_cython__(struct __pyx_obj_11cython_code_13my_translator_MyTranslator *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_11cython_code_13my_translator_12MyTranslator_6__setstate_cython__(struct __pyx_obj_11cython_code_13my_translator_MyTranslator *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_11cython_code_13my_translator___pyx_unpickle_MyTranslator(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_tp_new_11cython_code_13my_translator_MyTranslator(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +/* #### Code section: late_includes ### */ +/* #### Code section: module_state ### */ +typedef struct { + PyObject *__pyx_d; + PyObject *__pyx_b; + PyObject *__pyx_cython_runtime; + PyObject *__pyx_empty_tuple; + PyObject *__pyx_empty_bytes; + PyObject *__pyx_empty_unicode; + #ifdef __Pyx_CyFunction_USED + PyTypeObject *__pyx_CyFunctionType; + #endif + #ifdef __Pyx_FusedFunction_USED + PyTypeObject *__pyx_FusedFunctionType; + #endif + #ifdef __Pyx_Generator_USED + PyTypeObject *__pyx_GeneratorType; + #endif + #ifdef __Pyx_IterableCoroutine_USED + PyTypeObject *__pyx_IterableCoroutineType; + #endif + #ifdef __Pyx_Coroutine_USED + PyTypeObject *__pyx_CoroutineAwaitType; + #endif + #ifdef __Pyx_Coroutine_USED + PyTypeObject *__pyx_CoroutineType; + #endif + #if CYTHON_USE_MODULE_STATE + PyObject *__pyx_type_11cython_code_13my_translator_MyTranslator; + #endif + PyTypeObject *__pyx_ptype_11cython_code_13my_translator_MyTranslator; + PyObject *__pyx_n_s_FileNotFoundError; + PyObject *__pyx_n_s_GoogleTranslator; + PyObject *__pyx_kp_s_Incompatible_checksums_0x_x_vs_0; + PyObject *__pyx_n_s_JSONDecodeError; + PyObject *__pyx_n_s_KeyError; + PyObject *__pyx_n_s_MyTranslator; + PyObject *__pyx_n_s_MyTranslator___reduce_cython; + PyObject *__pyx_n_s_MyTranslator___setstate_cython; + PyObject *__pyx_n_s_MyTranslator_translator; + PyObject *__pyx_n_s_PickleError; + PyObject *__pyx_n_s__14; + PyObject *__pyx_kp_u__2; + PyObject *__pyx_kp_u__4; + PyObject *__pyx_n_s__5; + PyObject *__pyx_n_s_asyncio_coroutines; + PyObject *__pyx_n_u_auto; + PyObject *__pyx_n_s_cline_in_traceback; + PyObject *__pyx_n_s_cython_code_my_translator; + PyObject *__pyx_kp_s_cython_code_my_translator_pyx; + PyObject *__pyx_n_s_data; + PyObject *__pyx_n_s_data_config; + PyObject *__pyx_n_u_date; + PyObject *__pyx_n_s_deep_translator; + PyObject *__pyx_n_s_dict; + PyObject *__pyx_n_s_dict_2; + PyObject *__pyx_kp_u_disable; + PyObject *__pyx_n_s_dump; + PyObject *__pyx_kp_u_enable; + PyObject *__pyx_n_s_enter; + PyObject *__pyx_n_s_err; + PyObject *__pyx_n_s_error; + PyObject *__pyx_n_s_exit; + PyObject *__pyx_n_s_file_path; + PyObject *__pyx_kp_u_gc; + PyObject *__pyx_n_s_getstate; + PyObject *__pyx_n_s_import; + PyObject *__pyx_n_s_initializing; + PyObject *__pyx_n_s_is_coroutine; + PyObject *__pyx_kp_u_isenabled; + PyObject *__pyx_n_s_json; + PyObject *__pyx_n_s_json_file; + PyObject *__pyx_n_s_lang; + PyObject *__pyx_n_s_load; + PyObject *__pyx_n_s_logging; + PyObject *__pyx_n_s_main; + PyObject *__pyx_n_s_name; + PyObject *__pyx_n_s_new; + PyObject *__pyx_n_s_open; + PyObject *__pyx_n_s_pickle; + PyObject *__pyx_n_s_pyx_PickleError; + PyObject *__pyx_n_s_pyx_checksum; + PyObject *__pyx_n_s_pyx_result; + PyObject *__pyx_n_s_pyx_state; + PyObject *__pyx_n_s_pyx_type; + PyObject *__pyx_n_s_pyx_unpickle_MyTranslator; + PyObject *__pyx_n_u_r; + PyObject *__pyx_n_s_real; + PyObject *__pyx_n_s_reduce; + PyObject *__pyx_n_s_reduce_cython; + PyObject *__pyx_n_s_reduce_ex; + PyObject *__pyx_n_s_result; + PyObject *__pyx_n_s_self; + PyObject *__pyx_n_s_setstate; + PyObject *__pyx_n_s_setstate_cython; + PyObject *__pyx_n_s_soat_minut_sekund; + PyObject *__pyx_n_s_source; + PyObject *__pyx_n_s_spec; + PyObject *__pyx_n_s_state; + PyObject *__pyx_kp_s_stringsource; + PyObject *__pyx_n_s_target; + PyObject *__pyx_n_s_test; + PyObject *__pyx_n_s_text; + PyObject *__pyx_n_s_translate; + PyObject *__pyx_n_s_translator; + PyObject *__pyx_n_s_update; + PyObject *__pyx_n_s_use_setstate; + PyObject *__pyx_n_u_w; + PyObject *__pyx_n_s_yil_oy_kun; + PyObject *__pyx_int_29801547; + PyObject *__pyx_int_91887528; + PyObject *__pyx_int_178269606; + PyObject *__pyx_tuple_; + PyObject *__pyx_tuple__3; + PyObject *__pyx_tuple__6; + PyObject *__pyx_tuple__8; + PyObject *__pyx_tuple__10; + PyObject *__pyx_tuple__12; + PyObject *__pyx_codeobj__7; + PyObject *__pyx_codeobj__9; + PyObject *__pyx_codeobj__11; + PyObject *__pyx_codeobj__13; +} __pyx_mstate; + +#if CYTHON_USE_MODULE_STATE +#ifdef __cplusplus +namespace { + extern struct PyModuleDef __pyx_moduledef; +} /* anonymous namespace */ +#else +static struct PyModuleDef __pyx_moduledef; +#endif + +#define __pyx_mstate(o) ((__pyx_mstate *)__Pyx_PyModule_GetState(o)) + +#define __pyx_mstate_global (__pyx_mstate(PyState_FindModule(&__pyx_moduledef))) + +#define __pyx_m (PyState_FindModule(&__pyx_moduledef)) +#else +static __pyx_mstate __pyx_mstate_global_static = +#ifdef __cplusplus + {}; +#else + {0}; +#endif +static __pyx_mstate *__pyx_mstate_global = &__pyx_mstate_global_static; +#endif +/* #### Code section: module_state_clear ### */ +#if CYTHON_USE_MODULE_STATE +static int __pyx_m_clear(PyObject *m) { + __pyx_mstate *clear_module_state = __pyx_mstate(m); + if (!clear_module_state) return 0; + Py_CLEAR(clear_module_state->__pyx_d); + Py_CLEAR(clear_module_state->__pyx_b); + Py_CLEAR(clear_module_state->__pyx_cython_runtime); + Py_CLEAR(clear_module_state->__pyx_empty_tuple); + Py_CLEAR(clear_module_state->__pyx_empty_bytes); + Py_CLEAR(clear_module_state->__pyx_empty_unicode); + #ifdef __Pyx_CyFunction_USED + Py_CLEAR(clear_module_state->__pyx_CyFunctionType); + #endif + #ifdef __Pyx_FusedFunction_USED + Py_CLEAR(clear_module_state->__pyx_FusedFunctionType); + #endif + Py_CLEAR(clear_module_state->__pyx_ptype_11cython_code_13my_translator_MyTranslator); + Py_CLEAR(clear_module_state->__pyx_type_11cython_code_13my_translator_MyTranslator); + Py_CLEAR(clear_module_state->__pyx_n_s_FileNotFoundError); + Py_CLEAR(clear_module_state->__pyx_n_s_GoogleTranslator); + Py_CLEAR(clear_module_state->__pyx_kp_s_Incompatible_checksums_0x_x_vs_0); + Py_CLEAR(clear_module_state->__pyx_n_s_JSONDecodeError); + Py_CLEAR(clear_module_state->__pyx_n_s_KeyError); + Py_CLEAR(clear_module_state->__pyx_n_s_MyTranslator); + Py_CLEAR(clear_module_state->__pyx_n_s_MyTranslator___reduce_cython); + Py_CLEAR(clear_module_state->__pyx_n_s_MyTranslator___setstate_cython); + Py_CLEAR(clear_module_state->__pyx_n_s_MyTranslator_translator); + Py_CLEAR(clear_module_state->__pyx_n_s_PickleError); + Py_CLEAR(clear_module_state->__pyx_n_s__14); + Py_CLEAR(clear_module_state->__pyx_kp_u__2); + Py_CLEAR(clear_module_state->__pyx_kp_u__4); + Py_CLEAR(clear_module_state->__pyx_n_s__5); + Py_CLEAR(clear_module_state->__pyx_n_s_asyncio_coroutines); + Py_CLEAR(clear_module_state->__pyx_n_u_auto); + Py_CLEAR(clear_module_state->__pyx_n_s_cline_in_traceback); + Py_CLEAR(clear_module_state->__pyx_n_s_cython_code_my_translator); + Py_CLEAR(clear_module_state->__pyx_kp_s_cython_code_my_translator_pyx); + Py_CLEAR(clear_module_state->__pyx_n_s_data); + Py_CLEAR(clear_module_state->__pyx_n_s_data_config); + Py_CLEAR(clear_module_state->__pyx_n_u_date); + Py_CLEAR(clear_module_state->__pyx_n_s_deep_translator); + Py_CLEAR(clear_module_state->__pyx_n_s_dict); + Py_CLEAR(clear_module_state->__pyx_n_s_dict_2); + Py_CLEAR(clear_module_state->__pyx_kp_u_disable); + Py_CLEAR(clear_module_state->__pyx_n_s_dump); + Py_CLEAR(clear_module_state->__pyx_kp_u_enable); + Py_CLEAR(clear_module_state->__pyx_n_s_enter); + Py_CLEAR(clear_module_state->__pyx_n_s_err); + Py_CLEAR(clear_module_state->__pyx_n_s_error); + Py_CLEAR(clear_module_state->__pyx_n_s_exit); + Py_CLEAR(clear_module_state->__pyx_n_s_file_path); + Py_CLEAR(clear_module_state->__pyx_kp_u_gc); + Py_CLEAR(clear_module_state->__pyx_n_s_getstate); + Py_CLEAR(clear_module_state->__pyx_n_s_import); + Py_CLEAR(clear_module_state->__pyx_n_s_initializing); + Py_CLEAR(clear_module_state->__pyx_n_s_is_coroutine); + Py_CLEAR(clear_module_state->__pyx_kp_u_isenabled); + Py_CLEAR(clear_module_state->__pyx_n_s_json); + Py_CLEAR(clear_module_state->__pyx_n_s_json_file); + Py_CLEAR(clear_module_state->__pyx_n_s_lang); + Py_CLEAR(clear_module_state->__pyx_n_s_load); + Py_CLEAR(clear_module_state->__pyx_n_s_logging); + Py_CLEAR(clear_module_state->__pyx_n_s_main); + Py_CLEAR(clear_module_state->__pyx_n_s_name); + Py_CLEAR(clear_module_state->__pyx_n_s_new); + Py_CLEAR(clear_module_state->__pyx_n_s_open); + Py_CLEAR(clear_module_state->__pyx_n_s_pickle); + Py_CLEAR(clear_module_state->__pyx_n_s_pyx_PickleError); + Py_CLEAR(clear_module_state->__pyx_n_s_pyx_checksum); + Py_CLEAR(clear_module_state->__pyx_n_s_pyx_result); + Py_CLEAR(clear_module_state->__pyx_n_s_pyx_state); + Py_CLEAR(clear_module_state->__pyx_n_s_pyx_type); + Py_CLEAR(clear_module_state->__pyx_n_s_pyx_unpickle_MyTranslator); + Py_CLEAR(clear_module_state->__pyx_n_u_r); + Py_CLEAR(clear_module_state->__pyx_n_s_real); + Py_CLEAR(clear_module_state->__pyx_n_s_reduce); + Py_CLEAR(clear_module_state->__pyx_n_s_reduce_cython); + Py_CLEAR(clear_module_state->__pyx_n_s_reduce_ex); + Py_CLEAR(clear_module_state->__pyx_n_s_result); + Py_CLEAR(clear_module_state->__pyx_n_s_self); + Py_CLEAR(clear_module_state->__pyx_n_s_setstate); + Py_CLEAR(clear_module_state->__pyx_n_s_setstate_cython); + Py_CLEAR(clear_module_state->__pyx_n_s_soat_minut_sekund); + Py_CLEAR(clear_module_state->__pyx_n_s_source); + Py_CLEAR(clear_module_state->__pyx_n_s_spec); + Py_CLEAR(clear_module_state->__pyx_n_s_state); + Py_CLEAR(clear_module_state->__pyx_kp_s_stringsource); + Py_CLEAR(clear_module_state->__pyx_n_s_target); + Py_CLEAR(clear_module_state->__pyx_n_s_test); + Py_CLEAR(clear_module_state->__pyx_n_s_text); + Py_CLEAR(clear_module_state->__pyx_n_s_translate); + Py_CLEAR(clear_module_state->__pyx_n_s_translator); + Py_CLEAR(clear_module_state->__pyx_n_s_update); + Py_CLEAR(clear_module_state->__pyx_n_s_use_setstate); + Py_CLEAR(clear_module_state->__pyx_n_u_w); + Py_CLEAR(clear_module_state->__pyx_n_s_yil_oy_kun); + Py_CLEAR(clear_module_state->__pyx_int_29801547); + Py_CLEAR(clear_module_state->__pyx_int_91887528); + Py_CLEAR(clear_module_state->__pyx_int_178269606); + Py_CLEAR(clear_module_state->__pyx_tuple_); + Py_CLEAR(clear_module_state->__pyx_tuple__3); + Py_CLEAR(clear_module_state->__pyx_tuple__6); + Py_CLEAR(clear_module_state->__pyx_tuple__8); + Py_CLEAR(clear_module_state->__pyx_tuple__10); + Py_CLEAR(clear_module_state->__pyx_tuple__12); + Py_CLEAR(clear_module_state->__pyx_codeobj__7); + Py_CLEAR(clear_module_state->__pyx_codeobj__9); + Py_CLEAR(clear_module_state->__pyx_codeobj__11); + Py_CLEAR(clear_module_state->__pyx_codeobj__13); + return 0; +} +#endif +/* #### Code section: module_state_traverse ### */ +#if CYTHON_USE_MODULE_STATE +static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { + __pyx_mstate *traverse_module_state = __pyx_mstate(m); + if (!traverse_module_state) return 0; + Py_VISIT(traverse_module_state->__pyx_d); + Py_VISIT(traverse_module_state->__pyx_b); + Py_VISIT(traverse_module_state->__pyx_cython_runtime); + Py_VISIT(traverse_module_state->__pyx_empty_tuple); + Py_VISIT(traverse_module_state->__pyx_empty_bytes); + Py_VISIT(traverse_module_state->__pyx_empty_unicode); + #ifdef __Pyx_CyFunction_USED + Py_VISIT(traverse_module_state->__pyx_CyFunctionType); + #endif + #ifdef __Pyx_FusedFunction_USED + Py_VISIT(traverse_module_state->__pyx_FusedFunctionType); + #endif + Py_VISIT(traverse_module_state->__pyx_ptype_11cython_code_13my_translator_MyTranslator); + Py_VISIT(traverse_module_state->__pyx_type_11cython_code_13my_translator_MyTranslator); + Py_VISIT(traverse_module_state->__pyx_n_s_FileNotFoundError); + Py_VISIT(traverse_module_state->__pyx_n_s_GoogleTranslator); + Py_VISIT(traverse_module_state->__pyx_kp_s_Incompatible_checksums_0x_x_vs_0); + Py_VISIT(traverse_module_state->__pyx_n_s_JSONDecodeError); + Py_VISIT(traverse_module_state->__pyx_n_s_KeyError); + Py_VISIT(traverse_module_state->__pyx_n_s_MyTranslator); + Py_VISIT(traverse_module_state->__pyx_n_s_MyTranslator___reduce_cython); + Py_VISIT(traverse_module_state->__pyx_n_s_MyTranslator___setstate_cython); + Py_VISIT(traverse_module_state->__pyx_n_s_MyTranslator_translator); + Py_VISIT(traverse_module_state->__pyx_n_s_PickleError); + Py_VISIT(traverse_module_state->__pyx_n_s__14); + Py_VISIT(traverse_module_state->__pyx_kp_u__2); + Py_VISIT(traverse_module_state->__pyx_kp_u__4); + Py_VISIT(traverse_module_state->__pyx_n_s__5); + Py_VISIT(traverse_module_state->__pyx_n_s_asyncio_coroutines); + Py_VISIT(traverse_module_state->__pyx_n_u_auto); + Py_VISIT(traverse_module_state->__pyx_n_s_cline_in_traceback); + Py_VISIT(traverse_module_state->__pyx_n_s_cython_code_my_translator); + Py_VISIT(traverse_module_state->__pyx_kp_s_cython_code_my_translator_pyx); + Py_VISIT(traverse_module_state->__pyx_n_s_data); + Py_VISIT(traverse_module_state->__pyx_n_s_data_config); + Py_VISIT(traverse_module_state->__pyx_n_u_date); + Py_VISIT(traverse_module_state->__pyx_n_s_deep_translator); + Py_VISIT(traverse_module_state->__pyx_n_s_dict); + Py_VISIT(traverse_module_state->__pyx_n_s_dict_2); + Py_VISIT(traverse_module_state->__pyx_kp_u_disable); + Py_VISIT(traverse_module_state->__pyx_n_s_dump); + Py_VISIT(traverse_module_state->__pyx_kp_u_enable); + Py_VISIT(traverse_module_state->__pyx_n_s_enter); + Py_VISIT(traverse_module_state->__pyx_n_s_err); + Py_VISIT(traverse_module_state->__pyx_n_s_error); + Py_VISIT(traverse_module_state->__pyx_n_s_exit); + Py_VISIT(traverse_module_state->__pyx_n_s_file_path); + Py_VISIT(traverse_module_state->__pyx_kp_u_gc); + Py_VISIT(traverse_module_state->__pyx_n_s_getstate); + Py_VISIT(traverse_module_state->__pyx_n_s_import); + Py_VISIT(traverse_module_state->__pyx_n_s_initializing); + Py_VISIT(traverse_module_state->__pyx_n_s_is_coroutine); + Py_VISIT(traverse_module_state->__pyx_kp_u_isenabled); + Py_VISIT(traverse_module_state->__pyx_n_s_json); + Py_VISIT(traverse_module_state->__pyx_n_s_json_file); + Py_VISIT(traverse_module_state->__pyx_n_s_lang); + Py_VISIT(traverse_module_state->__pyx_n_s_load); + Py_VISIT(traverse_module_state->__pyx_n_s_logging); + Py_VISIT(traverse_module_state->__pyx_n_s_main); + Py_VISIT(traverse_module_state->__pyx_n_s_name); + Py_VISIT(traverse_module_state->__pyx_n_s_new); + Py_VISIT(traverse_module_state->__pyx_n_s_open); + Py_VISIT(traverse_module_state->__pyx_n_s_pickle); + Py_VISIT(traverse_module_state->__pyx_n_s_pyx_PickleError); + Py_VISIT(traverse_module_state->__pyx_n_s_pyx_checksum); + Py_VISIT(traverse_module_state->__pyx_n_s_pyx_result); + Py_VISIT(traverse_module_state->__pyx_n_s_pyx_state); + Py_VISIT(traverse_module_state->__pyx_n_s_pyx_type); + Py_VISIT(traverse_module_state->__pyx_n_s_pyx_unpickle_MyTranslator); + Py_VISIT(traverse_module_state->__pyx_n_u_r); + Py_VISIT(traverse_module_state->__pyx_n_s_real); + Py_VISIT(traverse_module_state->__pyx_n_s_reduce); + Py_VISIT(traverse_module_state->__pyx_n_s_reduce_cython); + Py_VISIT(traverse_module_state->__pyx_n_s_reduce_ex); + Py_VISIT(traverse_module_state->__pyx_n_s_result); + Py_VISIT(traverse_module_state->__pyx_n_s_self); + Py_VISIT(traverse_module_state->__pyx_n_s_setstate); + Py_VISIT(traverse_module_state->__pyx_n_s_setstate_cython); + Py_VISIT(traverse_module_state->__pyx_n_s_soat_minut_sekund); + Py_VISIT(traverse_module_state->__pyx_n_s_source); + Py_VISIT(traverse_module_state->__pyx_n_s_spec); + Py_VISIT(traverse_module_state->__pyx_n_s_state); + Py_VISIT(traverse_module_state->__pyx_kp_s_stringsource); + Py_VISIT(traverse_module_state->__pyx_n_s_target); + Py_VISIT(traverse_module_state->__pyx_n_s_test); + Py_VISIT(traverse_module_state->__pyx_n_s_text); + Py_VISIT(traverse_module_state->__pyx_n_s_translate); + Py_VISIT(traverse_module_state->__pyx_n_s_translator); + Py_VISIT(traverse_module_state->__pyx_n_s_update); + Py_VISIT(traverse_module_state->__pyx_n_s_use_setstate); + Py_VISIT(traverse_module_state->__pyx_n_u_w); + Py_VISIT(traverse_module_state->__pyx_n_s_yil_oy_kun); + Py_VISIT(traverse_module_state->__pyx_int_29801547); + Py_VISIT(traverse_module_state->__pyx_int_91887528); + Py_VISIT(traverse_module_state->__pyx_int_178269606); + Py_VISIT(traverse_module_state->__pyx_tuple_); + Py_VISIT(traverse_module_state->__pyx_tuple__3); + Py_VISIT(traverse_module_state->__pyx_tuple__6); + Py_VISIT(traverse_module_state->__pyx_tuple__8); + Py_VISIT(traverse_module_state->__pyx_tuple__10); + Py_VISIT(traverse_module_state->__pyx_tuple__12); + Py_VISIT(traverse_module_state->__pyx_codeobj__7); + Py_VISIT(traverse_module_state->__pyx_codeobj__9); + Py_VISIT(traverse_module_state->__pyx_codeobj__11); + Py_VISIT(traverse_module_state->__pyx_codeobj__13); + return 0; +} +#endif +/* #### Code section: module_state_defines ### */ +#define __pyx_d __pyx_mstate_global->__pyx_d +#define __pyx_b __pyx_mstate_global->__pyx_b +#define __pyx_cython_runtime __pyx_mstate_global->__pyx_cython_runtime +#define __pyx_empty_tuple __pyx_mstate_global->__pyx_empty_tuple +#define __pyx_empty_bytes __pyx_mstate_global->__pyx_empty_bytes +#define __pyx_empty_unicode __pyx_mstate_global->__pyx_empty_unicode +#ifdef __Pyx_CyFunction_USED +#define __pyx_CyFunctionType __pyx_mstate_global->__pyx_CyFunctionType +#endif +#ifdef __Pyx_FusedFunction_USED +#define __pyx_FusedFunctionType __pyx_mstate_global->__pyx_FusedFunctionType +#endif +#ifdef __Pyx_Generator_USED +#define __pyx_GeneratorType __pyx_mstate_global->__pyx_GeneratorType +#endif +#ifdef __Pyx_IterableCoroutine_USED +#define __pyx_IterableCoroutineType __pyx_mstate_global->__pyx_IterableCoroutineType +#endif +#ifdef __Pyx_Coroutine_USED +#define __pyx_CoroutineAwaitType __pyx_mstate_global->__pyx_CoroutineAwaitType +#endif +#ifdef __Pyx_Coroutine_USED +#define __pyx_CoroutineType __pyx_mstate_global->__pyx_CoroutineType +#endif +#if CYTHON_USE_MODULE_STATE +#define __pyx_type_11cython_code_13my_translator_MyTranslator __pyx_mstate_global->__pyx_type_11cython_code_13my_translator_MyTranslator +#endif +#define __pyx_ptype_11cython_code_13my_translator_MyTranslator __pyx_mstate_global->__pyx_ptype_11cython_code_13my_translator_MyTranslator +#define __pyx_n_s_FileNotFoundError __pyx_mstate_global->__pyx_n_s_FileNotFoundError +#define __pyx_n_s_GoogleTranslator __pyx_mstate_global->__pyx_n_s_GoogleTranslator +#define __pyx_kp_s_Incompatible_checksums_0x_x_vs_0 __pyx_mstate_global->__pyx_kp_s_Incompatible_checksums_0x_x_vs_0 +#define __pyx_n_s_JSONDecodeError __pyx_mstate_global->__pyx_n_s_JSONDecodeError +#define __pyx_n_s_KeyError __pyx_mstate_global->__pyx_n_s_KeyError +#define __pyx_n_s_MyTranslator __pyx_mstate_global->__pyx_n_s_MyTranslator +#define __pyx_n_s_MyTranslator___reduce_cython __pyx_mstate_global->__pyx_n_s_MyTranslator___reduce_cython +#define __pyx_n_s_MyTranslator___setstate_cython __pyx_mstate_global->__pyx_n_s_MyTranslator___setstate_cython +#define __pyx_n_s_MyTranslator_translator __pyx_mstate_global->__pyx_n_s_MyTranslator_translator +#define __pyx_n_s_PickleError __pyx_mstate_global->__pyx_n_s_PickleError +#define __pyx_n_s__14 __pyx_mstate_global->__pyx_n_s__14 +#define __pyx_kp_u__2 __pyx_mstate_global->__pyx_kp_u__2 +#define __pyx_kp_u__4 __pyx_mstate_global->__pyx_kp_u__4 +#define __pyx_n_s__5 __pyx_mstate_global->__pyx_n_s__5 +#define __pyx_n_s_asyncio_coroutines __pyx_mstate_global->__pyx_n_s_asyncio_coroutines +#define __pyx_n_u_auto __pyx_mstate_global->__pyx_n_u_auto +#define __pyx_n_s_cline_in_traceback __pyx_mstate_global->__pyx_n_s_cline_in_traceback +#define __pyx_n_s_cython_code_my_translator __pyx_mstate_global->__pyx_n_s_cython_code_my_translator +#define __pyx_kp_s_cython_code_my_translator_pyx __pyx_mstate_global->__pyx_kp_s_cython_code_my_translator_pyx +#define __pyx_n_s_data __pyx_mstate_global->__pyx_n_s_data +#define __pyx_n_s_data_config __pyx_mstate_global->__pyx_n_s_data_config +#define __pyx_n_u_date __pyx_mstate_global->__pyx_n_u_date +#define __pyx_n_s_deep_translator __pyx_mstate_global->__pyx_n_s_deep_translator +#define __pyx_n_s_dict __pyx_mstate_global->__pyx_n_s_dict +#define __pyx_n_s_dict_2 __pyx_mstate_global->__pyx_n_s_dict_2 +#define __pyx_kp_u_disable __pyx_mstate_global->__pyx_kp_u_disable +#define __pyx_n_s_dump __pyx_mstate_global->__pyx_n_s_dump +#define __pyx_kp_u_enable __pyx_mstate_global->__pyx_kp_u_enable +#define __pyx_n_s_enter __pyx_mstate_global->__pyx_n_s_enter +#define __pyx_n_s_err __pyx_mstate_global->__pyx_n_s_err +#define __pyx_n_s_error __pyx_mstate_global->__pyx_n_s_error +#define __pyx_n_s_exit __pyx_mstate_global->__pyx_n_s_exit +#define __pyx_n_s_file_path __pyx_mstate_global->__pyx_n_s_file_path +#define __pyx_kp_u_gc __pyx_mstate_global->__pyx_kp_u_gc +#define __pyx_n_s_getstate __pyx_mstate_global->__pyx_n_s_getstate +#define __pyx_n_s_import __pyx_mstate_global->__pyx_n_s_import +#define __pyx_n_s_initializing __pyx_mstate_global->__pyx_n_s_initializing +#define __pyx_n_s_is_coroutine __pyx_mstate_global->__pyx_n_s_is_coroutine +#define __pyx_kp_u_isenabled __pyx_mstate_global->__pyx_kp_u_isenabled +#define __pyx_n_s_json __pyx_mstate_global->__pyx_n_s_json +#define __pyx_n_s_json_file __pyx_mstate_global->__pyx_n_s_json_file +#define __pyx_n_s_lang __pyx_mstate_global->__pyx_n_s_lang +#define __pyx_n_s_load __pyx_mstate_global->__pyx_n_s_load +#define __pyx_n_s_logging __pyx_mstate_global->__pyx_n_s_logging +#define __pyx_n_s_main __pyx_mstate_global->__pyx_n_s_main +#define __pyx_n_s_name __pyx_mstate_global->__pyx_n_s_name +#define __pyx_n_s_new __pyx_mstate_global->__pyx_n_s_new +#define __pyx_n_s_open __pyx_mstate_global->__pyx_n_s_open +#define __pyx_n_s_pickle __pyx_mstate_global->__pyx_n_s_pickle +#define __pyx_n_s_pyx_PickleError __pyx_mstate_global->__pyx_n_s_pyx_PickleError +#define __pyx_n_s_pyx_checksum __pyx_mstate_global->__pyx_n_s_pyx_checksum +#define __pyx_n_s_pyx_result __pyx_mstate_global->__pyx_n_s_pyx_result +#define __pyx_n_s_pyx_state __pyx_mstate_global->__pyx_n_s_pyx_state +#define __pyx_n_s_pyx_type __pyx_mstate_global->__pyx_n_s_pyx_type +#define __pyx_n_s_pyx_unpickle_MyTranslator __pyx_mstate_global->__pyx_n_s_pyx_unpickle_MyTranslator +#define __pyx_n_u_r __pyx_mstate_global->__pyx_n_u_r +#define __pyx_n_s_real __pyx_mstate_global->__pyx_n_s_real +#define __pyx_n_s_reduce __pyx_mstate_global->__pyx_n_s_reduce +#define __pyx_n_s_reduce_cython __pyx_mstate_global->__pyx_n_s_reduce_cython +#define __pyx_n_s_reduce_ex __pyx_mstate_global->__pyx_n_s_reduce_ex +#define __pyx_n_s_result __pyx_mstate_global->__pyx_n_s_result +#define __pyx_n_s_self __pyx_mstate_global->__pyx_n_s_self +#define __pyx_n_s_setstate __pyx_mstate_global->__pyx_n_s_setstate +#define __pyx_n_s_setstate_cython __pyx_mstate_global->__pyx_n_s_setstate_cython +#define __pyx_n_s_soat_minut_sekund __pyx_mstate_global->__pyx_n_s_soat_minut_sekund +#define __pyx_n_s_source __pyx_mstate_global->__pyx_n_s_source +#define __pyx_n_s_spec __pyx_mstate_global->__pyx_n_s_spec +#define __pyx_n_s_state __pyx_mstate_global->__pyx_n_s_state +#define __pyx_kp_s_stringsource __pyx_mstate_global->__pyx_kp_s_stringsource +#define __pyx_n_s_target __pyx_mstate_global->__pyx_n_s_target +#define __pyx_n_s_test __pyx_mstate_global->__pyx_n_s_test +#define __pyx_n_s_text __pyx_mstate_global->__pyx_n_s_text +#define __pyx_n_s_translate __pyx_mstate_global->__pyx_n_s_translate +#define __pyx_n_s_translator __pyx_mstate_global->__pyx_n_s_translator +#define __pyx_n_s_update __pyx_mstate_global->__pyx_n_s_update +#define __pyx_n_s_use_setstate __pyx_mstate_global->__pyx_n_s_use_setstate +#define __pyx_n_u_w __pyx_mstate_global->__pyx_n_u_w +#define __pyx_n_s_yil_oy_kun __pyx_mstate_global->__pyx_n_s_yil_oy_kun +#define __pyx_int_29801547 __pyx_mstate_global->__pyx_int_29801547 +#define __pyx_int_91887528 __pyx_mstate_global->__pyx_int_91887528 +#define __pyx_int_178269606 __pyx_mstate_global->__pyx_int_178269606 +#define __pyx_tuple_ __pyx_mstate_global->__pyx_tuple_ +#define __pyx_tuple__3 __pyx_mstate_global->__pyx_tuple__3 +#define __pyx_tuple__6 __pyx_mstate_global->__pyx_tuple__6 +#define __pyx_tuple__8 __pyx_mstate_global->__pyx_tuple__8 +#define __pyx_tuple__10 __pyx_mstate_global->__pyx_tuple__10 +#define __pyx_tuple__12 __pyx_mstate_global->__pyx_tuple__12 +#define __pyx_codeobj__7 __pyx_mstate_global->__pyx_codeobj__7 +#define __pyx_codeobj__9 __pyx_mstate_global->__pyx_codeobj__9 +#define __pyx_codeobj__11 __pyx_mstate_global->__pyx_codeobj__11 +#define __pyx_codeobj__13 __pyx_mstate_global->__pyx_codeobj__13 +/* #### Code section: module_code ### */ + +/* "cython_code/my_translator.pyx":13 + * cdef dict json_data + * + * def __init__(self, str file_path, str text, str lang, bint real=False): # <<<<<<<<<<<<<< + * self.file_path = file_path + * self.text = text + */ + +/* Python wrapper */ +static int __pyx_pw_11cython_code_13my_translator_12MyTranslator_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_11cython_code_13my_translator_12MyTranslator_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_file_path = 0; + PyObject *__pyx_v_text = 0; + PyObject *__pyx_v_lang = 0; + int __pyx_v_real; + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[4] = {0,0,0,0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1; + #endif + __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_file_path,&__pyx_n_s_text,&__pyx_n_s_lang,&__pyx_n_s_real,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 4: values[3] = __Pyx_Arg_VARARGS(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = __Pyx_Arg_VARARGS(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_file_path)) != 0)) { + (void)__Pyx_Arg_NewRef_VARARGS(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 13, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_text)) != 0)) { + (void)__Pyx_Arg_NewRef_VARARGS(values[1]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 13, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("__init__", 0, 3, 4, 1); __PYX_ERR(0, 13, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_lang)) != 0)) { + (void)__Pyx_Arg_NewRef_VARARGS(values[2]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 13, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("__init__", 0, 3, 4, 2); __PYX_ERR(0, 13, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (kw_args > 0) { + PyObject* value = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_real); + if (value) { values[3] = __Pyx_Arg_NewRef_VARARGS(value); kw_args--; } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 13, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 13, __pyx_L3_error) + } + } else { + switch (__pyx_nargs) { + case 4: values[3] = __Pyx_Arg_VARARGS(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = __Pyx_Arg_VARARGS(__pyx_args, 2); + values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1); + values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_file_path = ((PyObject*)values[0]); + __pyx_v_text = ((PyObject*)values[1]); + __pyx_v_lang = ((PyObject*)values[2]); + if (values[3]) { + __pyx_v_real = __Pyx_PyObject_IsTrue(values[3]); if (unlikely((__pyx_v_real == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 13, __pyx_L3_error) + } else { + __pyx_v_real = ((int)0); + } + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 0, 3, 4, __pyx_nargs); __PYX_ERR(0, 13, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.my_translator.MyTranslator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_file_path), (&PyUnicode_Type), 1, "file_path", 1))) __PYX_ERR(0, 13, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_text), (&PyUnicode_Type), 1, "text", 1))) __PYX_ERR(0, 13, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_lang), (&PyUnicode_Type), 1, "lang", 1))) __PYX_ERR(0, 13, __pyx_L1_error) + __pyx_r = __pyx_pf_11cython_code_13my_translator_12MyTranslator___init__(((struct __pyx_obj_11cython_code_13my_translator_MyTranslator *)__pyx_v_self), __pyx_v_file_path, __pyx_v_text, __pyx_v_lang, __pyx_v_real); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_11cython_code_13my_translator_12MyTranslator___init__(struct __pyx_obj_11cython_code_13my_translator_MyTranslator *__pyx_v_self, PyObject *__pyx_v_file_path, PyObject *__pyx_v_text, PyObject *__pyx_v_lang, int __pyx_v_real) { + PyObject *__pyx_v_json_file = NULL; + PyObject *__pyx_v_data = NULL; + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + unsigned int __pyx_t_9; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + int __pyx_t_14; + int __pyx_t_15; + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + int __pyx_t_18; + PyObject *__pyx_t_19 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__init__", 1); + + /* "cython_code/my_translator.pyx":14 + * + * def __init__(self, str file_path, str text, str lang, bint real=False): + * self.file_path = file_path # <<<<<<<<<<<<<< + * self.text = text + * self.lang = lang + */ + __Pyx_INCREF(__pyx_v_file_path); + __Pyx_GIVEREF(__pyx_v_file_path); + __Pyx_GOTREF(__pyx_v_self->file_path); + __Pyx_DECREF(__pyx_v_self->file_path); + __pyx_v_self->file_path = __pyx_v_file_path; + + /* "cython_code/my_translator.pyx":15 + * def __init__(self, str file_path, str text, str lang, bint real=False): + * self.file_path = file_path + * self.text = text # <<<<<<<<<<<<<< + * self.lang = lang + * self.real = real + */ + __Pyx_INCREF(__pyx_v_text); + __Pyx_GIVEREF(__pyx_v_text); + __Pyx_GOTREF(__pyx_v_self->text); + __Pyx_DECREF(__pyx_v_self->text); + __pyx_v_self->text = __pyx_v_text; + + /* "cython_code/my_translator.pyx":16 + * self.file_path = file_path + * self.text = text + * self.lang = lang # <<<<<<<<<<<<<< + * self.real = real + * try: + */ + __Pyx_INCREF(__pyx_v_lang); + __Pyx_GIVEREF(__pyx_v_lang); + __Pyx_GOTREF(__pyx_v_self->lang); + __Pyx_DECREF(__pyx_v_self->lang); + __pyx_v_self->lang = __pyx_v_lang; + + /* "cython_code/my_translator.pyx":17 + * self.text = text + * self.lang = lang + * self.real = real # <<<<<<<<<<<<<< + * try: + * with open(self.file_path, "r") as json_file: + */ + __pyx_v_self->real = __pyx_v_real; + + /* "cython_code/my_translator.pyx":18 + * self.lang = lang + * self.real = real + * try: # <<<<<<<<<<<<<< + * with open(self.file_path, "r") as json_file: + * self.json_data = json.load(json_file) + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "cython_code/my_translator.pyx":19 + * self.real = real + * try: + * with open(self.file_path, "r") as json_file: # <<<<<<<<<<<<<< + * self.json_data = json.load(json_file) + * except (FileNotFoundError, json.JSONDecodeError): + */ + /*with:*/ { + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 19, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_v_self->file_path); + __Pyx_GIVEREF(__pyx_v_self->file_path); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_v_self->file_path)) __PYX_ERR(0, 19, __pyx_L3_error); + __Pyx_INCREF(__pyx_n_u_r); + __Pyx_GIVEREF(__pyx_n_u_r); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_n_u_r)) __PYX_ERR(0, 19, __pyx_L3_error); + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_4, NULL); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 19, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 19, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_7 = __Pyx_PyObject_LookupSpecial(__pyx_t_5, __pyx_n_s_enter); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 19, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_8, NULL}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_9, 0+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 19, __pyx_L9_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __pyx_t_7 = __pyx_t_4; + __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + /*try:*/ { + __pyx_v_json_file = __pyx_t_7; + __pyx_t_7 = 0; + + /* "cython_code/my_translator.pyx":20 + * try: + * with open(self.file_path, "r") as json_file: + * self.json_data = json.load(json_file) # <<<<<<<<<<<<<< + * except (FileNotFoundError, json.JSONDecodeError): + * data = {"date": str(yil_oy_kun) + ' / ' + str(soat_minut_sekund)} + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_json); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 20, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_load); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 20, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_json_file}; + __pyx_t_7 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 20, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + if (!(likely(PyDict_CheckExact(__pyx_t_7))||((__pyx_t_7) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_7))) __PYX_ERR(0, 20, __pyx_L13_error) + __Pyx_GIVEREF(__pyx_t_7); + __Pyx_GOTREF(__pyx_v_self->json_data); + __Pyx_DECREF(__pyx_v_self->json_data); + __pyx_v_self->json_data = ((PyObject*)__pyx_t_7); + __pyx_t_7 = 0; + + /* "cython_code/my_translator.pyx":19 + * self.real = real + * try: + * with open(self.file_path, "r") as json_file: # <<<<<<<<<<<<<< + * self.json_data = json.load(json_file) + * except (FileNotFoundError, json.JSONDecodeError): + */ + } + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L18_try_end; + __pyx_L13_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + /*except:*/ { + __Pyx_AddTraceback("cython_code.my_translator.MyTranslator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 19, __pyx_L15_except_error) + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + __pyx_t_8 = PyTuple_Pack(3, __pyx_t_7, __pyx_t_4, __pyx_t_5); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 19, __pyx_L15_except_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 19, __pyx_L15_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (__pyx_t_14 < 0) __PYX_ERR(0, 19, __pyx_L15_except_error) + __pyx_t_15 = (!__pyx_t_14); + if (unlikely(__pyx_t_15)) { + __Pyx_GIVEREF(__pyx_t_7); + __Pyx_GIVEREF(__pyx_t_4); + __Pyx_XGIVEREF(__pyx_t_5); + __Pyx_ErrRestoreWithState(__pyx_t_7, __pyx_t_4, __pyx_t_5); + __pyx_t_7 = 0; __pyx_t_4 = 0; __pyx_t_5 = 0; + __PYX_ERR(0, 19, __pyx_L15_except_error) + } + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L14_exception_handled; + } + __pyx_L15_except_error:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + goto __pyx_L3_error; + __pyx_L14_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + __pyx_L18_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_6) { + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 19, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + goto __pyx_L12; + } + __pyx_L12:; + } + goto __pyx_L22; + __pyx_L9_error:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L3_error; + __pyx_L22:; + } + + /* "cython_code/my_translator.pyx":18 + * self.lang = lang + * self.real = real + * try: # <<<<<<<<<<<<<< + * with open(self.file_path, "r") as json_file: + * self.json_data = json.load(json_file) + */ + } + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L8_try_end; + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "cython_code/my_translator.pyx":21 + * with open(self.file_path, "r") as json_file: + * self.json_data = json.load(json_file) + * except (FileNotFoundError, json.JSONDecodeError): # <<<<<<<<<<<<<< + * data = {"date": str(yil_oy_kun) + ' / ' + str(soat_minut_sekund)} + * with open(self.file_path, "w") as json_file: + */ + __Pyx_ErrFetch(&__pyx_t_5, &__pyx_t_4, &__pyx_t_7); + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_FileNotFoundError); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 21, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_json); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 21, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_JSONDecodeError); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 21, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_18 = __Pyx_PyErr_GivenExceptionMatches2(__pyx_t_5, __pyx_t_8, __pyx_t_17); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_ErrRestore(__pyx_t_5, __pyx_t_4, __pyx_t_7); + __pyx_t_5 = 0; __pyx_t_4 = 0; __pyx_t_7 = 0; + if (__pyx_t_18) { + __Pyx_AddTraceback("cython_code.my_translator.MyTranslator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 21, __pyx_L5_except_error) + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + + /* "cython_code/my_translator.pyx":22 + * self.json_data = json.load(json_file) + * except (FileNotFoundError, json.JSONDecodeError): + * data = {"date": str(yil_oy_kun) + ' / ' + str(soat_minut_sekund)} # <<<<<<<<<<<<<< + * with open(self.file_path, "w") as json_file: + * json.dump(data, json_file) + */ + __pyx_t_17 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 22, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_yil_oy_kun); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 22, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_16 = __Pyx_PyObject_Unicode(__pyx_t_8); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 22, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyUnicode_ConcatInPlace(__pyx_t_16, __pyx_kp_u__2); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 22, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_soat_minut_sekund); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 22, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_19 = __Pyx_PyObject_Unicode(__pyx_t_16); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 22, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_16 = __Pyx_PyUnicode_ConcatInPlace(__pyx_t_8, __pyx_t_19); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 22, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + if (PyDict_SetItem(__pyx_t_17, __pyx_n_u_date, __pyx_t_16) < 0) __PYX_ERR(0, 22, __pyx_L5_except_error) + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_v_data = ((PyObject*)__pyx_t_17); + __pyx_t_17 = 0; + + /* "cython_code/my_translator.pyx":23 + * except (FileNotFoundError, json.JSONDecodeError): + * data = {"date": str(yil_oy_kun) + ' / ' + str(soat_minut_sekund)} + * with open(self.file_path, "w") as json_file: # <<<<<<<<<<<<<< + * json.dump(data, json_file) + * with open(self.file_path, "r") as json_file: + */ + /*with:*/ { + __pyx_t_17 = PyTuple_New(2); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 23, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_INCREF(__pyx_v_self->file_path); + __Pyx_GIVEREF(__pyx_v_self->file_path); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_17, 0, __pyx_v_self->file_path)) __PYX_ERR(0, 23, __pyx_L5_except_error); + __Pyx_INCREF(__pyx_n_u_w); + __Pyx_GIVEREF(__pyx_n_u_w); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_17, 1, __pyx_n_u_w)) __PYX_ERR(0, 23, __pyx_L5_except_error); + __pyx_t_16 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_17, NULL); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 23, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_16, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 23, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_19 = __Pyx_PyObject_LookupSpecial(__pyx_t_16, __pyx_n_s_enter); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 23, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_19))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_19); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_19, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_8, NULL}; + __pyx_t_17 = __Pyx_PyObject_FastCall(__pyx_t_19, __pyx_callargs+1-__pyx_t_9, 0+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 23, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + } + __pyx_t_19 = __pyx_t_17; + __pyx_t_17 = 0; + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_12, &__pyx_t_11, &__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_10); + /*try:*/ { + __Pyx_XDECREF_SET(__pyx_v_json_file, __pyx_t_19); + __pyx_t_19 = 0; + + /* "cython_code/my_translator.pyx":24 + * data = {"date": str(yil_oy_kun) + ' / ' + str(soat_minut_sekund)} + * with open(self.file_path, "w") as json_file: + * json.dump(data, json_file) # <<<<<<<<<<<<<< + * with open(self.file_path, "r") as json_file: + * self.json_data = json.load(json_file) + */ + __Pyx_GetModuleGlobalName(__pyx_t_16, __pyx_n_s_json); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 24, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_16); + __pyx_t_17 = __Pyx_PyObject_GetAttrStr(__pyx_t_16, __pyx_n_s_dump); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 24, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_16 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_17))) { + __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_17); + if (likely(__pyx_t_16)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_17); + __Pyx_INCREF(__pyx_t_16); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_17, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[3] = {__pyx_t_16, __pyx_v_data, __pyx_v_json_file}; + __pyx_t_19 = __Pyx_PyObject_FastCall(__pyx_t_17, __pyx_callargs+1-__pyx_t_9, 2+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 24, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + } + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + + /* "cython_code/my_translator.pyx":23 + * except (FileNotFoundError, json.JSONDecodeError): + * data = {"date": str(yil_oy_kun) + ' / ' + str(soat_minut_sekund)} + * with open(self.file_path, "w") as json_file: # <<<<<<<<<<<<<< + * json.dump(data, json_file) + * with open(self.file_path, "r") as json_file: + */ + } + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + goto __pyx_L38_try_end; + __pyx_L31_error:; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + /*except:*/ { + __Pyx_AddTraceback("cython_code.my_translator.MyTranslator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_19, &__pyx_t_17, &__pyx_t_16) < 0) __PYX_ERR(0, 23, __pyx_L33_except_error) + __Pyx_XGOTREF(__pyx_t_19); + __Pyx_XGOTREF(__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_16); + __pyx_t_8 = PyTuple_Pack(3, __pyx_t_19, __pyx_t_17, __pyx_t_16); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 23, __pyx_L33_except_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 23, __pyx_L33_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_15 = __Pyx_PyObject_IsTrue(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (__pyx_t_15 < 0) __PYX_ERR(0, 23, __pyx_L33_except_error) + __pyx_t_14 = (!__pyx_t_15); + if (unlikely(__pyx_t_14)) { + __Pyx_GIVEREF(__pyx_t_19); + __Pyx_GIVEREF(__pyx_t_17); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ErrRestoreWithState(__pyx_t_19, __pyx_t_17, __pyx_t_16); + __pyx_t_19 = 0; __pyx_t_17 = 0; __pyx_t_16 = 0; + __PYX_ERR(0, 23, __pyx_L33_except_error) + } + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + goto __pyx_L32_exception_handled; + } + __pyx_L33_except_error:; + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_11, __pyx_t_10); + goto __pyx_L5_except_error; + __pyx_L32_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_ExceptionReset(__pyx_t_12, __pyx_t_11, __pyx_t_10); + __pyx_L38_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_6) { + __pyx_t_10 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_10)) __PYX_ERR(0, 23, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_10); + __Pyx_DECREF(__pyx_t_10); __pyx_t_10 = 0; + } + goto __pyx_L30; + } + __pyx_L30:; + } + goto __pyx_L42; + __pyx_L25_error:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L5_except_error; + __pyx_L42:; + } + + /* "cython_code/my_translator.pyx":25 + * with open(self.file_path, "w") as json_file: + * json.dump(data, json_file) + * with open(self.file_path, "r") as json_file: # <<<<<<<<<<<<<< + * self.json_data = json.load(json_file) + * + */ + /*with:*/ { + __pyx_t_16 = PyTuple_New(2); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 25, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_INCREF(__pyx_v_self->file_path); + __Pyx_GIVEREF(__pyx_v_self->file_path); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_16, 0, __pyx_v_self->file_path)) __PYX_ERR(0, 25, __pyx_L5_except_error); + __Pyx_INCREF(__pyx_n_u_r); + __Pyx_GIVEREF(__pyx_n_u_r); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_16, 1, __pyx_n_u_r)) __PYX_ERR(0, 25, __pyx_L5_except_error); + __pyx_t_17 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_16, NULL); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 25, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_17); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + __pyx_t_6 = __Pyx_PyObject_LookupSpecial(__pyx_t_17, __pyx_n_s_exit); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 25, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_19 = __Pyx_PyObject_LookupSpecial(__pyx_t_17, __pyx_n_s_enter); if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 25, __pyx_L43_error) + __Pyx_GOTREF(__pyx_t_19); + __pyx_t_8 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_19))) { + __pyx_t_8 = PyMethod_GET_SELF(__pyx_t_19); + if (likely(__pyx_t_8)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_19); + __Pyx_INCREF(__pyx_t_8); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_19, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_8, NULL}; + __pyx_t_16 = __Pyx_PyObject_FastCall(__pyx_t_19, __pyx_callargs+1-__pyx_t_9, 0+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 25, __pyx_L43_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_19); __pyx_t_19 = 0; + } + __pyx_t_19 = __pyx_t_16; + __pyx_t_16 = 0; + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_10, &__pyx_t_11, &__pyx_t_12); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_12); + /*try:*/ { + __Pyx_XDECREF_SET(__pyx_v_json_file, __pyx_t_19); + __pyx_t_19 = 0; + + /* "cython_code/my_translator.pyx":26 + * json.dump(data, json_file) + * with open(self.file_path, "r") as json_file: + * self.json_data = json.load(json_file) # <<<<<<<<<<<<<< + * + * def translator(self): + */ + __Pyx_GetModuleGlobalName(__pyx_t_17, __pyx_n_s_json); if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 26, __pyx_L49_error) + __Pyx_GOTREF(__pyx_t_17); + __pyx_t_16 = __Pyx_PyObject_GetAttrStr(__pyx_t_17, __pyx_n_s_load); if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 26, __pyx_L49_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + __pyx_t_17 = NULL; + __pyx_t_9 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_16))) { + __pyx_t_17 = PyMethod_GET_SELF(__pyx_t_16); + if (likely(__pyx_t_17)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_16); + __Pyx_INCREF(__pyx_t_17); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_16, function); + __pyx_t_9 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_17, __pyx_v_json_file}; + __pyx_t_19 = __Pyx_PyObject_FastCall(__pyx_t_16, __pyx_callargs+1-__pyx_t_9, 1+__pyx_t_9); + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + if (unlikely(!__pyx_t_19)) __PYX_ERR(0, 26, __pyx_L49_error) + __Pyx_GOTREF(__pyx_t_19); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + } + if (!(likely(PyDict_CheckExact(__pyx_t_19))||((__pyx_t_19) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_19))) __PYX_ERR(0, 26, __pyx_L49_error) + __Pyx_GIVEREF(__pyx_t_19); + __Pyx_GOTREF(__pyx_v_self->json_data); + __Pyx_DECREF(__pyx_v_self->json_data); + __pyx_v_self->json_data = ((PyObject*)__pyx_t_19); + __pyx_t_19 = 0; + + /* "cython_code/my_translator.pyx":25 + * with open(self.file_path, "w") as json_file: + * json.dump(data, json_file) + * with open(self.file_path, "r") as json_file: # <<<<<<<<<<<<<< + * self.json_data = json.load(json_file) + * + */ + } + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + goto __pyx_L56_try_end; + __pyx_L49_error:; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + /*except:*/ { + __Pyx_AddTraceback("cython_code.my_translator.MyTranslator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_19, &__pyx_t_16, &__pyx_t_17) < 0) __PYX_ERR(0, 25, __pyx_L51_except_error) + __Pyx_XGOTREF(__pyx_t_19); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_17); + __pyx_t_8 = PyTuple_Pack(3, __pyx_t_19, __pyx_t_16, __pyx_t_17); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 25, __pyx_L51_except_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_13 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_t_8, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 25, __pyx_L51_except_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = __Pyx_PyObject_IsTrue(__pyx_t_13); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (__pyx_t_14 < 0) __PYX_ERR(0, 25, __pyx_L51_except_error) + __pyx_t_15 = (!__pyx_t_14); + if (unlikely(__pyx_t_15)) { + __Pyx_GIVEREF(__pyx_t_19); + __Pyx_GIVEREF(__pyx_t_16); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_ErrRestoreWithState(__pyx_t_19, __pyx_t_16, __pyx_t_17); + __pyx_t_19 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; + __PYX_ERR(0, 25, __pyx_L51_except_error) + } + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_17); __pyx_t_17 = 0; + goto __pyx_L50_exception_handled; + } + __pyx_L51_except_error:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + goto __pyx_L5_except_error; + __pyx_L50_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_12); + __Pyx_ExceptionReset(__pyx_t_10, __pyx_t_11, __pyx_t_12); + __pyx_L56_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_6) { + __pyx_t_12 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 25, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_12); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + } + goto __pyx_L48; + } + __pyx_L48:; + } + goto __pyx_L60; + __pyx_L43_error:; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L5_except_error; + __pyx_L60:; + } + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L4_exception_handled; + } + goto __pyx_L5_except_error; + + /* "cython_code/my_translator.pyx":18 + * self.lang = lang + * self.real = real + * try: # <<<<<<<<<<<<<< + * with open(self.file_path, "r") as json_file: + * self.json_data = json.load(json_file) + */ + __pyx_L5_except_error:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L4_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + __pyx_L8_try_end:; + } + + /* "cython_code/my_translator.pyx":13 + * cdef dict json_data + * + * def __init__(self, str file_path, str text, str lang, bint real=False): # <<<<<<<<<<<<<< + * self.file_path = file_path + * self.text = text + */ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_16); + __Pyx_XDECREF(__pyx_t_17); + __Pyx_XDECREF(__pyx_t_19); + __Pyx_AddTraceback("cython_code.my_translator.MyTranslator.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_json_file); + __Pyx_XDECREF(__pyx_v_data); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cython_code/my_translator.pyx":28 + * self.json_data = json.load(json_file) + * + * def translator(self): # <<<<<<<<<<<<<< + * try: + * if self.real: + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_13my_translator_12MyTranslator_3translator(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_13my_translator_12MyTranslator_3translator = {"translator", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_13my_translator_12MyTranslator_3translator, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_13my_translator_12MyTranslator_3translator(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("translator (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + if (unlikely(__pyx_nargs > 0)) { + __Pyx_RaiseArgtupleInvalid("translator", 1, 0, 0, __pyx_nargs); return NULL;} + if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "translator", 0))) return NULL; + __pyx_r = __pyx_pf_11cython_code_13my_translator_12MyTranslator_2translator(((struct __pyx_obj_11cython_code_13my_translator_MyTranslator *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_13my_translator_12MyTranslator_2translator(struct __pyx_obj_11cython_code_13my_translator_MyTranslator *__pyx_v_self) { + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_v_data = NULL; + PyObject *__pyx_v_json_file = NULL; + PyObject *__pyx_v_err = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + unsigned int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + int __pyx_t_12; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + int __pyx_t_18; + int __pyx_t_19; + PyObject *__pyx_t_20 = NULL; + PyObject *__pyx_t_21 = NULL; + int __pyx_t_22; + char const *__pyx_t_23; + PyObject *__pyx_t_24 = NULL; + char const *__pyx_t_25; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("translator", 1); + + /* "cython_code/my_translator.pyx":29 + * + * def translator(self): + * try: # <<<<<<<<<<<<<< + * if self.real: + * return GoogleTranslator(source='auto', target=self.lang).translate(self.text) + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "cython_code/my_translator.pyx":30 + * def translator(self): + * try: + * if self.real: # <<<<<<<<<<<<<< + * return GoogleTranslator(source='auto', target=self.lang).translate(self.text) + * try: + */ + if (__pyx_v_self->real) { + + /* "cython_code/my_translator.pyx":31 + * try: + * if self.real: + * return GoogleTranslator(source='auto', target=self.lang).translate(self.text) # <<<<<<<<<<<<<< + * try: + * return self.json_data[self.text][self.lang] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_GoogleTranslator); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 31, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 31, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_source, __pyx_n_u_auto) < 0) __PYX_ERR(0, 31, __pyx_L3_error) + if (PyDict_SetItem(__pyx_t_6, __pyx_n_s_target, __pyx_v_self->lang) < 0) __PYX_ERR(0, 31, __pyx_L3_error) + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_t_5, __pyx_empty_tuple, __pyx_t_6); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 31, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_translate); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 31, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_8 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_8 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_v_self->text}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 31, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __pyx_r = __pyx_t_4; + __pyx_t_4 = 0; + goto __pyx_L7_try_return; + + /* "cython_code/my_translator.pyx":30 + * def translator(self): + * try: + * if self.real: # <<<<<<<<<<<<<< + * return GoogleTranslator(source='auto', target=self.lang).translate(self.text) + * try: + */ + } + + /* "cython_code/my_translator.pyx":32 + * if self.real: + * return GoogleTranslator(source='auto', target=self.lang).translate(self.text) + * try: # <<<<<<<<<<<<<< + * return self.json_data[self.text][self.lang] + * except KeyError: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + /*try:*/ { + + /* "cython_code/my_translator.pyx":33 + * return GoogleTranslator(source='auto', target=self.lang).translate(self.text) + * try: + * return self.json_data[self.text][self.lang] # <<<<<<<<<<<<<< + * except KeyError: + * pass + */ + __Pyx_XDECREF(__pyx_r); + if (unlikely(__pyx_v_self->json_data == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 33, __pyx_L10_error) + } + __pyx_t_4 = __Pyx_PyDict_GetItem(__pyx_v_self->json_data, __pyx_v_self->text); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 33, __pyx_L10_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __Pyx_PyObject_Dict_GetItem(__pyx_t_4, __pyx_v_self->lang); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 33, __pyx_L10_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + goto __pyx_L14_try_return; + + /* "cython_code/my_translator.pyx":32 + * if self.real: + * return GoogleTranslator(source='auto', target=self.lang).translate(self.text) + * try: # <<<<<<<<<<<<<< + * return self.json_data[self.text][self.lang] + * except KeyError: + */ + } + __pyx_L10_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "cython_code/my_translator.pyx":34 + * try: + * return self.json_data[self.text][self.lang] + * except KeyError: # <<<<<<<<<<<<<< + * pass + * result = GoogleTranslator(source='auto', target=self.lang).translate(self.text) + */ + __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(__pyx_builtin_KeyError); + if (__pyx_t_12) { + __Pyx_ErrRestore(0,0,0); + goto __pyx_L11_exception_handled; + } + goto __pyx_L12_except_error; + + /* "cython_code/my_translator.pyx":32 + * if self.real: + * return GoogleTranslator(source='auto', target=self.lang).translate(self.text) + * try: # <<<<<<<<<<<<<< + * return self.json_data[self.text][self.lang] + * except KeyError: + */ + __pyx_L12_except_error:; + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11); + goto __pyx_L3_error; + __pyx_L14_try_return:; + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11); + goto __pyx_L7_try_return; + __pyx_L11_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11); + } + + /* "cython_code/my_translator.pyx":36 + * except KeyError: + * pass + * result = GoogleTranslator(source='auto', target=self.lang).translate(self.text) # <<<<<<<<<<<<<< + * data = { + * self.lang: result + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_GoogleTranslator); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 36, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_7 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 36, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_source, __pyx_n_u_auto) < 0) __PYX_ERR(0, 36, __pyx_L3_error) + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_target, __pyx_v_self->lang) < 0) __PYX_ERR(0, 36, __pyx_L3_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_empty_tuple, __pyx_t_7); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 36, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_translate); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 36, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + __pyx_t_8 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_7))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_7); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_7); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_7, function); + __pyx_t_8 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_5, __pyx_v_self->text}; + __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_7, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 36, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + } + __pyx_v_result = __pyx_t_6; + __pyx_t_6 = 0; + + /* "cython_code/my_translator.pyx":38 + * result = GoogleTranslator(source='auto', target=self.lang).translate(self.text) + * data = { + * self.lang: result # <<<<<<<<<<<<<< + * } + * try: + */ + __pyx_t_6 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 38, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_t_6, __pyx_v_self->lang, __pyx_v_result) < 0) __PYX_ERR(0, 38, __pyx_L3_error) + __pyx_v_data = ((PyObject*)__pyx_t_6); + __pyx_t_6 = 0; + + /* "cython_code/my_translator.pyx":40 + * self.lang: result + * } + * try: # <<<<<<<<<<<<<< + * self.json_data[self.text] = data + * with open(self.file_path, "w") as json_file: + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_9); + /*try:*/ { + + /* "cython_code/my_translator.pyx":41 + * } + * try: + * self.json_data[self.text] = data # <<<<<<<<<<<<<< + * with open(self.file_path, "w") as json_file: + * json.dump(self.json_data, json_file) + */ + if (unlikely(__pyx_v_self->json_data == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(0, 41, __pyx_L16_error) + } + if (unlikely((PyDict_SetItem(__pyx_v_self->json_data, __pyx_v_self->text, __pyx_v_data) < 0))) __PYX_ERR(0, 41, __pyx_L16_error) + + /* "cython_code/my_translator.pyx":42 + * try: + * self.json_data[self.text] = data + * with open(self.file_path, "w") as json_file: # <<<<<<<<<<<<<< + * json.dump(self.json_data, json_file) + * except Exception as err: + */ + /*with:*/ { + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 42, __pyx_L16_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_v_self->file_path); + __Pyx_GIVEREF(__pyx_v_self->file_path); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_v_self->file_path)) __PYX_ERR(0, 42, __pyx_L16_error); + __Pyx_INCREF(__pyx_n_u_w); + __Pyx_GIVEREF(__pyx_n_u_w); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_n_u_w)) __PYX_ERR(0, 42, __pyx_L16_error); + __pyx_t_7 = __Pyx_PyObject_Call(__pyx_builtin_open, __pyx_t_6, NULL); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 42, __pyx_L16_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_13 = __Pyx_PyObject_LookupSpecial(__pyx_t_7, __pyx_n_s_exit); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 42, __pyx_L16_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_5 = __Pyx_PyObject_LookupSpecial(__pyx_t_7, __pyx_n_s_enter); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 42, __pyx_L22_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = NULL; + __pyx_t_8 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_8 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL}; + __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_8, 0+__pyx_t_8); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 42, __pyx_L22_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __pyx_t_5 = __pyx_t_6; + __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + /*try:*/ { + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_16); + /*try:*/ { + __pyx_v_json_file = __pyx_t_5; + __pyx_t_5 = 0; + + /* "cython_code/my_translator.pyx":43 + * self.json_data[self.text] = data + * with open(self.file_path, "w") as json_file: + * json.dump(self.json_data, json_file) # <<<<<<<<<<<<<< + * except Exception as err: + * logging.error(err) + */ + __Pyx_GetModuleGlobalName(__pyx_t_7, __pyx_n_s_json); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 43, __pyx_L26_error) + __Pyx_GOTREF(__pyx_t_7); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_7, __pyx_n_s_dump); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 43, __pyx_L26_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + __pyx_t_7 = NULL; + __pyx_t_8 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_8 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[3] = {__pyx_t_7, __pyx_v_self->json_data, __pyx_v_json_file}; + __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_8, 2+__pyx_t_8); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 43, __pyx_L26_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "cython_code/my_translator.pyx":42 + * try: + * self.json_data[self.text] = data + * with open(self.file_path, "w") as json_file: # <<<<<<<<<<<<<< + * json.dump(self.json_data, json_file) + * except Exception as err: + */ + } + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + goto __pyx_L31_try_end; + __pyx_L26_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + /*except:*/ { + __Pyx_AddTraceback("cython_code.my_translator.MyTranslator.translator", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 42, __pyx_L28_except_error) + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + __pyx_t_4 = PyTuple_Pack(3, __pyx_t_5, __pyx_t_6, __pyx_t_7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 42, __pyx_L28_except_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_17 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_4, NULL); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_17)) __PYX_ERR(0, 42, __pyx_L28_except_error) + __Pyx_GOTREF(__pyx_t_17); + __pyx_t_18 = __Pyx_PyObject_IsTrue(__pyx_t_17); + __Pyx_DECREF(__pyx_t_17); __pyx_t_17 = 0; + if (__pyx_t_18 < 0) __PYX_ERR(0, 42, __pyx_L28_except_error) + __pyx_t_19 = (!__pyx_t_18); + if (unlikely(__pyx_t_19)) { + __Pyx_GIVEREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_ErrRestoreWithState(__pyx_t_5, __pyx_t_6, __pyx_t_7); + __pyx_t_5 = 0; __pyx_t_6 = 0; __pyx_t_7 = 0; + __PYX_ERR(0, 42, __pyx_L28_except_error) + } + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L27_exception_handled; + } + __pyx_L28_except_error:; + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16); + goto __pyx_L16_error; + __pyx_L27_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_15, __pyx_t_16); + __pyx_L31_try_end:; + } + } + /*finally:*/ { + /*normal exit:*/{ + if (__pyx_t_13) { + __pyx_t_16 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_tuple_, NULL); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_16)) __PYX_ERR(0, 42, __pyx_L16_error) + __Pyx_GOTREF(__pyx_t_16); + __Pyx_DECREF(__pyx_t_16); __pyx_t_16 = 0; + } + goto __pyx_L25; + } + __pyx_L25:; + } + goto __pyx_L35; + __pyx_L22_error:; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + goto __pyx_L16_error; + __pyx_L35:; + } + + /* "cython_code/my_translator.pyx":40 + * self.lang: result + * } + * try: # <<<<<<<<<<<<<< + * self.json_data[self.text] = data + * with open(self.file_path, "w") as json_file: + */ + } + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L21_try_end; + __pyx_L16_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "cython_code/my_translator.pyx":44 + * with open(self.file_path, "w") as json_file: + * json.dump(self.json_data, json_file) + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + * return result + */ + __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); + if (__pyx_t_12) { + __Pyx_AddTraceback("cython_code.my_translator.MyTranslator.translator", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_7, &__pyx_t_6, &__pyx_t_5) < 0) __PYX_ERR(0, 44, __pyx_L18_except_error) + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + __pyx_v_err = __pyx_t_6; + /*try:*/ { + + /* "cython_code/my_translator.pyx":45 + * json.dump(self.json_data, json_file) + * except Exception as err: + * logging.error(err) # <<<<<<<<<<<<<< + * return result + * except Exception as err: + */ + __Pyx_GetModuleGlobalName(__pyx_t_20, __pyx_n_s_logging); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 45, __pyx_L41_error) + __Pyx_GOTREF(__pyx_t_20); + __pyx_t_21 = __Pyx_PyObject_GetAttrStr(__pyx_t_20, __pyx_n_s_error); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 45, __pyx_L41_error) + __Pyx_GOTREF(__pyx_t_21); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + __pyx_t_20 = NULL; + __pyx_t_8 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_21))) { + __pyx_t_20 = PyMethod_GET_SELF(__pyx_t_21); + if (likely(__pyx_t_20)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_21); + __Pyx_INCREF(__pyx_t_20); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_21, function); + __pyx_t_8 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_20, __pyx_v_err}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_21, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8); + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 45, __pyx_L41_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + + /* "cython_code/my_translator.pyx":44 + * with open(self.file_path, "w") as json_file: + * json.dump(self.json_data, json_file) + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + * return result + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + goto __pyx_L42; + } + __pyx_L41_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_13 = 0; __pyx_t_16 = 0; __pyx_t_15 = 0; __pyx_t_14 = 0; __pyx_t_17 = 0; __pyx_t_24 = 0; + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_14, &__pyx_t_17, &__pyx_t_24); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_13, &__pyx_t_16, &__pyx_t_15) < 0)) __Pyx_ErrFetch(&__pyx_t_13, &__pyx_t_16, &__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_13); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_24); + __pyx_t_12 = __pyx_lineno; __pyx_t_22 = __pyx_clineno; __pyx_t_23 = __pyx_filename; + { + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_XGIVEREF(__pyx_t_24); + __Pyx_ExceptionReset(__pyx_t_14, __pyx_t_17, __pyx_t_24); + } + __Pyx_XGIVEREF(__pyx_t_13); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_ErrRestore(__pyx_t_13, __pyx_t_16, __pyx_t_15); + __pyx_t_13 = 0; __pyx_t_16 = 0; __pyx_t_15 = 0; __pyx_t_14 = 0; __pyx_t_17 = 0; __pyx_t_24 = 0; + __pyx_lineno = __pyx_t_12; __pyx_clineno = __pyx_t_22; __pyx_filename = __pyx_t_23; + goto __pyx_L18_except_error; + } + __pyx_L42:; + } + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L17_exception_handled; + } + goto __pyx_L18_except_error; + + /* "cython_code/my_translator.pyx":40 + * self.lang: result + * } + * try: # <<<<<<<<<<<<<< + * self.json_data[self.text] = data + * with open(self.file_path, "w") as json_file: + */ + __pyx_L18_except_error:; + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_10, __pyx_t_9); + goto __pyx_L3_error; + __pyx_L17_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_10, __pyx_t_9); + __pyx_L21_try_end:; + } + + /* "cython_code/my_translator.pyx":46 + * except Exception as err: + * logging.error(err) + * return result # <<<<<<<<<<<<<< + * except Exception as err: + * logging.error(err) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_result); + __pyx_r = __pyx_v_result; + goto __pyx_L7_try_return; + + /* "cython_code/my_translator.pyx":29 + * + * def translator(self): + * try: # <<<<<<<<<<<<<< + * if self.real: + * return GoogleTranslator(source='auto', target=self.lang).translate(self.text) + */ + } + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "cython_code/my_translator.pyx":47 + * logging.error(err) + * return result + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + * return self.text + */ + __pyx_t_22 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); + if (__pyx_t_22) { + __Pyx_AddTraceback("cython_code.my_translator.MyTranslator.translator", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_5, &__pyx_t_6, &__pyx_t_7) < 0) __PYX_ERR(0, 47, __pyx_L5_except_error) + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_INCREF(__pyx_t_6); + __Pyx_XDECREF_SET(__pyx_v_err, __pyx_t_6); + /*try:*/ { + + /* "cython_code/my_translator.pyx":48 + * return result + * except Exception as err: + * logging.error(err) # <<<<<<<<<<<<<< + * return self.text + */ + __Pyx_GetModuleGlobalName(__pyx_t_21, __pyx_n_s_logging); if (unlikely(!__pyx_t_21)) __PYX_ERR(0, 48, __pyx_L52_error) + __Pyx_GOTREF(__pyx_t_21); + __pyx_t_20 = __Pyx_PyObject_GetAttrStr(__pyx_t_21, __pyx_n_s_error); if (unlikely(!__pyx_t_20)) __PYX_ERR(0, 48, __pyx_L52_error) + __Pyx_GOTREF(__pyx_t_20); + __Pyx_DECREF(__pyx_t_21); __pyx_t_21 = 0; + __pyx_t_21 = NULL; + __pyx_t_8 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_20))) { + __pyx_t_21 = PyMethod_GET_SELF(__pyx_t_20); + if (likely(__pyx_t_21)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_20); + __Pyx_INCREF(__pyx_t_21); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_20, function); + __pyx_t_8 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_21, __pyx_v_err}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_20, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8); + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 48, __pyx_L52_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_20); __pyx_t_20 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "cython_code/my_translator.pyx":49 + * except Exception as err: + * logging.error(err) + * return self.text # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v_self->text); + __pyx_r = __pyx_v_self->text; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + goto __pyx_L51_return; + } + + /* "cython_code/my_translator.pyx":47 + * logging.error(err) + * return result + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + * return self.text + */ + /*finally:*/ { + __pyx_L52_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_24 = 0; __pyx_t_17 = 0; __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_24, &__pyx_t_17, &__pyx_t_14); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11) < 0)) __Pyx_ErrFetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_24); + __Pyx_XGOTREF(__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_14); + __pyx_t_22 = __pyx_lineno; __pyx_t_12 = __pyx_clineno; __pyx_t_25 = __pyx_filename; + { + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_24); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_ExceptionReset(__pyx_t_24, __pyx_t_17, __pyx_t_14); + } + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ErrRestore(__pyx_t_9, __pyx_t_10, __pyx_t_11); + __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_24 = 0; __pyx_t_17 = 0; __pyx_t_14 = 0; + __pyx_lineno = __pyx_t_22; __pyx_clineno = __pyx_t_12; __pyx_filename = __pyx_t_25; + goto __pyx_L5_except_error; + } + __pyx_L51_return: { + __pyx_t_14 = __pyx_r; + __pyx_r = 0; + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + __pyx_r = __pyx_t_14; + __pyx_t_14 = 0; + goto __pyx_L6_except_return; + } + } + } + goto __pyx_L5_except_error; + + /* "cython_code/my_translator.pyx":29 + * + * def translator(self): + * try: # <<<<<<<<<<<<<< + * if self.real: + * return GoogleTranslator(source='auto', target=self.lang).translate(self.text) + */ + __pyx_L5_except_error:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L7_try_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; + __pyx_L6_except_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; + } + + /* "cython_code/my_translator.pyx":28 + * self.json_data = json.load(json_file) + * + * def translator(self): # <<<<<<<<<<<<<< + * try: + * if self.real: + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_XDECREF(__pyx_t_20); + __Pyx_XDECREF(__pyx_t_21); + __Pyx_AddTraceback("cython_code.my_translator.MyTranslator.translator", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_data); + __Pyx_XDECREF(__pyx_v_json_file); + __Pyx_XDECREF(__pyx_v_err); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_13my_translator_12MyTranslator_5__reduce_cython__(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_13my_translator_12MyTranslator_5__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_13my_translator_12MyTranslator_5__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_13my_translator_12MyTranslator_5__reduce_cython__(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + if (unlikely(__pyx_nargs > 0)) { + __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;} + if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL; + __pyx_r = __pyx_pf_11cython_code_13my_translator_12MyTranslator_4__reduce_cython__(((struct __pyx_obj_11cython_code_13my_translator_MyTranslator *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_13my_translator_12MyTranslator_4__reduce_cython__(struct __pyx_obj_11cython_code_13my_translator_MyTranslator *__pyx_v_self) { + PyObject *__pyx_v_state = 0; + PyObject *__pyx_v__dict = 0; + int __pyx_v_use_setstate; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + int __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__reduce_cython__", 1); + + /* "(tree fragment)":5 + * cdef object _dict + * cdef bint use_setstate + * state = (self.file_path, self.json_data, self.lang, self.real, self.text) # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + */ + __pyx_t_1 = __Pyx_PyBool_FromLong(__pyx_v_self->real); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(5); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v_self->file_path); + __Pyx_GIVEREF(__pyx_v_self->file_path); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v_self->file_path)) __PYX_ERR(1, 5, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_self->json_data); + __Pyx_GIVEREF(__pyx_v_self->json_data); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_v_self->json_data)) __PYX_ERR(1, 5, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_self->lang); + __Pyx_GIVEREF(__pyx_v_self->lang); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_self->lang)) __PYX_ERR(1, 5, __pyx_L1_error); + __Pyx_GIVEREF(__pyx_t_1); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 3, __pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_self->text); + __Pyx_GIVEREF(__pyx_v_self->text); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 4, __pyx_v_self->text)) __PYX_ERR(1, 5, __pyx_L1_error); + __pyx_t_1 = 0; + __pyx_v_state = ((PyObject*)__pyx_t_2); + __pyx_t_2 = 0; + + /* "(tree fragment)":6 + * cdef bint use_setstate + * state = (self.file_path, self.json_data, self.lang, self.real, self.text) + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) + */ + __pyx_t_2 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_v__dict = __pyx_t_2; + __pyx_t_2 = 0; + + /* "(tree fragment)":7 + * state = (self.file_path, self.json_data, self.lang, self.real, self.text) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + __pyx_t_3 = (__pyx_v__dict != Py_None); + if (__pyx_t_3) { + + /* "(tree fragment)":8 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True + * else: + */ + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_v__dict)) __PYX_ERR(1, 8, __pyx_L1_error); + __pyx_t_1 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_1)); + __pyx_t_1 = 0; + + /* "(tree fragment)":9 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< + * else: + * use_setstate = self.file_path is not None or self.json_data is not None or self.lang is not None or self.text is not None + */ + __pyx_v_use_setstate = 1; + + /* "(tree fragment)":7 + * state = (self.file_path, self.json_data, self.lang, self.real, self.text) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + goto __pyx_L3; + } + + /* "(tree fragment)":11 + * use_setstate = True + * else: + * use_setstate = self.file_path is not None or self.json_data is not None or self.lang is not None or self.text is not None # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle_MyTranslator, (type(self), 0xaa02da6, None), state + */ + /*else*/ { + __pyx_t_4 = (__pyx_v_self->file_path != ((PyObject*)Py_None)); + if (!__pyx_t_4) { + } else { + __pyx_t_3 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = (__pyx_v_self->json_data != ((PyObject*)Py_None)); + if (!__pyx_t_4) { + } else { + __pyx_t_3 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = (__pyx_v_self->lang != ((PyObject*)Py_None)); + if (!__pyx_t_4) { + } else { + __pyx_t_3 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = (__pyx_v_self->text != ((PyObject*)Py_None)); + __pyx_t_3 = __pyx_t_4; + __pyx_L4_bool_binop_done:; + __pyx_v_use_setstate = __pyx_t_3; + } + __pyx_L3:; + + /* "(tree fragment)":12 + * else: + * use_setstate = self.file_path is not None or self.json_data is not None or self.lang is not None or self.text is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_MyTranslator, (type(self), 0xaa02da6, None), state + * else: + */ + if (__pyx_v_use_setstate) { + + /* "(tree fragment)":13 + * use_setstate = self.file_path is not None or self.json_data is not None or self.lang is not None or self.text is not None + * if use_setstate: + * return __pyx_unpickle_MyTranslator, (type(self), 0xaa02da6, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle_MyTranslator, (type(self), 0xaa02da6, state) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_pyx_unpickle_MyTranslator); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))))) __PYX_ERR(1, 13, __pyx_L1_error); + __Pyx_INCREF(__pyx_int_178269606); + __Pyx_GIVEREF(__pyx_int_178269606); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_178269606)) __PYX_ERR(1, 13, __pyx_L1_error); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 2, Py_None)) __PYX_ERR(1, 13, __pyx_L1_error); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_1); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error); + __Pyx_GIVEREF(__pyx_t_2); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_2)) __PYX_ERR(1, 13, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state)) __PYX_ERR(1, 13, __pyx_L1_error); + __pyx_t_1 = 0; + __pyx_t_2 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "(tree fragment)":12 + * else: + * use_setstate = self.file_path is not None or self.json_data is not None or self.lang is not None or self.text is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_MyTranslator, (type(self), 0xaa02da6, None), state + * else: + */ + } + + /* "(tree fragment)":15 + * return __pyx_unpickle_MyTranslator, (type(self), 0xaa02da6, None), state + * else: + * return __pyx_unpickle_MyTranslator, (type(self), 0xaa02da6, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_MyTranslator__set_state(self, __pyx_state) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pyx_unpickle_MyTranslator); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_2 = PyTuple_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))))) __PYX_ERR(1, 15, __pyx_L1_error); + __Pyx_INCREF(__pyx_int_178269606); + __Pyx_GIVEREF(__pyx_int_178269606); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 1, __pyx_int_178269606)) __PYX_ERR(1, 15, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 2, __pyx_v_state)) __PYX_ERR(1, 15, __pyx_L1_error); + __pyx_t_1 = PyTuple_New(2); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_5); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_t_5)) __PYX_ERR(1, 15, __pyx_L1_error); + __Pyx_GIVEREF(__pyx_t_2); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_2)) __PYX_ERR(1, 15, __pyx_L1_error); + __pyx_t_5 = 0; + __pyx_t_2 = 0; + __pyx_r = __pyx_t_1; + __pyx_t_1 = 0; + goto __pyx_L0; + } + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("cython_code.my_translator.MyTranslator.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":16 + * else: + * return __pyx_unpickle_MyTranslator, (type(self), 0xaa02da6, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_MyTranslator__set_state(self, __pyx_state) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_13my_translator_12MyTranslator_7__setstate_cython__(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_13my_translator_12MyTranslator_7__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_13my_translator_12MyTranslator_7__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_13my_translator_12MyTranslator_7__setstate_cython__(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + PyObject *__pyx_v___pyx_state = 0; + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[1] = {0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 16, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(1, 16, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 1)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + } + __pyx_v___pyx_state = values[0]; + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(1, 16, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.my_translator.MyTranslator.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_11cython_code_13my_translator_12MyTranslator_6__setstate_cython__(((struct __pyx_obj_11cython_code_13my_translator_MyTranslator *)__pyx_v_self), __pyx_v___pyx_state); + + /* function exit code */ + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_13my_translator_12MyTranslator_6__setstate_cython__(struct __pyx_obj_11cython_code_13my_translator_MyTranslator *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__setstate_cython__", 1); + + /* "(tree fragment)":17 + * return __pyx_unpickle_MyTranslator, (type(self), 0xaa02da6, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_MyTranslator__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None) || __Pyx_RaiseUnexpectedTypeError("tuple", __pyx_v___pyx_state))) __PYX_ERR(1, 17, __pyx_L1_error) + __pyx_t_1 = __pyx_f_11cython_code_13my_translator___pyx_unpickle_MyTranslator__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":16 + * else: + * return __pyx_unpickle_MyTranslator, (type(self), 0xaa02da6, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_MyTranslator__set_state(self, __pyx_state) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("cython_code.my_translator.MyTranslator.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __pyx_unpickle_MyTranslator(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_13my_translator_1__pyx_unpickle_MyTranslator(PyObject *__pyx_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_13my_translator_1__pyx_unpickle_MyTranslator = {"__pyx_unpickle_MyTranslator", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_13my_translator_1__pyx_unpickle_MyTranslator, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_13my_translator_1__pyx_unpickle_MyTranslator(PyObject *__pyx_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + PyObject *__pyx_v___pyx_type = 0; + long __pyx_v___pyx_checksum; + PyObject *__pyx_v___pyx_state = 0; + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[3] = {0,0,0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__pyx_unpickle_MyTranslator (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_type)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_checksum)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[1]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_MyTranslator", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[2]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_MyTranslator", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__pyx_unpickle_MyTranslator") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 3)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); + } + __pyx_v___pyx_type = values[0]; + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_state = values[2]; + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_MyTranslator", 1, 3, 3, __pyx_nargs); __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.my_translator.__pyx_unpickle_MyTranslator", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_11cython_code_13my_translator___pyx_unpickle_MyTranslator(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + + /* function exit code */ + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_13my_translator___pyx_unpickle_MyTranslator(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_v___pyx_PickleError = 0; + PyObject *__pyx_v___pyx_result = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + unsigned int __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__pyx_unpickle_MyTranslator", 1); + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum not in (0xaa02da6, 0x1c6bc4b, 0x57a17a8): # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xaa02da6, 0x1c6bc4b, 0x57a17a8) = (file_path, json_data, lang, real, text))" % __pyx_checksum + */ + __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_t_1, __pyx_tuple__3, Py_NE)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "(tree fragment)":5 + * cdef object __pyx_result + * if __pyx_checksum not in (0xaa02da6, 0x1c6bc4b, 0x57a17a8): + * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< + * raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xaa02da6, 0x1c6bc4b, 0x57a17a8) = (file_path, json_data, lang, real, text))" % __pyx_checksum + * __pyx_result = MyTranslator.__new__(__pyx_type) + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_PickleError); + __Pyx_GIVEREF(__pyx_n_s_PickleError); + if (__Pyx_PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_PickleError)) __PYX_ERR(1, 5, __pyx_L1_error); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_1); + __pyx_v___pyx_PickleError = __pyx_t_1; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":6 + * if __pyx_checksum not in (0xaa02da6, 0x1c6bc4b, 0x57a17a8): + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xaa02da6, 0x1c6bc4b, 0x57a17a8) = (file_path, json_data, lang, real, text))" % __pyx_checksum # <<<<<<<<<<<<<< + * __pyx_result = MyTranslator.__new__(__pyx_type) + * if __pyx_state is not None: + */ + __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_0x_x_vs_0, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_v___pyx_PickleError, __pyx_t_1, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 6, __pyx_L1_error) + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum not in (0xaa02da6, 0x1c6bc4b, 0x57a17a8): # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xaa02da6, 0x1c6bc4b, 0x57a17a8) = (file_path, json_data, lang, real, text))" % __pyx_checksum + */ + } + + /* "(tree fragment)":7 + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xaa02da6, 0x1c6bc4b, 0x57a17a8) = (file_path, json_data, lang, real, text))" % __pyx_checksum + * __pyx_result = MyTranslator.__new__(__pyx_type) # <<<<<<<<<<<<<< + * if __pyx_state is not None: + * __pyx_unpickle_MyTranslator__set_state( __pyx_result, __pyx_state) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_11cython_code_13my_translator_MyTranslator), __pyx_n_s_new); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + __pyx_t_5 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_5 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v___pyx_type}; + __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_v___pyx_result = __pyx_t_1; + __pyx_t_1 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xaa02da6, 0x1c6bc4b, 0x57a17a8) = (file_path, json_data, lang, real, text))" % __pyx_checksum + * __pyx_result = MyTranslator.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_MyTranslator__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + __pyx_t_2 = (__pyx_v___pyx_state != Py_None); + if (__pyx_t_2) { + + /* "(tree fragment)":9 + * __pyx_result = MyTranslator.__new__(__pyx_type) + * if __pyx_state is not None: + * __pyx_unpickle_MyTranslator__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * return __pyx_result + * cdef __pyx_unpickle_MyTranslator__set_state(MyTranslator __pyx_result, tuple __pyx_state): + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None) || __Pyx_RaiseUnexpectedTypeError("tuple", __pyx_v___pyx_state))) __PYX_ERR(1, 9, __pyx_L1_error) + __pyx_t_1 = __pyx_f_11cython_code_13my_translator___pyx_unpickle_MyTranslator__set_state(((struct __pyx_obj_11cython_code_13my_translator_MyTranslator *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xaa02da6, 0x1c6bc4b, 0x57a17a8) = (file_path, json_data, lang, real, text))" % __pyx_checksum + * __pyx_result = MyTranslator.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_MyTranslator__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + } + + /* "(tree fragment)":10 + * if __pyx_state is not None: + * __pyx_unpickle_MyTranslator__set_state( __pyx_result, __pyx_state) + * return __pyx_result # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_MyTranslator__set_state(MyTranslator __pyx_result, tuple __pyx_state): + * __pyx_result.file_path = __pyx_state[0]; __pyx_result.json_data = __pyx_state[1]; __pyx_result.lang = __pyx_state[2]; __pyx_result.real = __pyx_state[3]; __pyx_result.text = __pyx_state[4] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v___pyx_result); + __pyx_r = __pyx_v___pyx_result; + goto __pyx_L0; + + /* "(tree fragment)":1 + * def __pyx_unpickle_MyTranslator(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("cython_code.my_translator.__pyx_unpickle_MyTranslator", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v___pyx_PickleError); + __Pyx_XDECREF(__pyx_v___pyx_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":11 + * __pyx_unpickle_MyTranslator__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_MyTranslator__set_state(MyTranslator __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.file_path = __pyx_state[0]; __pyx_result.json_data = __pyx_state[1]; __pyx_result.lang = __pyx_state[2]; __pyx_result.real = __pyx_state[3]; __pyx_result.text = __pyx_state[4] + * if len(__pyx_state) > 5 and hasattr(__pyx_result, '__dict__'): + */ + +static PyObject *__pyx_f_11cython_code_13my_translator___pyx_unpickle_MyTranslator__set_state(struct __pyx_obj_11cython_code_13my_translator_MyTranslator *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + unsigned int __pyx_t_8; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__pyx_unpickle_MyTranslator__set_state", 1); + + /* "(tree fragment)":12 + * return __pyx_result + * cdef __pyx_unpickle_MyTranslator__set_state(MyTranslator __pyx_result, tuple __pyx_state): + * __pyx_result.file_path = __pyx_state[0]; __pyx_result.json_data = __pyx_state[1]; __pyx_result.lang = __pyx_state[2]; __pyx_result.real = __pyx_state[3]; __pyx_result.text = __pyx_state[4] # <<<<<<<<<<<<<< + * if len(__pyx_state) > 5 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[5]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("unicode", __pyx_t_1))) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->file_path); + __Pyx_DECREF(__pyx_v___pyx_result->file_path); + __pyx_v___pyx_result->file_path = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyDict_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("dict", __pyx_t_1))) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->json_data); + __Pyx_DECREF(__pyx_v___pyx_result->json_data); + __pyx_v___pyx_result->json_data = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("unicode", __pyx_t_1))) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->lang); + __Pyx_DECREF(__pyx_v___pyx_result->lang); + __pyx_v___pyx_result->lang = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 == (int)-1) && PyErr_Occurred())) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v___pyx_result->real = __pyx_t_2; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("unicode", __pyx_t_1))) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->text); + __Pyx_DECREF(__pyx_v___pyx_result->text); + __pyx_v___pyx_result->text = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_MyTranslator__set_state(MyTranslator __pyx_result, tuple __pyx_state): + * __pyx_result.file_path = __pyx_state[0]; __pyx_result.json_data = __pyx_state[1]; __pyx_result.lang = __pyx_state[2]; __pyx_result.real = __pyx_state[3]; __pyx_result.text = __pyx_state[4] + * if len(__pyx_state) > 5 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[5]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(1, 13, __pyx_L1_error) + } + __pyx_t_3 = __Pyx_PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_4 = (__pyx_t_3 > 5); + if (__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_2 = __pyx_t_4; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { + + /* "(tree fragment)":14 + * __pyx_result.file_path = __pyx_state[0]; __pyx_result.json_data = __pyx_state[1]; __pyx_result.lang = __pyx_state[2]; __pyx_result.real = __pyx_state[3]; __pyx_result.text = __pyx_state[4] + * if len(__pyx_state) > 5 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[5]) # <<<<<<<<<<<<<< + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_update); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 14, __pyx_L1_error) + } + __pyx_t_5 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = NULL; + __pyx_t_8 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_8 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_t_5}; + __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_MyTranslator__set_state(MyTranslator __pyx_result, tuple __pyx_state): + * __pyx_result.file_path = __pyx_state[0]; __pyx_result.json_data = __pyx_state[1]; __pyx_result.lang = __pyx_state[2]; __pyx_result.real = __pyx_state[3]; __pyx_result.text = __pyx_state[4] + * if len(__pyx_state) > 5 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[5]) + */ + } + + /* "(tree fragment)":11 + * __pyx_unpickle_MyTranslator__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_MyTranslator__set_state(MyTranslator __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.file_path = __pyx_state[0]; __pyx_result.json_data = __pyx_state[1]; __pyx_result.lang = __pyx_state[2]; __pyx_result.real = __pyx_state[3]; __pyx_result.text = __pyx_state[4] + * if len(__pyx_state) > 5 and hasattr(__pyx_result, '__dict__'): + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("cython_code.my_translator.__pyx_unpickle_MyTranslator__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_tp_new_11cython_code_13my_translator_MyTranslator(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_11cython_code_13my_translator_MyTranslator *p; + PyObject *o; + #if CYTHON_COMPILING_IN_LIMITED_API + allocfunc alloc_func = (allocfunc)PyType_GetSlot(t, Py_tp_alloc); + o = alloc_func(t, 0); + #else + if (likely(!__Pyx_PyType_HasFeature(t, Py_TPFLAGS_IS_ABSTRACT))) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + #endif + p = ((struct __pyx_obj_11cython_code_13my_translator_MyTranslator *)o); + p->file_path = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->text = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->lang = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->json_data = ((PyObject*)Py_None); Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_11cython_code_13my_translator_MyTranslator(PyObject *o) { + struct __pyx_obj_11cython_code_13my_translator_MyTranslator *p = (struct __pyx_obj_11cython_code_13my_translator_MyTranslator *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && !__Pyx_PyObject_GC_IsFinalized(o)) { + if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_11cython_code_13my_translator_MyTranslator) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->file_path); + Py_CLEAR(p->text); + Py_CLEAR(p->lang); + Py_CLEAR(p->json_data); + #if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY + (*Py_TYPE(o)->tp_free)(o); + #else + { + freefunc tp_free = (freefunc)PyType_GetSlot(Py_TYPE(o), Py_tp_free); + if (tp_free) tp_free(o); + } + #endif +} + +static int __pyx_tp_traverse_11cython_code_13my_translator_MyTranslator(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_11cython_code_13my_translator_MyTranslator *p = (struct __pyx_obj_11cython_code_13my_translator_MyTranslator *)o; + if (p->json_data) { + e = (*v)(p->json_data, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_11cython_code_13my_translator_MyTranslator(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_11cython_code_13my_translator_MyTranslator *p = (struct __pyx_obj_11cython_code_13my_translator_MyTranslator *)o; + tmp = ((PyObject*)p->json_data); + p->json_data = ((PyObject*)Py_None); Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_11cython_code_13my_translator_MyTranslator[] = { + {"translator", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_13my_translator_12MyTranslator_3translator, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_13my_translator_12MyTranslator_5__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_13my_translator_12MyTranslator_7__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {0, 0, 0, 0} +}; +#if CYTHON_USE_TYPE_SPECS +static PyType_Slot __pyx_type_11cython_code_13my_translator_MyTranslator_slots[] = { + {Py_tp_dealloc, (void *)__pyx_tp_dealloc_11cython_code_13my_translator_MyTranslator}, + {Py_tp_traverse, (void *)__pyx_tp_traverse_11cython_code_13my_translator_MyTranslator}, + {Py_tp_clear, (void *)__pyx_tp_clear_11cython_code_13my_translator_MyTranslator}, + {Py_tp_methods, (void *)__pyx_methods_11cython_code_13my_translator_MyTranslator}, + {Py_tp_init, (void *)__pyx_pw_11cython_code_13my_translator_12MyTranslator_1__init__}, + {Py_tp_new, (void *)__pyx_tp_new_11cython_code_13my_translator_MyTranslator}, + {0, 0}, +}; +static PyType_Spec __pyx_type_11cython_code_13my_translator_MyTranslator_spec = { + "cython_code.my_translator.MyTranslator", + sizeof(struct __pyx_obj_11cython_code_13my_translator_MyTranslator), + 0, + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, + __pyx_type_11cython_code_13my_translator_MyTranslator_slots, +}; +#else + +static PyTypeObject __pyx_type_11cython_code_13my_translator_MyTranslator = { + PyVarObject_HEAD_INIT(0, 0) + "cython_code.my_translator.""MyTranslator", /*tp_name*/ + sizeof(struct __pyx_obj_11cython_code_13my_translator_MyTranslator), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_11cython_code_13my_translator_MyTranslator, /*tp_dealloc*/ + #if PY_VERSION_HEX < 0x030800b4 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 + 0, /*tp_vectorcall_offset*/ + #endif + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_11cython_code_13my_translator_MyTranslator, /*tp_traverse*/ + __pyx_tp_clear_11cython_code_13my_translator_MyTranslator, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_11cython_code_13my_translator_MyTranslator, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + #if !CYTHON_USE_TYPE_SPECS + 0, /*tp_dictoffset*/ + #endif + __pyx_pw_11cython_code_13my_translator_12MyTranslator_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_11cython_code_13my_translator_MyTranslator, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + #if CYTHON_USE_TP_FINALIZE + 0, /*tp_finalize*/ + #else + NULL, /*tp_finalize*/ + #endif + #endif + #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) + 0, /*tp_vectorcall*/ + #endif + #if __PYX_NEED_TP_PRINT_SLOT == 1 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030C0000 + 0, /*tp_watched*/ + #endif + #if PY_VERSION_HEX >= 0x030d00A4 + 0, /*tp_versions_used*/ + #endif + #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 + 0, /*tp_pypy_flags*/ + #endif +}; +#endif + +static PyMethodDef __pyx_methods[] = { + {0, 0, 0, 0} +}; +#ifndef CYTHON_SMALL_CODE +#if defined(__clang__) + #define CYTHON_SMALL_CODE +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) + #define CYTHON_SMALL_CODE __attribute__((cold)) +#else + #define CYTHON_SMALL_CODE +#endif +#endif +/* #### Code section: pystring_table ### */ + +static int __Pyx_CreateStringTabAndInitStrings(void) { + __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_n_s_FileNotFoundError, __pyx_k_FileNotFoundError, sizeof(__pyx_k_FileNotFoundError), 0, 0, 1, 1}, + {&__pyx_n_s_GoogleTranslator, __pyx_k_GoogleTranslator, sizeof(__pyx_k_GoogleTranslator), 0, 0, 1, 1}, + {&__pyx_kp_s_Incompatible_checksums_0x_x_vs_0, __pyx_k_Incompatible_checksums_0x_x_vs_0, sizeof(__pyx_k_Incompatible_checksums_0x_x_vs_0), 0, 0, 1, 0}, + {&__pyx_n_s_JSONDecodeError, __pyx_k_JSONDecodeError, sizeof(__pyx_k_JSONDecodeError), 0, 0, 1, 1}, + {&__pyx_n_s_KeyError, __pyx_k_KeyError, sizeof(__pyx_k_KeyError), 0, 0, 1, 1}, + {&__pyx_n_s_MyTranslator, __pyx_k_MyTranslator, sizeof(__pyx_k_MyTranslator), 0, 0, 1, 1}, + {&__pyx_n_s_MyTranslator___reduce_cython, __pyx_k_MyTranslator___reduce_cython, sizeof(__pyx_k_MyTranslator___reduce_cython), 0, 0, 1, 1}, + {&__pyx_n_s_MyTranslator___setstate_cython, __pyx_k_MyTranslator___setstate_cython, sizeof(__pyx_k_MyTranslator___setstate_cython), 0, 0, 1, 1}, + {&__pyx_n_s_MyTranslator_translator, __pyx_k_MyTranslator_translator, sizeof(__pyx_k_MyTranslator_translator), 0, 0, 1, 1}, + {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1}, + {&__pyx_n_s__14, __pyx_k__14, sizeof(__pyx_k__14), 0, 0, 1, 1}, + {&__pyx_kp_u__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 1, 0, 0}, + {&__pyx_kp_u__4, __pyx_k__4, sizeof(__pyx_k__4), 0, 1, 0, 0}, + {&__pyx_n_s__5, __pyx_k__5, sizeof(__pyx_k__5), 0, 0, 1, 1}, + {&__pyx_n_s_asyncio_coroutines, __pyx_k_asyncio_coroutines, sizeof(__pyx_k_asyncio_coroutines), 0, 0, 1, 1}, + {&__pyx_n_u_auto, __pyx_k_auto, sizeof(__pyx_k_auto), 0, 1, 0, 1}, + {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, + {&__pyx_n_s_cython_code_my_translator, __pyx_k_cython_code_my_translator, sizeof(__pyx_k_cython_code_my_translator), 0, 0, 1, 1}, + {&__pyx_kp_s_cython_code_my_translator_pyx, __pyx_k_cython_code_my_translator_pyx, sizeof(__pyx_k_cython_code_my_translator_pyx), 0, 0, 1, 0}, + {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1}, + {&__pyx_n_s_data_config, __pyx_k_data_config, sizeof(__pyx_k_data_config), 0, 0, 1, 1}, + {&__pyx_n_u_date, __pyx_k_date, sizeof(__pyx_k_date), 0, 1, 0, 1}, + {&__pyx_n_s_deep_translator, __pyx_k_deep_translator, sizeof(__pyx_k_deep_translator), 0, 0, 1, 1}, + {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1}, + {&__pyx_n_s_dict_2, __pyx_k_dict_2, sizeof(__pyx_k_dict_2), 0, 0, 1, 1}, + {&__pyx_kp_u_disable, __pyx_k_disable, sizeof(__pyx_k_disable), 0, 1, 0, 0}, + {&__pyx_n_s_dump, __pyx_k_dump, sizeof(__pyx_k_dump), 0, 0, 1, 1}, + {&__pyx_kp_u_enable, __pyx_k_enable, sizeof(__pyx_k_enable), 0, 1, 0, 0}, + {&__pyx_n_s_enter, __pyx_k_enter, sizeof(__pyx_k_enter), 0, 0, 1, 1}, + {&__pyx_n_s_err, __pyx_k_err, sizeof(__pyx_k_err), 0, 0, 1, 1}, + {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1}, + {&__pyx_n_s_exit, __pyx_k_exit, sizeof(__pyx_k_exit), 0, 0, 1, 1}, + {&__pyx_n_s_file_path, __pyx_k_file_path, sizeof(__pyx_k_file_path), 0, 0, 1, 1}, + {&__pyx_kp_u_gc, __pyx_k_gc, sizeof(__pyx_k_gc), 0, 1, 0, 0}, + {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, + {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, + {&__pyx_n_s_initializing, __pyx_k_initializing, sizeof(__pyx_k_initializing), 0, 0, 1, 1}, + {&__pyx_n_s_is_coroutine, __pyx_k_is_coroutine, sizeof(__pyx_k_is_coroutine), 0, 0, 1, 1}, + {&__pyx_kp_u_isenabled, __pyx_k_isenabled, sizeof(__pyx_k_isenabled), 0, 1, 0, 0}, + {&__pyx_n_s_json, __pyx_k_json, sizeof(__pyx_k_json), 0, 0, 1, 1}, + {&__pyx_n_s_json_file, __pyx_k_json_file, sizeof(__pyx_k_json_file), 0, 0, 1, 1}, + {&__pyx_n_s_lang, __pyx_k_lang, sizeof(__pyx_k_lang), 0, 0, 1, 1}, + {&__pyx_n_s_load, __pyx_k_load, sizeof(__pyx_k_load), 0, 0, 1, 1}, + {&__pyx_n_s_logging, __pyx_k_logging, sizeof(__pyx_k_logging), 0, 0, 1, 1}, + {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, + {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1}, + {&__pyx_n_s_open, __pyx_k_open, sizeof(__pyx_k_open), 0, 0, 1, 1}, + {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_unpickle_MyTranslator, __pyx_k_pyx_unpickle_MyTranslator, sizeof(__pyx_k_pyx_unpickle_MyTranslator), 0, 0, 1, 1}, + {&__pyx_n_u_r, __pyx_k_r, sizeof(__pyx_k_r), 0, 1, 0, 1}, + {&__pyx_n_s_real, __pyx_k_real, sizeof(__pyx_k_real), 0, 0, 1, 1}, + {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1}, + {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, + {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, + {&__pyx_n_s_result, __pyx_k_result, sizeof(__pyx_k_result), 0, 0, 1, 1}, + {&__pyx_n_s_self, __pyx_k_self, sizeof(__pyx_k_self), 0, 0, 1, 1}, + {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1}, + {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1}, + {&__pyx_n_s_soat_minut_sekund, __pyx_k_soat_minut_sekund, sizeof(__pyx_k_soat_minut_sekund), 0, 0, 1, 1}, + {&__pyx_n_s_source, __pyx_k_source, sizeof(__pyx_k_source), 0, 0, 1, 1}, + {&__pyx_n_s_spec, __pyx_k_spec, sizeof(__pyx_k_spec), 0, 0, 1, 1}, + {&__pyx_n_s_state, __pyx_k_state, sizeof(__pyx_k_state), 0, 0, 1, 1}, + {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0}, + {&__pyx_n_s_target, __pyx_k_target, sizeof(__pyx_k_target), 0, 0, 1, 1}, + {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {&__pyx_n_s_text, __pyx_k_text, sizeof(__pyx_k_text), 0, 0, 1, 1}, + {&__pyx_n_s_translate, __pyx_k_translate, sizeof(__pyx_k_translate), 0, 0, 1, 1}, + {&__pyx_n_s_translator, __pyx_k_translator, sizeof(__pyx_k_translator), 0, 0, 1, 1}, + {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1}, + {&__pyx_n_s_use_setstate, __pyx_k_use_setstate, sizeof(__pyx_k_use_setstate), 0, 0, 1, 1}, + {&__pyx_n_u_w, __pyx_k_w, sizeof(__pyx_k_w), 0, 1, 0, 1}, + {&__pyx_n_s_yil_oy_kun, __pyx_k_yil_oy_kun, sizeof(__pyx_k_yil_oy_kun), 0, 0, 1, 1}, + {0, 0, 0, 0, 0, 0, 0} + }; + return __Pyx_InitStrings(__pyx_string_tab); +} +/* #### Code section: cached_builtins ### */ +static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { + __pyx_builtin_open = __Pyx_GetBuiltinName(__pyx_n_s_open); if (!__pyx_builtin_open) __PYX_ERR(0, 19, __pyx_L1_error) + __pyx_builtin_KeyError = __Pyx_GetBuiltinName(__pyx_n_s_KeyError); if (!__pyx_builtin_KeyError) __PYX_ERR(0, 34, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} +/* #### Code section: cached_constants ### */ + +static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "cython_code/my_translator.pyx":19 + * self.real = real + * try: + * with open(self.file_path, "r") as json_file: # <<<<<<<<<<<<<< + * self.json_data = json.load(json_file) + * except (FileNotFoundError, json.JSONDecodeError): + */ + __pyx_tuple_ = PyTuple_Pack(3, Py_None, Py_None, Py_None); if (unlikely(!__pyx_tuple_)) __PYX_ERR(0, 19, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple_); + __Pyx_GIVEREF(__pyx_tuple_); + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum not in (0xaa02da6, 0x1c6bc4b, 0x57a17a8): # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xaa02da6, 0x1c6bc4b, 0x57a17a8) = (file_path, json_data, lang, real, text))" % __pyx_checksum + */ + __pyx_tuple__3 = PyTuple_Pack(3, __pyx_int_178269606, __pyx_int_29801547, __pyx_int_91887528); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__3); + __Pyx_GIVEREF(__pyx_tuple__3); + + /* "cython_code/my_translator.pyx":28 + * self.json_data = json.load(json_file) + * + * def translator(self): # <<<<<<<<<<<<<< + * try: + * if self.real: + */ + __pyx_tuple__6 = PyTuple_Pack(5, __pyx_n_s_self, __pyx_n_s_result, __pyx_n_s_data, __pyx_n_s_json_file, __pyx_n_s_err); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 28, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__6); + __Pyx_GIVEREF(__pyx_tuple__6); + __pyx_codeobj__7 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__6, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cython_code_my_translator_pyx, __pyx_n_s_translator, 28, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__7)) __PYX_ERR(0, 28, __pyx_L1_error) + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + __pyx_tuple__8 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_state, __pyx_n_s_dict_2, __pyx_n_s_use_setstate); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__8); + __Pyx_GIVEREF(__pyx_tuple__8); + __pyx_codeobj__9 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__8, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__9)) __PYX_ERR(1, 1, __pyx_L1_error) + + /* "(tree fragment)":16 + * else: + * return __pyx_unpickle_MyTranslator, (type(self), 0xaa02da6, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_MyTranslator__set_state(self, __pyx_state) + */ + __pyx_tuple__10 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_pyx_state); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(1, 16, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__10); + __Pyx_GIVEREF(__pyx_tuple__10); + __pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 16, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(1, 16, __pyx_L1_error) + + /* "(tree fragment)":1 + * def __pyx_unpickle_MyTranslator(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + __pyx_tuple__12 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__12); + __Pyx_GIVEREF(__pyx_tuple__12); + __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__12, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_MyTranslator, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} +/* #### Code section: init_constants ### */ + +static CYTHON_SMALL_CODE int __Pyx_InitConstants(void) { + if (__Pyx_CreateStringTabAndInitStrings() < 0) __PYX_ERR(0, 1, __pyx_L1_error); + __pyx_int_29801547 = PyInt_FromLong(29801547L); if (unlikely(!__pyx_int_29801547)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_91887528 = PyInt_FromLong(91887528L); if (unlikely(!__pyx_int_91887528)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_178269606 = PyInt_FromLong(178269606L); if (unlikely(!__pyx_int_178269606)) __PYX_ERR(0, 1, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} +/* #### Code section: init_globals ### */ + +static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { + return 0; +} +/* #### Code section: init_module ### */ + +static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/ + +static int __Pyx_modinit_global_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); + /*--- Global init code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); + /*--- Variable export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); + /*--- Function export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_type_init_code(void) { + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); + /*--- Type init code ---*/ + #if CYTHON_USE_TYPE_SPECS + __pyx_ptype_11cython_code_13my_translator_MyTranslator = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_11cython_code_13my_translator_MyTranslator_spec, NULL); if (unlikely(!__pyx_ptype_11cython_code_13my_translator_MyTranslator)) __PYX_ERR(0, 6, __pyx_L1_error) + if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_11cython_code_13my_translator_MyTranslator_spec, __pyx_ptype_11cython_code_13my_translator_MyTranslator) < 0) __PYX_ERR(0, 6, __pyx_L1_error) + #else + __pyx_ptype_11cython_code_13my_translator_MyTranslator = &__pyx_type_11cython_code_13my_translator_MyTranslator; + #endif + #if !CYTHON_COMPILING_IN_LIMITED_API + #endif + #if !CYTHON_USE_TYPE_SPECS + if (__Pyx_PyType_Ready(__pyx_ptype_11cython_code_13my_translator_MyTranslator) < 0) __PYX_ERR(0, 6, __pyx_L1_error) + #endif + #if PY_MAJOR_VERSION < 3 + __pyx_ptype_11cython_code_13my_translator_MyTranslator->tp_print = 0; + #endif + #if !CYTHON_COMPILING_IN_LIMITED_API + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_11cython_code_13my_translator_MyTranslator->tp_dictoffset && __pyx_ptype_11cython_code_13my_translator_MyTranslator->tp_getattro == PyObject_GenericGetAttr)) { + __pyx_ptype_11cython_code_13my_translator_MyTranslator->tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + #endif + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_MyTranslator, (PyObject *) __pyx_ptype_11cython_code_13my_translator_MyTranslator) < 0) __PYX_ERR(0, 6, __pyx_L1_error) + #if !CYTHON_COMPILING_IN_LIMITED_API + if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_11cython_code_13my_translator_MyTranslator) < 0) __PYX_ERR(0, 6, __pyx_L1_error) + #endif + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_modinit_type_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); + /*--- Type import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); + /*--- Variable import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); + /*--- Function import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + + +#if PY_MAJOR_VERSION >= 3 +#if CYTHON_PEP489_MULTI_PHASE_INIT +static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ +static int __pyx_pymod_exec_my_translator(PyObject* module); /*proto*/ +static PyModuleDef_Slot __pyx_moduledef_slots[] = { + {Py_mod_create, (void*)__pyx_pymod_create}, + {Py_mod_exec, (void*)__pyx_pymod_exec_my_translator}, + {0, NULL} +}; +#endif + +#ifdef __cplusplus +namespace { + struct PyModuleDef __pyx_moduledef = + #else + static struct PyModuleDef __pyx_moduledef = + #endif + { + PyModuleDef_HEAD_INIT, + "my_translator", + 0, /* m_doc */ + #if CYTHON_PEP489_MULTI_PHASE_INIT + 0, /* m_size */ + #elif CYTHON_USE_MODULE_STATE + sizeof(__pyx_mstate), /* m_size */ + #else + -1, /* m_size */ + #endif + __pyx_methods /* m_methods */, + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_moduledef_slots, /* m_slots */ + #else + NULL, /* m_reload */ + #endif + #if CYTHON_USE_MODULE_STATE + __pyx_m_traverse, /* m_traverse */ + __pyx_m_clear, /* m_clear */ + NULL /* m_free */ + #else + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ + #endif + }; + #ifdef __cplusplus +} /* anonymous namespace */ +#endif +#endif + +#ifndef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#elif PY_MAJOR_VERSION < 3 +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" void +#else +#define __Pyx_PyMODINIT_FUNC void +#endif +#else +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" PyObject * +#else +#define __Pyx_PyMODINIT_FUNC PyObject * +#endif +#endif + + +#if PY_MAJOR_VERSION < 3 +__Pyx_PyMODINIT_FUNC initmy_translator(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC initmy_translator(void) +#else +__Pyx_PyMODINIT_FUNC PyInit_my_translator(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC PyInit_my_translator(void) +#if CYTHON_PEP489_MULTI_PHASE_INIT +{ + return PyModuleDef_Init(&__pyx_moduledef); +} +static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { + #if PY_VERSION_HEX >= 0x030700A1 + static PY_INT64_T main_interpreter_id = -1; + PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); + if (main_interpreter_id == -1) { + main_interpreter_id = current_id; + return (unlikely(current_id == -1)) ? -1 : 0; + } else if (unlikely(main_interpreter_id != current_id)) + #else + static PyInterpreterState *main_interpreter = NULL; + PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; + if (!main_interpreter) { + main_interpreter = current_interpreter; + } else if (unlikely(main_interpreter != current_interpreter)) + #endif + { + PyErr_SetString( + PyExc_ImportError, + "Interpreter change detected - this module can only be loaded into one interpreter per process."); + return -1; + } + return 0; +} +#if CYTHON_COMPILING_IN_LIMITED_API +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *module, const char* from_name, const char* to_name, int allow_none) +#else +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) +#endif +{ + PyObject *value = PyObject_GetAttrString(spec, from_name); + int result = 0; + if (likely(value)) { + if (allow_none || value != Py_None) { +#if CYTHON_COMPILING_IN_LIMITED_API + result = PyModule_AddObject(module, to_name, value); +#else + result = PyDict_SetItemString(moddict, to_name, value); +#endif + } + Py_DECREF(value); + } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + } else { + result = -1; + } + return result; +} +static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def) { + PyObject *module = NULL, *moddict, *modname; + CYTHON_UNUSED_VAR(def); + if (__Pyx_check_single_interpreter()) + return NULL; + if (__pyx_m) + return __Pyx_NewRef(__pyx_m); + modname = PyObject_GetAttrString(spec, "name"); + if (unlikely(!modname)) goto bad; + module = PyModule_NewObject(modname); + Py_DECREF(modname); + if (unlikely(!module)) goto bad; +#if CYTHON_COMPILING_IN_LIMITED_API + moddict = module; +#else + moddict = PyModule_GetDict(module); + if (unlikely(!moddict)) goto bad; +#endif + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; + return module; +bad: + Py_XDECREF(module); + return NULL; +} + + +static CYTHON_SMALL_CODE int __pyx_pymod_exec_my_translator(PyObject *__pyx_pyinit_module) +#endif +#endif +{ + int stringtab_initialized = 0; + #if CYTHON_USE_MODULE_STATE + int pystate_addmodule_run = 0; + #endif + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannyDeclarations + #if CYTHON_PEP489_MULTI_PHASE_INIT + if (__pyx_m) { + if (__pyx_m == __pyx_pyinit_module) return 0; + PyErr_SetString(PyExc_RuntimeError, "Module 'my_translator' has already been imported. Re-initialisation is not supported."); + return -1; + } + #elif PY_MAJOR_VERSION >= 3 + if (__pyx_m) return __Pyx_NewRef(__pyx_m); + #endif + /*--- Module creation code ---*/ + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_m = __pyx_pyinit_module; + Py_INCREF(__pyx_m); + #else + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4("my_translator", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #elif CYTHON_USE_MODULE_STATE + __pyx_t_1 = PyModule_Create(&__pyx_moduledef); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) + { + int add_module_result = PyState_AddModule(__pyx_t_1, &__pyx_moduledef); + __pyx_t_1 = 0; /* transfer ownership from __pyx_t_1 to "my_translator" pseudovariable */ + if (unlikely((add_module_result < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + pystate_addmodule_run = 1; + } + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #endif + CYTHON_UNUSED_VAR(__pyx_t_1); + __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_d); + __pyx_b = __Pyx_PyImport_AddModuleRef(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_cython_runtime = __Pyx_PyImport_AddModuleRef((const char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if CYTHON_REFNANNY +__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); +if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); +} +#endif + __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_my_translator(void)", 0); + if (__Pyx_check_binary_version(__PYX_LIMITED_VERSION_HEX, __Pyx_get_runtime_version(), CYTHON_COMPILING_IN_LIMITED_API) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pxy_PyFrame_Initialize_Offsets + __Pxy_PyFrame_Initialize_Offsets(); + #endif + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pyx_CyFunction_USED + if (__pyx_CyFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_FusedFunction_USED + if (__pyx_FusedFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Coroutine_USED + if (__pyx_Coroutine_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Generator_USED + if (__pyx_Generator_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_AsyncGen_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_StopAsyncIteration_USED + if (__pyx_StopAsyncIteration_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + /*--- Library function declarations ---*/ + /*--- Threads initialization code ---*/ + #if defined(WITH_THREAD) && PY_VERSION_HEX < 0x030700F0 && defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + PyEval_InitThreads(); + #endif + /*--- Initialize various global constants etc. ---*/ + if (__Pyx_InitConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + stringtab_initialized = 1; + if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) + if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + if (__pyx_module_is_main_cython_code__my_translator) { + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + } + #if PY_MAJOR_VERSION >= 3 + { + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) + if (!PyDict_GetItemString(modules, "cython_code.my_translator")) { + if (unlikely((PyDict_SetItemString(modules, "cython_code.my_translator", __pyx_m) < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + } + } + #endif + /*--- Builtin init code ---*/ + if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Constants init code ---*/ + if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Global type/function init code ---*/ + (void)__Pyx_modinit_global_init_code(); + (void)__Pyx_modinit_variable_export_code(); + (void)__Pyx_modinit_function_export_code(); + if (unlikely((__Pyx_modinit_type_init_code() < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + (void)__Pyx_modinit_type_import_code(); + (void)__Pyx_modinit_variable_import_code(); + (void)__Pyx_modinit_function_import_code(); + /*--- Execution code ---*/ + #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + + /* "cython_code/my_translator.pyx":1 + * import json # <<<<<<<<<<<<<< + * import logging + * from deep_translator import GoogleTranslator + */ + __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_json, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_json, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/my_translator.pyx":2 + * import json + * import logging # <<<<<<<<<<<<<< + * from deep_translator import GoogleTranslator + * from data.config import yil_oy_kun, soat_minut_sekund + */ + __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_logging, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_logging, __pyx_t_2) < 0) __PYX_ERR(0, 2, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/my_translator.pyx":3 + * import json + * import logging + * from deep_translator import GoogleTranslator # <<<<<<<<<<<<<< + * from data.config import yil_oy_kun, soat_minut_sekund + * + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_GoogleTranslator); + __Pyx_GIVEREF(__pyx_n_s_GoogleTranslator); + if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_GoogleTranslator)) __PYX_ERR(0, 3, __pyx_L1_error); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_deep_translator, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_GoogleTranslator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_GoogleTranslator, __pyx_t_2) < 0) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "cython_code/my_translator.pyx":4 + * import logging + * from deep_translator import GoogleTranslator + * from data.config import yil_oy_kun, soat_minut_sekund # <<<<<<<<<<<<<< + * + * cdef class MyTranslator: + */ + __pyx_t_3 = PyList_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_n_s_yil_oy_kun); + __Pyx_GIVEREF(__pyx_n_s_yil_oy_kun); + if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_yil_oy_kun)) __PYX_ERR(0, 4, __pyx_L1_error); + __Pyx_INCREF(__pyx_n_s_soat_minut_sekund); + __Pyx_GIVEREF(__pyx_n_s_soat_minut_sekund); + if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_soat_minut_sekund)) __PYX_ERR(0, 4, __pyx_L1_error); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_data_config, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_yil_oy_kun); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_yil_oy_kun, __pyx_t_3) < 0) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_soat_minut_sekund); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_soat_minut_sekund, __pyx_t_3) < 0) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/my_translator.pyx":28 + * self.json_data = json.load(json_file) + * + * def translator(self): # <<<<<<<<<<<<<< + * try: + * if self.real: + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_13my_translator_12MyTranslator_3translator, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_MyTranslator_translator, NULL, __pyx_n_s_cython_code_my_translator, __pyx_d, ((PyObject *)__pyx_codeobj__7)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 28, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_11cython_code_13my_translator_MyTranslator, __pyx_n_s_translator, __pyx_t_2) < 0) __PYX_ERR(0, 28, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyType_Modified(__pyx_ptype_11cython_code_13my_translator_MyTranslator); + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_13my_translator_12MyTranslator_5__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_MyTranslator___reduce_cython, NULL, __pyx_n_s_cython_code_my_translator, __pyx_d, ((PyObject *)__pyx_codeobj__9)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_11cython_code_13my_translator_MyTranslator, __pyx_n_s_reduce_cython, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyType_Modified(__pyx_ptype_11cython_code_13my_translator_MyTranslator); + + /* "(tree fragment)":16 + * else: + * return __pyx_unpickle_MyTranslator, (type(self), 0xaa02da6, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_MyTranslator__set_state(self, __pyx_state) + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_13my_translator_12MyTranslator_7__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_MyTranslator___setstate_cython, NULL, __pyx_n_s_cython_code_my_translator, __pyx_d, ((PyObject *)__pyx_codeobj__11)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 16, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_11cython_code_13my_translator_MyTranslator, __pyx_n_s_setstate_cython, __pyx_t_2) < 0) __PYX_ERR(1, 16, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyType_Modified(__pyx_ptype_11cython_code_13my_translator_MyTranslator); + + /* "(tree fragment)":1 + * def __pyx_unpickle_MyTranslator(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_13my_translator_1__pyx_unpickle_MyTranslator, 0, __pyx_n_s_pyx_unpickle_MyTranslator, NULL, __pyx_n_s_cython_code_my_translator, __pyx_d, ((PyObject *)__pyx_codeobj__13)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_MyTranslator, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/my_translator.pyx":1 + * import json # <<<<<<<<<<<<<< + * import logging + * from deep_translator import GoogleTranslator + */ + __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /*--- Wrapped vars code ---*/ + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + if (__pyx_m) { + if (__pyx_d && stringtab_initialized) { + __Pyx_AddTraceback("init cython_code.my_translator", __pyx_clineno, __pyx_lineno, __pyx_filename); + } + #if !CYTHON_USE_MODULE_STATE + Py_CLEAR(__pyx_m); + #else + Py_DECREF(__pyx_m); + if (pystate_addmodule_run) { + PyObject *tp, *value, *tb; + PyErr_Fetch(&tp, &value, &tb); + PyState_RemoveModule(&__pyx_moduledef); + PyErr_Restore(tp, value, tb); + } + #endif + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init cython_code.my_translator"); + } + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + #if CYTHON_PEP489_MULTI_PHASE_INIT + return (__pyx_m != NULL) ? 0 : -1; + #elif PY_MAJOR_VERSION >= 3 + return __pyx_m; + #else + return; + #endif +} +/* #### Code section: cleanup_globals ### */ +/* #### Code section: cleanup_module ### */ +/* #### Code section: main_method ### */ +/* #### Code section: utility_code_pragmas ### */ +#ifdef _MSC_VER +#pragma warning( push ) +/* Warning 4127: conditional expression is constant + * Cython uses constant conditional expressions to allow in inline functions to be optimized at + * compile-time, so this warning is not useful + */ +#pragma warning( disable : 4127 ) +#endif + + + +/* #### Code section: utility_code_def ### */ + +/* --- Runtime support code --- */ +/* Refnanny */ +#if CYTHON_REFNANNY +static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { + PyObject *m = NULL, *p = NULL; + void *r = NULL; + m = PyImport_ImportModule(modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, "RefNannyAPI"); + if (!p) goto end; + r = PyLong_AsVoidPtr(p); +end: + Py_XDECREF(p); + Py_XDECREF(m); + return (__Pyx_RefNannyAPIStruct *)r; +} +#endif + +/* PyErrExceptionMatches */ +#if CYTHON_FAST_THREAD_STATE +static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; i= 0x030C00A6 + PyObject *current_exception = tstate->current_exception; + if (unlikely(!current_exception)) return 0; + exc_type = (PyObject*) Py_TYPE(current_exception); + if (exc_type == err) return 1; +#else + exc_type = tstate->curexc_type; + if (exc_type == err) return 1; + if (unlikely(!exc_type)) return 0; +#endif + #if CYTHON_AVOID_BORROWED_REFS + Py_INCREF(exc_type); + #endif + if (unlikely(PyTuple_Check(err))) { + result = __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); + } else { + result = __Pyx_PyErr_GivenExceptionMatches(exc_type, err); + } + #if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(exc_type); + #endif + return result; +} +#endif + +/* PyErrFetchRestore */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { +#if PY_VERSION_HEX >= 0x030C00A6 + PyObject *tmp_value; + assert(type == NULL || (value != NULL && type == (PyObject*) Py_TYPE(value))); + if (value) { + #if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(((PyBaseExceptionObject*) value)->traceback != tb)) + #endif + PyException_SetTraceback(value, tb); + } + tmp_value = tstate->current_exception; + tstate->current_exception = value; + Py_XDECREF(tmp_value); + Py_XDECREF(type); + Py_XDECREF(tb); +#else + PyObject *tmp_type, *tmp_value, *tmp_tb; + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#endif +} +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { +#if PY_VERSION_HEX >= 0x030C00A6 + PyObject* exc_value; + exc_value = tstate->current_exception; + tstate->current_exception = 0; + *value = exc_value; + *type = NULL; + *tb = NULL; + if (exc_value) { + *type = (PyObject*) Py_TYPE(exc_value); + Py_INCREF(*type); + #if CYTHON_COMPILING_IN_CPYTHON + *tb = ((PyBaseExceptionObject*) exc_value)->traceback; + Py_XINCREF(*tb); + #else + *tb = PyException_GetTraceback(exc_value); + #endif + } +#else + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +#endif +} +#endif + +/* PyObjectGetAttrStr */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro)) + return tp->tp_getattro(obj, attr_name); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_getattr)) + return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); +#endif + return PyObject_GetAttr(obj, attr_name); +} +#endif + +/* PyObjectGetAttrStrNoError */ +#if __PYX_LIMITED_VERSION_HEX < 0x030d00A1 +static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + __Pyx_PyErr_Clear(); +} +#endif +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { + PyObject *result; +#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1 + (void) PyObject_GetOptionalAttr(obj, attr_name, &result); + return result; +#else +#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { + return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); + } +#endif + result = __Pyx_PyObject_GetAttrStr(obj, attr_name); + if (unlikely(!result)) { + __Pyx_PyObject_GetAttrStr_ClearAttributeError(); + } + return result; +#endif +} + +/* GetBuiltinName */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name) { + PyObject* result = __Pyx_PyObject_GetAttrStrNoError(__pyx_b, name); + if (unlikely(!result) && !PyErr_Occurred()) { + PyErr_Format(PyExc_NameError, +#if PY_MAJOR_VERSION >= 3 + "name '%U' is not defined", name); +#else + "name '%.200s' is not defined", PyString_AS_STRING(name)); +#endif + } + return result; +} + +/* TupleAndListFromArray */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE void __Pyx_copy_object_array(PyObject *const *CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) { + PyObject *v; + Py_ssize_t i; + for (i = 0; i < length; i++) { + v = dest[i] = src[i]; + Py_INCREF(v); + } +} +static CYTHON_INLINE PyObject * +__Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n) +{ + PyObject *res; + if (n <= 0) { + Py_INCREF(__pyx_empty_tuple); + return __pyx_empty_tuple; + } + res = PyTuple_New(n); + if (unlikely(res == NULL)) return NULL; + __Pyx_copy_object_array(src, ((PyTupleObject*)res)->ob_item, n); + return res; +} +static CYTHON_INLINE PyObject * +__Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n) +{ + PyObject *res; + if (n <= 0) { + return PyList_New(0); + } + res = PyList_New(n); + if (unlikely(res == NULL)) return NULL; + __Pyx_copy_object_array(src, ((PyListObject*)res)->ob_item, n); + return res; +} +#endif + +/* BytesEquals */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API + return PyObject_RichCompareBool(s1, s2, equals); +#else + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { + const char *ps1, *ps2; + Py_ssize_t length = PyBytes_GET_SIZE(s1); + if (length != PyBytes_GET_SIZE(s2)) + return (equals == Py_NE); + ps1 = PyBytes_AS_STRING(s1); + ps2 = PyBytes_AS_STRING(s2); + if (ps1[0] != ps2[0]) { + return (equals == Py_NE); + } else if (length == 1) { + return (equals == Py_EQ); + } else { + int result; +#if CYTHON_USE_UNICODE_INTERNALS && (PY_VERSION_HEX < 0x030B0000) + Py_hash_t hash1, hash2; + hash1 = ((PyBytesObject*)s1)->ob_shash; + hash2 = ((PyBytesObject*)s2)->ob_shash; + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + return (equals == Py_NE); + } +#endif + result = memcmp(ps1, ps2, (size_t)length); + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +#endif +} + +/* UnicodeEquals */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API + return PyObject_RichCompareBool(s1, s2, equals); +#else +#if PY_MAJOR_VERSION < 3 + PyObject* owned_ref = NULL; +#endif + int s1_is_unicode, s2_is_unicode; + if (s1 == s2) { + goto return_eq; + } + s1_is_unicode = PyUnicode_CheckExact(s1); + s2_is_unicode = PyUnicode_CheckExact(s2); +#if PY_MAJOR_VERSION < 3 + if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { + owned_ref = PyUnicode_FromObject(s2); + if (unlikely(!owned_ref)) + return -1; + s2 = owned_ref; + s2_is_unicode = 1; + } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { + owned_ref = PyUnicode_FromObject(s1); + if (unlikely(!owned_ref)) + return -1; + s1 = owned_ref; + s1_is_unicode = 1; + } else if (((!s2_is_unicode) & (!s1_is_unicode))) { + return __Pyx_PyBytes_Equals(s1, s2, equals); + } +#endif + if (s1_is_unicode & s2_is_unicode) { + Py_ssize_t length; + int kind; + void *data1, *data2; + if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) + return -1; + length = __Pyx_PyUnicode_GET_LENGTH(s1); + if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { + goto return_ne; + } +#if CYTHON_USE_UNICODE_INTERNALS + { + Py_hash_t hash1, hash2; + #if CYTHON_PEP393_ENABLED + hash1 = ((PyASCIIObject*)s1)->hash; + hash2 = ((PyASCIIObject*)s2)->hash; + #else + hash1 = ((PyUnicodeObject*)s1)->hash; + hash2 = ((PyUnicodeObject*)s2)->hash; + #endif + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + goto return_ne; + } + } +#endif + kind = __Pyx_PyUnicode_KIND(s1); + if (kind != __Pyx_PyUnicode_KIND(s2)) { + goto return_ne; + } + data1 = __Pyx_PyUnicode_DATA(s1); + data2 = __Pyx_PyUnicode_DATA(s2); + if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { + goto return_ne; + } else if (length == 1) { + goto return_eq; + } else { + int result = memcmp(data1, data2, (size_t)(length * kind)); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & s2_is_unicode) { + goto return_ne; + } else if ((s2 == Py_None) & s1_is_unicode) { + goto return_ne; + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +return_eq: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ); +return_ne: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_NE); +#endif +} + +/* fastcall */ +#if CYTHON_METH_FASTCALL +static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s) +{ + Py_ssize_t i, n = PyTuple_GET_SIZE(kwnames); + for (i = 0; i < n; i++) + { + if (s == PyTuple_GET_ITEM(kwnames, i)) return kwvalues[i]; + } + for (i = 0; i < n; i++) + { + int eq = __Pyx_PyUnicode_Equals(s, PyTuple_GET_ITEM(kwnames, i), Py_EQ); + if (unlikely(eq != 0)) { + if (unlikely(eq < 0)) return NULL; + return kwvalues[i]; + } + } + return NULL; +} +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000 +CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues) { + Py_ssize_t i, nkwargs = PyTuple_GET_SIZE(kwnames); + PyObject *dict; + dict = PyDict_New(); + if (unlikely(!dict)) + return NULL; + for (i=0; i= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AsString(kw_name)); + #endif +} + +/* ParseKeywords */ +static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject *const *kwvalues, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + int kwds_is_tuple = CYTHON_METH_FASTCALL && likely(PyTuple_Check(kwds)); + while (1) { + Py_XDECREF(key); key = NULL; + Py_XDECREF(value); value = NULL; + if (kwds_is_tuple) { + Py_ssize_t size; +#if CYTHON_ASSUME_SAFE_MACROS + size = PyTuple_GET_SIZE(kwds); +#else + size = PyTuple_Size(kwds); + if (size < 0) goto bad; +#endif + if (pos >= size) break; +#if CYTHON_AVOID_BORROWED_REFS + key = __Pyx_PySequence_ITEM(kwds, pos); + if (!key) goto bad; +#elif CYTHON_ASSUME_SAFE_MACROS + key = PyTuple_GET_ITEM(kwds, pos); +#else + key = PyTuple_GetItem(kwds, pos); + if (!key) goto bad; +#endif + value = kwvalues[pos]; + pos++; + } + else + { + if (!PyDict_Next(kwds, &pos, &key, &value)) break; +#if CYTHON_AVOID_BORROWED_REFS + Py_INCREF(key); +#endif + } + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; +#if CYTHON_AVOID_BORROWED_REFS + Py_INCREF(value); + Py_DECREF(key); +#endif + key = NULL; + value = NULL; + continue; + } +#if !CYTHON_AVOID_BORROWED_REFS + Py_INCREF(key); +#endif + Py_INCREF(value); + name = first_kw_arg; + #if PY_MAJOR_VERSION < 3 + if (likely(PyString_Check(key))) { + while (*name) { + if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) + && _PyString_Eq(**name, key)) { + values[name-argnames] = value; +#if CYTHON_AVOID_BORROWED_REFS + value = NULL; +#endif + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + if ((**argname == key) || ( + (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) + && _PyString_Eq(**argname, key))) { + goto arg_passed_twice; + } + argname++; + } + } + } else + #endif + if (likely(PyUnicode_Check(key))) { + while (*name) { + int cmp = ( + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : + #endif + PyUnicode_Compare(**name, key) + ); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) { + values[name-argnames] = value; +#if CYTHON_AVOID_BORROWED_REFS + value = NULL; +#endif + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + int cmp = (**argname == key) ? 0 : + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : + #endif + PyUnicode_Compare(**argname, key); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) goto arg_passed_twice; + argname++; + } + } + } else + goto invalid_keyword_type; + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; + } + } + Py_XDECREF(key); + Py_XDECREF(value); + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, key); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + #if PY_MAJOR_VERSION < 3 + PyErr_Format(PyExc_TypeError, + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + PyErr_Format(PyExc_TypeError, + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + Py_XDECREF(key); + Py_XDECREF(value); + return -1; +} + +/* ArgTypeTest */ +static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) +{ + __Pyx_TypeName type_name; + __Pyx_TypeName obj_type_name; + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; + } + else if (exact) { + #if PY_MAJOR_VERSION == 2 + if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; + #endif + } + else { + if (likely(__Pyx_TypeCheck(obj, type))) return 1; + } + type_name = __Pyx_PyType_GetName(type); + obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj)); + PyErr_Format(PyExc_TypeError, + "Argument '%.200s' has incorrect type (expected " __Pyx_FMT_TYPENAME + ", got " __Pyx_FMT_TYPENAME ")", name, type_name, obj_type_name); + __Pyx_DECREF_TypeName(type_name); + __Pyx_DECREF_TypeName(obj_type_name); + return 0; +} + +/* PyObjectCall */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *result; + ternaryfunc call = Py_TYPE(func)->tp_call; + if (unlikely(!call)) + return PyObject_Call(func, arg, kw); + #if PY_MAJOR_VERSION < 3 + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + #else + if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) + return NULL; + #endif + result = (*call)(func, arg, kw); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* PyObjectLookupSpecial */ +#if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx__PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name, int with_error) { + PyObject *res; + PyTypeObject *tp = Py_TYPE(obj); +#if PY_MAJOR_VERSION < 3 + if (unlikely(PyInstance_Check(obj))) + return with_error ? __Pyx_PyObject_GetAttrStr(obj, attr_name) : __Pyx_PyObject_GetAttrStrNoError(obj, attr_name); +#endif + res = _PyType_Lookup(tp, attr_name); + if (likely(res)) { + descrgetfunc f = Py_TYPE(res)->tp_descr_get; + if (!f) { + Py_INCREF(res); + } else { + res = f(res, obj, (PyObject *)tp); + } + } else if (with_error) { + PyErr_SetObject(PyExc_AttributeError, attr_name); + } + return res; +} +#endif + +/* PyFunctionFastCall */ +#if CYTHON_FAST_PYCALL && !CYTHON_VECTORCALL +static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na, + PyObject *globals) { + PyFrameObject *f; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject **fastlocals; + Py_ssize_t i; + PyObject *result; + assert(globals != NULL); + /* XXX Perhaps we should create a specialized + PyFrame_New() that doesn't take locals, but does + take builtins without sanity checking them. + */ + assert(tstate != NULL); + f = PyFrame_New(tstate, co, globals, NULL); + if (f == NULL) { + return NULL; + } + fastlocals = __Pyx_PyFrame_GetLocalsplus(f); + for (i = 0; i < na; i++) { + Py_INCREF(*args); + fastlocals[i] = *args++; + } + result = PyEval_EvalFrameEx(f,0); + ++tstate->recursion_depth; + Py_DECREF(f); + --tstate->recursion_depth; + return result; +} +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) { + PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); + PyObject *globals = PyFunction_GET_GLOBALS(func); + PyObject *argdefs = PyFunction_GET_DEFAULTS(func); + PyObject *closure; +#if PY_MAJOR_VERSION >= 3 + PyObject *kwdefs; +#endif + PyObject *kwtuple, **k; + PyObject **d; + Py_ssize_t nd; + Py_ssize_t nk; + PyObject *result; + assert(kwargs == NULL || PyDict_Check(kwargs)); + nk = kwargs ? PyDict_Size(kwargs) : 0; + #if PY_MAJOR_VERSION < 3 + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) { + return NULL; + } + #else + if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) { + return NULL; + } + #endif + if ( +#if PY_MAJOR_VERSION >= 3 + co->co_kwonlyargcount == 0 && +#endif + likely(kwargs == NULL || nk == 0) && + co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { + if (argdefs == NULL && co->co_argcount == nargs) { + result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals); + goto done; + } + else if (nargs == 0 && argdefs != NULL + && co->co_argcount == Py_SIZE(argdefs)) { + /* function called with no arguments, but all parameters have + a default value: use default values as arguments .*/ + args = &PyTuple_GET_ITEM(argdefs, 0); + result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals); + goto done; + } + } + if (kwargs != NULL) { + Py_ssize_t pos, i; + kwtuple = PyTuple_New(2 * nk); + if (kwtuple == NULL) { + result = NULL; + goto done; + } + k = &PyTuple_GET_ITEM(kwtuple, 0); + pos = i = 0; + while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) { + Py_INCREF(k[i]); + Py_INCREF(k[i+1]); + i += 2; + } + nk = i / 2; + } + else { + kwtuple = NULL; + k = NULL; + } + closure = PyFunction_GET_CLOSURE(func); +#if PY_MAJOR_VERSION >= 3 + kwdefs = PyFunction_GET_KW_DEFAULTS(func); +#endif + if (argdefs != NULL) { + d = &PyTuple_GET_ITEM(argdefs, 0); + nd = Py_SIZE(argdefs); + } + else { + d = NULL; + nd = 0; + } +#if PY_MAJOR_VERSION >= 3 + result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL, + args, (int)nargs, + k, (int)nk, + d, (int)nd, kwdefs, closure); +#else + result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, + args, (int)nargs, + k, (int)nk, + d, (int)nd, closure); +#endif + Py_XDECREF(kwtuple); +done: + Py_LeaveRecursiveCall(); + return result; +} +#endif + +/* PyObjectCallMethO */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) { + PyObject *self, *result; + PyCFunction cfunc; + cfunc = __Pyx_CyOrPyCFunction_GET_FUNCTION(func); + self = __Pyx_CyOrPyCFunction_GET_SELF(func); + #if PY_MAJOR_VERSION < 3 + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + #else + if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) + return NULL; + #endif + result = cfunc(self, arg); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* PyObjectFastCall */ +#if PY_VERSION_HEX < 0x03090000 || CYTHON_COMPILING_IN_LIMITED_API +static PyObject* __Pyx_PyObject_FastCall_fallback(PyObject *func, PyObject **args, size_t nargs, PyObject *kwargs) { + PyObject *argstuple; + PyObject *result = 0; + size_t i; + argstuple = PyTuple_New((Py_ssize_t)nargs); + if (unlikely(!argstuple)) return NULL; + for (i = 0; i < nargs; i++) { + Py_INCREF(args[i]); + if (__Pyx_PyTuple_SET_ITEM(argstuple, (Py_ssize_t)i, args[i]) < 0) goto bad; + } + result = __Pyx_PyObject_Call(func, argstuple, kwargs); + bad: + Py_DECREF(argstuple); + return result; +} +#endif +static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject **args, size_t _nargs, PyObject *kwargs) { + Py_ssize_t nargs = __Pyx_PyVectorcall_NARGS(_nargs); +#if CYTHON_COMPILING_IN_CPYTHON + if (nargs == 0 && kwargs == NULL) { + if (__Pyx_CyOrPyCFunction_Check(func) && likely( __Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_NOARGS)) + return __Pyx_PyObject_CallMethO(func, NULL); + } + else if (nargs == 1 && kwargs == NULL) { + if (__Pyx_CyOrPyCFunction_Check(func) && likely( __Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_O)) + return __Pyx_PyObject_CallMethO(func, args[0]); + } +#endif + #if PY_VERSION_HEX < 0x030800B1 + #if CYTHON_FAST_PYCCALL + if (PyCFunction_Check(func)) { + if (kwargs) { + return _PyCFunction_FastCallDict(func, args, nargs, kwargs); + } else { + return _PyCFunction_FastCallKeywords(func, args, nargs, NULL); + } + } + #if PY_VERSION_HEX >= 0x030700A1 + if (!kwargs && __Pyx_IS_TYPE(func, &PyMethodDescr_Type)) { + return _PyMethodDescr_FastCallKeywords(func, args, nargs, NULL); + } + #endif + #endif + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(func)) { + return __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs); + } + #endif + #endif + if (kwargs == NULL) { + #if CYTHON_VECTORCALL + #if PY_VERSION_HEX < 0x03090000 + vectorcallfunc f = _PyVectorcall_Function(func); + #else + vectorcallfunc f = PyVectorcall_Function(func); + #endif + if (f) { + return f(func, args, (size_t)nargs, NULL); + } + #elif defined(__Pyx_CyFunction_USED) && CYTHON_BACKPORT_VECTORCALL + if (__Pyx_CyFunction_CheckExact(func)) { + __pyx_vectorcallfunc f = __Pyx_CyFunction_func_vectorcall(func); + if (f) return f(func, args, (size_t)nargs, NULL); + } + #endif + } + if (nargs == 0) { + return __Pyx_PyObject_Call(func, __pyx_empty_tuple, kwargs); + } + #if PY_VERSION_HEX >= 0x03090000 && !CYTHON_COMPILING_IN_LIMITED_API + return PyObject_VectorcallDict(func, args, (size_t)nargs, kwargs); + #else + return __Pyx_PyObject_FastCall_fallback(func, args, (size_t)nargs, kwargs); + #endif +} + +/* PyDictVersioning */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { + PyObject **dictptr = NULL; + Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; + if (offset) { +#if CYTHON_COMPILING_IN_CPYTHON + dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); +#else + dictptr = _PyObject_GetDictPtr(obj); +#endif + } + return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; +} +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) + return 0; + return obj_dict_version == __Pyx_get_object_dict_version(obj); +} +#endif + +/* GetModuleGlobalName */ +#if CYTHON_USE_DICT_VERSIONS +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) +#else +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) +#endif +{ + PyObject *result; +#if !CYTHON_AVOID_BORROWED_REFS +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && PY_VERSION_HEX < 0x030d0000 + result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } else if (unlikely(PyErr_Occurred())) { + return NULL; + } +#elif CYTHON_COMPILING_IN_LIMITED_API + if (unlikely(!__pyx_m)) { + return NULL; + } + result = PyObject_GetAttr(__pyx_m, name); + if (likely(result)) { + return result; + } +#else + result = PyDict_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } +#endif +#else + result = PyObject_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } + PyErr_Clear(); +#endif + return __Pyx_GetBuiltinName(name); +} + +/* RaiseUnexpectedTypeError */ +static int +__Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj) +{ + __Pyx_TypeName obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj)); + PyErr_Format(PyExc_TypeError, "Expected %s, got " __Pyx_FMT_TYPENAME, + expected, obj_type_name); + __Pyx_DECREF_TypeName(obj_type_name); + return 0; +} + +/* GetTopmostException */ +#if CYTHON_USE_EXC_INFO_STACK && CYTHON_FAST_THREAD_STATE +static _PyErr_StackItem * +__Pyx_PyErr_GetTopmostException(PyThreadState *tstate) +{ + _PyErr_StackItem *exc_info = tstate->exc_info; + while ((exc_info->exc_value == NULL || exc_info->exc_value == Py_None) && + exc_info->previous_item != NULL) + { + exc_info = exc_info->previous_item; + } + return exc_info; +} +#endif + +/* SaveResetException */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4 + _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); + PyObject *exc_value = exc_info->exc_value; + if (exc_value == NULL || exc_value == Py_None) { + *value = NULL; + *type = NULL; + *tb = NULL; + } else { + *value = exc_value; + Py_INCREF(*value); + *type = (PyObject*) Py_TYPE(exc_value); + Py_INCREF(*type); + *tb = PyException_GetTraceback(exc_value); + } + #elif CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); + *type = exc_info->exc_type; + *value = exc_info->exc_value; + *tb = exc_info->exc_traceback; + Py_XINCREF(*type); + Py_XINCREF(*value); + Py_XINCREF(*tb); + #else + *type = tstate->exc_type; + *value = tstate->exc_value; + *tb = tstate->exc_traceback; + Py_XINCREF(*type); + Py_XINCREF(*value); + Py_XINCREF(*tb); + #endif +} +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { + #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4 + _PyErr_StackItem *exc_info = tstate->exc_info; + PyObject *tmp_value = exc_info->exc_value; + exc_info->exc_value = value; + Py_XDECREF(tmp_value); + Py_XDECREF(type); + Py_XDECREF(tb); + #else + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = type; + exc_info->exc_value = value; + exc_info->exc_traceback = tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = type; + tstate->exc_value = value; + tstate->exc_traceback = tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); + #endif +} +#endif + +/* GetException */ +#if CYTHON_FAST_THREAD_STATE +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) +#endif +{ + PyObject *local_type = NULL, *local_value, *local_tb = NULL; +#if CYTHON_FAST_THREAD_STATE + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if PY_VERSION_HEX >= 0x030C00A6 + local_value = tstate->current_exception; + tstate->current_exception = 0; + if (likely(local_value)) { + local_type = (PyObject*) Py_TYPE(local_value); + Py_INCREF(local_type); + local_tb = PyException_GetTraceback(local_value); + } + #else + local_type = tstate->curexc_type; + local_value = tstate->curexc_value; + local_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; + #endif +#else + PyErr_Fetch(&local_type, &local_value, &local_tb); +#endif + PyErr_NormalizeException(&local_type, &local_value, &local_tb); +#if CYTHON_FAST_THREAD_STATE && PY_VERSION_HEX >= 0x030C00A6 + if (unlikely(tstate->current_exception)) +#elif CYTHON_FAST_THREAD_STATE + if (unlikely(tstate->curexc_type)) +#else + if (unlikely(PyErr_Occurred())) +#endif + goto bad; + #if PY_MAJOR_VERSION >= 3 + if (local_tb) { + if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) + goto bad; + } + #endif + Py_XINCREF(local_tb); + Py_XINCREF(local_type); + Py_XINCREF(local_value); + *type = local_type; + *value = local_value; + *tb = local_tb; +#if CYTHON_FAST_THREAD_STATE + #if CYTHON_USE_EXC_INFO_STACK + { + _PyErr_StackItem *exc_info = tstate->exc_info; + #if PY_VERSION_HEX >= 0x030B00a4 + tmp_value = exc_info->exc_value; + exc_info->exc_value = local_value; + tmp_type = NULL; + tmp_tb = NULL; + Py_XDECREF(local_type); + Py_XDECREF(local_tb); + #else + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = local_type; + exc_info->exc_value = local_value; + exc_info->exc_traceback = local_tb; + #endif + } + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = local_type; + tstate->exc_value = local_value; + tstate->exc_traceback = local_tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#else + PyErr_SetExcInfo(local_type, local_value, local_tb); +#endif + return 0; +bad: + *type = 0; + *value = 0; + *tb = 0; + Py_XDECREF(local_type); + Py_XDECREF(local_value); + Py_XDECREF(local_tb); + return -1; +} + +/* FastTypeChecks */ +#if CYTHON_COMPILING_IN_CPYTHON +static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { + while (a) { + a = __Pyx_PyType_GetSlot(a, tp_base, PyTypeObject*); + if (a == b) + return 1; + } + return b == &PyBaseObject_Type; +} +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { + PyObject *mro; + if (a == b) return 1; + mro = a->tp_mro; + if (likely(mro)) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) + return 1; + } + return 0; + } + return __Pyx_InBases(a, b); +} +static CYTHON_INLINE int __Pyx_IsAnySubtype2(PyTypeObject *cls, PyTypeObject *a, PyTypeObject *b) { + PyObject *mro; + if (cls == a || cls == b) return 1; + mro = cls->tp_mro; + if (likely(mro)) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + PyObject *base = PyTuple_GET_ITEM(mro, i); + if (base == (PyObject *)a || base == (PyObject *)b) + return 1; + } + return 0; + } + return __Pyx_InBases(cls, a) || __Pyx_InBases(cls, b); +} +#if PY_MAJOR_VERSION == 2 +static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { + PyObject *exception, *value, *tb; + int res; + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&exception, &value, &tb); + res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + if (!res) { + res = PyObject_IsSubclass(err, exc_type2); + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + } + __Pyx_ErrRestore(exception, value, tb); + return res; +} +#else +static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { + if (exc_type1) { + return __Pyx_IsAnySubtype2((PyTypeObject*)err, (PyTypeObject*)exc_type1, (PyTypeObject*)exc_type2); + } else { + return __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); + } +} +#endif +static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + assert(PyExceptionClass_Check(exc_type)); + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; i= 3 +static int +__Pyx_unicode_modifiable(PyObject *unicode) +{ + if (Py_REFCNT(unicode) != 1) + return 0; + if (!PyUnicode_CheckExact(unicode)) + return 0; + if (PyUnicode_CHECK_INTERNED(unicode)) + return 0; + return 1; +} +static CYTHON_INLINE PyObject *__Pyx_PyUnicode_ConcatInPlaceImpl(PyObject **p_left, PyObject *right + #if CYTHON_REFNANNY + , void* __pyx_refnanny + #endif + ) { + PyObject *left = *p_left; + Py_ssize_t left_len, right_len, new_len; + if (unlikely(__Pyx_PyUnicode_READY(left) == -1)) + return NULL; + if (unlikely(__Pyx_PyUnicode_READY(right) == -1)) + return NULL; + left_len = PyUnicode_GET_LENGTH(left); + if (left_len == 0) { + Py_INCREF(right); + return right; + } + right_len = PyUnicode_GET_LENGTH(right); + if (right_len == 0) { + Py_INCREF(left); + return left; + } + if (unlikely(left_len > PY_SSIZE_T_MAX - right_len)) { + PyErr_SetString(PyExc_OverflowError, + "strings are too large to concat"); + return NULL; + } + new_len = left_len + right_len; + if (__Pyx_unicode_modifiable(left) + && PyUnicode_CheckExact(right) + && PyUnicode_KIND(right) <= PyUnicode_KIND(left) + && !(PyUnicode_IS_ASCII(left) && !PyUnicode_IS_ASCII(right))) { + int ret; + __Pyx_GIVEREF(*p_left); + ret = PyUnicode_Resize(p_left, new_len); + __Pyx_GOTREF(*p_left); + if (unlikely(ret != 0)) + return NULL; + #if PY_VERSION_HEX >= 0x030d0000 + if (unlikely(PyUnicode_CopyCharacters(*p_left, left_len, right, 0, right_len) < 0)) return NULL; + #else + _PyUnicode_FastCopyCharacters(*p_left, left_len, right, 0, right_len); + #endif + __Pyx_INCREF(*p_left); + __Pyx_GIVEREF(*p_left); + return *p_left; + } else { + return __Pyx_PyUnicode_Concat(left, right); + } + } +#endif + +/* KeywordStringCheck */ +static int __Pyx_CheckKeywordStrings( + PyObject *kw, + const char* function_name, + int kw_allowed) +{ + PyObject* key = 0; + Py_ssize_t pos = 0; +#if CYTHON_COMPILING_IN_PYPY + if (!kw_allowed && PyDict_Next(kw, &pos, &key, 0)) + goto invalid_keyword; + return 1; +#else + if (CYTHON_METH_FASTCALL && likely(PyTuple_Check(kw))) { + Py_ssize_t kwsize; +#if CYTHON_ASSUME_SAFE_MACROS + kwsize = PyTuple_GET_SIZE(kw); +#else + kwsize = PyTuple_Size(kw); + if (kwsize < 0) return 0; +#endif + if (unlikely(kwsize == 0)) + return 1; + if (!kw_allowed) { +#if CYTHON_ASSUME_SAFE_MACROS + key = PyTuple_GET_ITEM(kw, 0); +#else + key = PyTuple_GetItem(kw, pos); + if (!key) return 0; +#endif + goto invalid_keyword; + } +#if PY_VERSION_HEX < 0x03090000 + for (pos = 0; pos < kwsize; pos++) { +#if CYTHON_ASSUME_SAFE_MACROS + key = PyTuple_GET_ITEM(kw, pos); +#else + key = PyTuple_GetItem(kw, pos); + if (!key) return 0; +#endif + if (unlikely(!PyUnicode_Check(key))) + goto invalid_keyword_type; + } +#endif + return 1; + } + while (PyDict_Next(kw, &pos, &key, 0)) { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_Check(key))) + #endif + if (unlikely(!PyUnicode_Check(key))) + goto invalid_keyword_type; + } + if (!kw_allowed && unlikely(key)) + goto invalid_keyword; + return 1; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + return 0; +#endif +invalid_keyword: + #if PY_MAJOR_VERSION < 3 + PyErr_Format(PyExc_TypeError, + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + PyErr_Format(PyExc_TypeError, + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif + return 0; +} + +/* DictGetItem */ +#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY +static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { + PyObject *value; + value = PyDict_GetItemWithError(d, key); + if (unlikely(!value)) { + if (!PyErr_Occurred()) { + if (unlikely(PyTuple_Check(key))) { + PyObject* args = PyTuple_Pack(1, key); + if (likely(args)) { + PyErr_SetObject(PyExc_KeyError, args); + Py_DECREF(args); + } + } else { + PyErr_SetObject(PyExc_KeyError, key); + } + } + return NULL; + } + Py_INCREF(value); + return value; +} +#endif + +/* SwapException */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4 + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_value = exc_info->exc_value; + exc_info->exc_value = *value; + if (tmp_value == NULL || tmp_value == Py_None) { + Py_XDECREF(tmp_value); + tmp_value = NULL; + tmp_type = NULL; + tmp_tb = NULL; + } else { + tmp_type = (PyObject*) Py_TYPE(tmp_value); + Py_INCREF(tmp_type); + #if CYTHON_COMPILING_IN_CPYTHON + tmp_tb = ((PyBaseExceptionObject*) tmp_value)->traceback; + Py_XINCREF(tmp_tb); + #else + tmp_tb = PyException_GetTraceback(tmp_value); + #endif + } + #elif CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = *type; + exc_info->exc_value = *value; + exc_info->exc_traceback = *tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = *type; + tstate->exc_value = *value; + tstate->exc_traceback = *tb; + #endif + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb); + PyErr_SetExcInfo(*type, *value, *tb); + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#endif + +/* GetAttr3 */ +#if __PYX_LIMITED_VERSION_HEX < 0x030d00A1 +static PyObject *__Pyx_GetAttr3Default(PyObject *d) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + return NULL; + __Pyx_PyErr_Clear(); + Py_INCREF(d); + return d; +} +#endif +static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) { + PyObject *r; +#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1 + int res = PyObject_GetOptionalAttr(o, n, &r); + return (res != 0) ? r : __Pyx_NewRef(d); +#else + #if CYTHON_USE_TYPE_SLOTS + if (likely(PyString_Check(n))) { + r = __Pyx_PyObject_GetAttrStrNoError(o, n); + if (unlikely(!r) && likely(!PyErr_Occurred())) { + r = __Pyx_NewRef(d); + } + return r; + } + #endif + r = PyObject_GetAttr(o, n); + return (likely(r)) ? r : __Pyx_GetAttr3Default(d); +#endif +} + +/* Import */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { + PyObject *module = 0; + PyObject *empty_dict = 0; + PyObject *empty_list = 0; + #if PY_MAJOR_VERSION < 3 + PyObject *py_import; + py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); + if (unlikely(!py_import)) + goto bad; + if (!from_list) { + empty_list = PyList_New(0); + if (unlikely(!empty_list)) + goto bad; + from_list = empty_list; + } + #endif + empty_dict = PyDict_New(); + if (unlikely(!empty_dict)) + goto bad; + { + #if PY_MAJOR_VERSION >= 3 + if (level == -1) { + if (strchr(__Pyx_MODULE_NAME, '.') != NULL) { + module = PyImport_ImportModuleLevelObject( + name, __pyx_d, empty_dict, from_list, 1); + if (unlikely(!module)) { + if (unlikely(!PyErr_ExceptionMatches(PyExc_ImportError))) + goto bad; + PyErr_Clear(); + } + } + level = 0; + } + #endif + if (!module) { + #if PY_MAJOR_VERSION < 3 + PyObject *py_level = PyInt_FromLong(level); + if (unlikely(!py_level)) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, __pyx_d, empty_dict, from_list, py_level, (PyObject *)NULL); + Py_DECREF(py_level); + #else + module = PyImport_ImportModuleLevelObject( + name, __pyx_d, empty_dict, from_list, level); + #endif + } + } +bad: + Py_XDECREF(empty_dict); + Py_XDECREF(empty_list); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(py_import); + #endif + return module; +} + +/* ImportFrom */ +static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) { + PyObject* value = __Pyx_PyObject_GetAttrStr(module, name); + if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) { + const char* module_name_str = 0; + PyObject* module_name = 0; + PyObject* module_dot = 0; + PyObject* full_name = 0; + PyErr_Clear(); + module_name_str = PyModule_GetName(module); + if (unlikely(!module_name_str)) { goto modbad; } + module_name = PyUnicode_FromString(module_name_str); + if (unlikely(!module_name)) { goto modbad; } + module_dot = PyUnicode_Concat(module_name, __pyx_kp_u__4); + if (unlikely(!module_dot)) { goto modbad; } + full_name = PyUnicode_Concat(module_dot, name); + if (unlikely(!full_name)) { goto modbad; } + #if PY_VERSION_HEX < 0x030700A1 || (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM < 0x07030400) + { + PyObject *modules = PyImport_GetModuleDict(); + if (unlikely(!modules)) + goto modbad; + value = PyObject_GetItem(modules, full_name); + } + #else + value = PyImport_GetModule(full_name); + #endif + modbad: + Py_XDECREF(full_name); + Py_XDECREF(module_dot); + Py_XDECREF(module_name); + } + if (unlikely(!value)) { + PyErr_Format(PyExc_ImportError, + #if PY_MAJOR_VERSION < 3 + "cannot import name %.230s", PyString_AS_STRING(name)); + #else + "cannot import name %S", name); + #endif + } + return value; +} + +/* RaiseException */ +#if PY_MAJOR_VERSION < 3 +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + __Pyx_PyThreadState_declare + CYTHON_UNUSED_VAR(cause); + Py_XINCREF(type); + if (!value || value == Py_None) + value = NULL; + else + Py_INCREF(value); + if (!tb || tb == Py_None) + tb = NULL; + else { + Py_INCREF(tb); + if (!PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + } + if (PyType_Check(type)) { +#if CYTHON_COMPILING_IN_PYPY + if (!value) { + Py_INCREF(Py_None); + value = Py_None; + } +#endif + PyErr_NormalizeException(&type, &value, &tb); + } else { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + value = type; + type = (PyObject*) Py_TYPE(type); + Py_INCREF(type); + if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto raise_error; + } + } + __Pyx_PyThreadState_assign + __Pyx_ErrRestore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} +#else +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + PyObject* owned_instance = NULL; + if (tb == Py_None) { + tb = 0; + } else if (tb && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto bad; + } + if (value == Py_None) + value = 0; + if (PyExceptionInstance_Check(type)) { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto bad; + } + value = type; + type = (PyObject*) Py_TYPE(value); + } else if (PyExceptionClass_Check(type)) { + PyObject *instance_class = NULL; + if (value && PyExceptionInstance_Check(value)) { + instance_class = (PyObject*) Py_TYPE(value); + if (instance_class != type) { + int is_subclass = PyObject_IsSubclass(instance_class, type); + if (!is_subclass) { + instance_class = NULL; + } else if (unlikely(is_subclass == -1)) { + goto bad; + } else { + type = instance_class; + } + } + } + if (!instance_class) { + PyObject *args; + if (!value) + args = PyTuple_New(0); + else if (PyTuple_Check(value)) { + Py_INCREF(value); + args = value; + } else + args = PyTuple_Pack(1, value); + if (!args) + goto bad; + owned_instance = PyObject_Call(type, args, NULL); + Py_DECREF(args); + if (!owned_instance) + goto bad; + value = owned_instance; + if (!PyExceptionInstance_Check(value)) { + PyErr_Format(PyExc_TypeError, + "calling %R should have returned an instance of " + "BaseException, not %R", + type, Py_TYPE(value)); + goto bad; + } + } + } else { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto bad; + } + if (cause) { + PyObject *fixed_cause; + if (cause == Py_None) { + fixed_cause = NULL; + } else if (PyExceptionClass_Check(cause)) { + fixed_cause = PyObject_CallObject(cause, NULL); + if (fixed_cause == NULL) + goto bad; + } else if (PyExceptionInstance_Check(cause)) { + fixed_cause = cause; + Py_INCREF(fixed_cause); + } else { + PyErr_SetString(PyExc_TypeError, + "exception causes must derive from " + "BaseException"); + goto bad; + } + PyException_SetCause(value, fixed_cause); + } + PyErr_SetObject(type, value); + if (tb) { + #if PY_VERSION_HEX >= 0x030C00A6 + PyException_SetTraceback(value, tb); + #elif CYTHON_FAST_THREAD_STATE + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject* tmp_tb = tstate->curexc_traceback; + if (tb != tmp_tb) { + Py_INCREF(tb); + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_tb); + } +#else + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); + Py_INCREF(tb); + PyErr_Restore(tmp_type, tmp_value, tb); + Py_XDECREF(tmp_tb); +#endif + } +bad: + Py_XDECREF(owned_instance); + return; +} +#endif + +/* GetItemInt */ +static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { + PyObject *r; + if (unlikely(!j)) return NULL; + r = PyObject_GetItem(o, j); + Py_DECREF(j); + return r; +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + Py_ssize_t wrapped_i = i; + if (wraparound & unlikely(i < 0)) { + wrapped_i += PyList_GET_SIZE(o); + } + if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, wrapped_i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + Py_ssize_t wrapped_i = i; + if (wraparound & unlikely(i < 0)) { + wrapped_i += PyTuple_GET_SIZE(o); + } + if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, wrapped_i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS + if (is_list || PyList_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); + if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) { + PyObject *r = PyList_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } + else if (PyTuple_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); + if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } else { + PyMappingMethods *mm = Py_TYPE(o)->tp_as_mapping; + PySequenceMethods *sm = Py_TYPE(o)->tp_as_sequence; + if (mm && mm->mp_subscript) { + PyObject *r, *key = PyInt_FromSsize_t(i); + if (unlikely(!key)) return NULL; + r = mm->mp_subscript(o, key); + Py_DECREF(key); + return r; + } + if (likely(sm && sm->sq_item)) { + if (wraparound && unlikely(i < 0) && likely(sm->sq_length)) { + Py_ssize_t l = sm->sq_length(o); + if (likely(l >= 0)) { + i += l; + } else { + if (!PyErr_ExceptionMatches(PyExc_OverflowError)) + return NULL; + PyErr_Clear(); + } + } + return sm->sq_item(o, i); + } + } +#else + if (is_list || !PyMapping_Check(o)) { + return PySequence_GetItem(o, i); + } +#endif + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} + +/* GetAttr */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) { +#if CYTHON_USE_TYPE_SLOTS +#if PY_MAJOR_VERSION >= 3 + if (likely(PyUnicode_Check(n))) +#else + if (likely(PyString_Check(n))) +#endif + return __Pyx_PyObject_GetAttrStr(o, n); +#endif + return PyObject_GetAttr(o, n); +} + +/* HasAttr */ +static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) { + PyObject *r; + if (unlikely(!__Pyx_PyBaseString_Check(n))) { + PyErr_SetString(PyExc_TypeError, + "hasattr(): attribute name must be string"); + return -1; + } + r = __Pyx_GetAttr(o, n); + if (!r) { + PyErr_Clear(); + return 0; + } else { + Py_DECREF(r); + return 1; + } +} + +/* FixUpExtensionType */ +#if CYTHON_USE_TYPE_SPECS +static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type) { +#if PY_VERSION_HEX > 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + CYTHON_UNUSED_VAR(spec); + CYTHON_UNUSED_VAR(type); +#else + const PyType_Slot *slot = spec->slots; + while (slot && slot->slot && slot->slot != Py_tp_members) + slot++; + if (slot && slot->slot == Py_tp_members) { + int changed = 0; +#if !(PY_VERSION_HEX <= 0x030900b1 && CYTHON_COMPILING_IN_CPYTHON) + const +#endif + PyMemberDef *memb = (PyMemberDef*) slot->pfunc; + while (memb && memb->name) { + if (memb->name[0] == '_' && memb->name[1] == '_') { +#if PY_VERSION_HEX < 0x030900b1 + if (strcmp(memb->name, "__weaklistoffset__") == 0) { + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); + type->tp_weaklistoffset = memb->offset; + changed = 1; + } + else if (strcmp(memb->name, "__dictoffset__") == 0) { + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); + type->tp_dictoffset = memb->offset; + changed = 1; + } +#if CYTHON_METH_FASTCALL + else if (strcmp(memb->name, "__vectorcalloffset__") == 0) { + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); +#if PY_VERSION_HEX >= 0x030800b4 + type->tp_vectorcall_offset = memb->offset; +#else + type->tp_print = (printfunc) memb->offset; +#endif + changed = 1; + } +#endif +#else + if ((0)); +#endif +#if PY_VERSION_HEX <= 0x030900b1 && CYTHON_COMPILING_IN_CPYTHON + else if (strcmp(memb->name, "__module__") == 0) { + PyObject *descr; + assert(memb->type == T_OBJECT); + assert(memb->flags == 0 || memb->flags == READONLY); + descr = PyDescr_NewMember(type, memb); + if (unlikely(!descr)) + return -1; + if (unlikely(PyDict_SetItem(type->tp_dict, PyDescr_NAME(descr), descr) < 0)) { + Py_DECREF(descr); + return -1; + } + Py_DECREF(descr); + changed = 1; + } +#endif + } + memb++; + } + if (changed) + PyType_Modified(type); + } +#endif + return 0; +} +#endif + +/* PyObjectCallNoArg */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { + PyObject *arg[2] = {NULL, NULL}; + return __Pyx_PyObject_FastCall(func, arg + 1, 0 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET); +} + +/* PyObjectCallOneArg */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { + PyObject *args[2] = {NULL, arg}; + return __Pyx_PyObject_FastCall(func, args+1, 1 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET); +} + +/* PyObjectGetMethod */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) { + PyObject *attr; +#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP + __Pyx_TypeName type_name; + PyTypeObject *tp = Py_TYPE(obj); + PyObject *descr; + descrgetfunc f = NULL; + PyObject **dictptr, *dict; + int meth_found = 0; + assert (*method == NULL); + if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) { + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; + } + if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) { + return 0; + } + descr = _PyType_Lookup(tp, name); + if (likely(descr != NULL)) { + Py_INCREF(descr); +#if defined(Py_TPFLAGS_METHOD_DESCRIPTOR) && Py_TPFLAGS_METHOD_DESCRIPTOR + if (__Pyx_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR)) +#elif PY_MAJOR_VERSION >= 3 + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type))) + #endif +#else + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr))) + #endif +#endif + { + meth_found = 1; + } else { + f = Py_TYPE(descr)->tp_descr_get; + if (f != NULL && PyDescr_IsData(descr)) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + } + } + dictptr = _PyObject_GetDictPtr(obj); + if (dictptr != NULL && (dict = *dictptr) != NULL) { + Py_INCREF(dict); + attr = __Pyx_PyDict_GetItemStr(dict, name); + if (attr != NULL) { + Py_INCREF(attr); + Py_DECREF(dict); + Py_XDECREF(descr); + goto try_unpack; + } + Py_DECREF(dict); + } + if (meth_found) { + *method = descr; + return 1; + } + if (f != NULL) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + if (likely(descr != NULL)) { + *method = descr; + return 0; + } + type_name = __Pyx_PyType_GetName(tp); + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%U'", + type_name, name); +#else + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%.400s'", + type_name, PyString_AS_STRING(name)); +#endif + __Pyx_DECREF_TypeName(type_name); + return 0; +#else + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; +#endif +try_unpack: +#if CYTHON_UNPACK_METHODS + if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) { + PyObject *function = PyMethod_GET_FUNCTION(attr); + Py_INCREF(function); + Py_DECREF(attr); + *method = function; + return 1; + } +#endif + *method = attr; + return 0; +} + +/* PyObjectCallMethod0 */ +static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) { + PyObject *method = NULL, *result = NULL; + int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); + if (likely(is_method)) { + result = __Pyx_PyObject_CallOneArg(method, obj); + Py_DECREF(method); + return result; + } + if (unlikely(!method)) goto bad; + result = __Pyx_PyObject_CallNoArg(method); + Py_DECREF(method); +bad: + return result; +} + +/* ValidateBasesTuple */ +#if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS +static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases) { + Py_ssize_t i, n; +#if CYTHON_ASSUME_SAFE_MACROS + n = PyTuple_GET_SIZE(bases); +#else + n = PyTuple_Size(bases); + if (n < 0) return -1; +#endif + for (i = 1; i < n; i++) + { +#if CYTHON_AVOID_BORROWED_REFS + PyObject *b0 = PySequence_GetItem(bases, i); + if (!b0) return -1; +#elif CYTHON_ASSUME_SAFE_MACROS + PyObject *b0 = PyTuple_GET_ITEM(bases, i); +#else + PyObject *b0 = PyTuple_GetItem(bases, i); + if (!b0) return -1; +#endif + PyTypeObject *b; +#if PY_MAJOR_VERSION < 3 + if (PyClass_Check(b0)) + { + PyErr_Format(PyExc_TypeError, "base class '%.200s' is an old-style class", + PyString_AS_STRING(((PyClassObject*)b0)->cl_name)); +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + return -1; + } +#endif + b = (PyTypeObject*) b0; + if (!__Pyx_PyType_HasFeature(b, Py_TPFLAGS_HEAPTYPE)) + { + __Pyx_TypeName b_name = __Pyx_PyType_GetName(b); + PyErr_Format(PyExc_TypeError, + "base class '" __Pyx_FMT_TYPENAME "' is not a heap type", b_name); + __Pyx_DECREF_TypeName(b_name); +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + return -1; + } + if (dictoffset == 0) + { + Py_ssize_t b_dictoffset = 0; +#if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY + b_dictoffset = b->tp_dictoffset; +#else + PyObject *py_b_dictoffset = PyObject_GetAttrString((PyObject*)b, "__dictoffset__"); + if (!py_b_dictoffset) goto dictoffset_return; + b_dictoffset = PyLong_AsSsize_t(py_b_dictoffset); + Py_DECREF(py_b_dictoffset); + if (b_dictoffset == -1 && PyErr_Occurred()) goto dictoffset_return; +#endif + if (b_dictoffset) { + { + __Pyx_TypeName b_name = __Pyx_PyType_GetName(b); + PyErr_Format(PyExc_TypeError, + "extension type '%.200s' has no __dict__ slot, " + "but base type '" __Pyx_FMT_TYPENAME "' has: " + "either add 'cdef dict __dict__' to the extension type " + "or add '__slots__ = [...]' to the base type", + type_name, b_name); + __Pyx_DECREF_TypeName(b_name); + } +#if !(CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY) + dictoffset_return: +#endif +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + return -1; + } + } +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + } + return 0; +} +#endif + +/* PyType_Ready */ +static int __Pyx_PyType_Ready(PyTypeObject *t) { +#if CYTHON_USE_TYPE_SPECS || !(CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API) || defined(PYSTON_MAJOR_VERSION) + (void)__Pyx_PyObject_CallMethod0; +#if CYTHON_USE_TYPE_SPECS + (void)__Pyx_validate_bases_tuple; +#endif + return PyType_Ready(t); +#else + int r; + PyObject *bases = __Pyx_PyType_GetSlot(t, tp_bases, PyObject*); + if (bases && unlikely(__Pyx_validate_bases_tuple(t->tp_name, t->tp_dictoffset, bases) == -1)) + return -1; +#if PY_VERSION_HEX >= 0x03050000 && !defined(PYSTON_MAJOR_VERSION) + { + int gc_was_enabled; + #if PY_VERSION_HEX >= 0x030A00b1 + gc_was_enabled = PyGC_Disable(); + (void)__Pyx_PyObject_CallMethod0; + #else + PyObject *ret, *py_status; + PyObject *gc = NULL; + #if PY_VERSION_HEX >= 0x030700a1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM+0 >= 0x07030400) + gc = PyImport_GetModule(__pyx_kp_u_gc); + #endif + if (unlikely(!gc)) gc = PyImport_Import(__pyx_kp_u_gc); + if (unlikely(!gc)) return -1; + py_status = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_isenabled); + if (unlikely(!py_status)) { + Py_DECREF(gc); + return -1; + } + gc_was_enabled = __Pyx_PyObject_IsTrue(py_status); + Py_DECREF(py_status); + if (gc_was_enabled > 0) { + ret = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_disable); + if (unlikely(!ret)) { + Py_DECREF(gc); + return -1; + } + Py_DECREF(ret); + } else if (unlikely(gc_was_enabled == -1)) { + Py_DECREF(gc); + return -1; + } + #endif + t->tp_flags |= Py_TPFLAGS_HEAPTYPE; +#if PY_VERSION_HEX >= 0x030A0000 + t->tp_flags |= Py_TPFLAGS_IMMUTABLETYPE; +#endif +#else + (void)__Pyx_PyObject_CallMethod0; +#endif + r = PyType_Ready(t); +#if PY_VERSION_HEX >= 0x03050000 && !defined(PYSTON_MAJOR_VERSION) + t->tp_flags &= ~Py_TPFLAGS_HEAPTYPE; + #if PY_VERSION_HEX >= 0x030A00b1 + if (gc_was_enabled) + PyGC_Enable(); + #else + if (gc_was_enabled) { + PyObject *tp, *v, *tb; + PyErr_Fetch(&tp, &v, &tb); + ret = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_enable); + if (likely(ret || r == -1)) { + Py_XDECREF(ret); + PyErr_Restore(tp, v, tb); + } else { + Py_XDECREF(tp); + Py_XDECREF(v); + Py_XDECREF(tb); + r = -1; + } + } + Py_DECREF(gc); + #endif + } +#endif + return r; +#endif +} + +/* PyObject_GenericGetAttrNoDict */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) { + __Pyx_TypeName type_name = __Pyx_PyType_GetName(tp); + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%U'", + type_name, attr_name); +#else + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%.400s'", + type_name, PyString_AS_STRING(attr_name)); +#endif + __Pyx_DECREF_TypeName(type_name); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) { + PyObject *descr; + PyTypeObject *tp = Py_TYPE(obj); + if (unlikely(!PyString_Check(attr_name))) { + return PyObject_GenericGetAttr(obj, attr_name); + } + assert(!tp->tp_dictoffset); + descr = _PyType_Lookup(tp, attr_name); + if (unlikely(!descr)) { + return __Pyx_RaiseGenericGetAttributeError(tp, attr_name); + } + Py_INCREF(descr); + #if PY_MAJOR_VERSION < 3 + if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS))) + #endif + { + descrgetfunc f = Py_TYPE(descr)->tp_descr_get; + if (unlikely(f)) { + PyObject *res = f(descr, obj, (PyObject *)tp); + Py_DECREF(descr); + return res; + } + } + return descr; +} +#endif + +/* PyObject_GenericGetAttr */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) { + if (unlikely(Py_TYPE(obj)->tp_dictoffset)) { + return PyObject_GenericGetAttr(obj, attr_name); + } + return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name); +} +#endif + +/* SetupReduce */ +#if !CYTHON_COMPILING_IN_LIMITED_API +static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { + int ret; + PyObject *name_attr; + name_attr = __Pyx_PyObject_GetAttrStrNoError(meth, __pyx_n_s_name); + if (likely(name_attr)) { + ret = PyObject_RichCompareBool(name_attr, name, Py_EQ); + } else { + ret = -1; + } + if (unlikely(ret < 0)) { + PyErr_Clear(); + ret = 0; + } + Py_XDECREF(name_attr); + return ret; +} +static int __Pyx_setup_reduce(PyObject* type_obj) { + int ret = 0; + PyObject *object_reduce = NULL; + PyObject *object_getstate = NULL; + PyObject *object_reduce_ex = NULL; + PyObject *reduce = NULL; + PyObject *reduce_ex = NULL; + PyObject *reduce_cython = NULL; + PyObject *setstate = NULL; + PyObject *setstate_cython = NULL; + PyObject *getstate = NULL; +#if CYTHON_USE_PYTYPE_LOOKUP + getstate = _PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate); +#else + getstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_getstate); + if (!getstate && PyErr_Occurred()) { + goto __PYX_BAD; + } +#endif + if (getstate) { +#if CYTHON_USE_PYTYPE_LOOKUP + object_getstate = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_getstate); +#else + object_getstate = __Pyx_PyObject_GetAttrStrNoError((PyObject*)&PyBaseObject_Type, __pyx_n_s_getstate); + if (!object_getstate && PyErr_Occurred()) { + goto __PYX_BAD; + } +#endif + if (object_getstate != getstate) { + goto __PYX_GOOD; + } + } +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; +#else + object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; +#endif + reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_BAD; + if (reduce_ex == object_reduce_ex) { +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; +#else + object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; +#endif + reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD; + if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { + reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython); + if (likely(reduce_cython)) { + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + } else if (reduce == object_reduce || PyErr_Occurred()) { + goto __PYX_BAD; + } + setstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate); + if (!setstate) PyErr_Clear(); + if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) { + setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython); + if (likely(setstate_cython)) { + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + } else if (!setstate || PyErr_Occurred()) { + goto __PYX_BAD; + } + } + PyType_Modified((PyTypeObject*)type_obj); + } + } + goto __PYX_GOOD; +__PYX_BAD: + if (!PyErr_Occurred()) { + __Pyx_TypeName type_obj_name = + __Pyx_PyType_GetName((PyTypeObject*)type_obj); + PyErr_Format(PyExc_RuntimeError, + "Unable to initialize pickling for " __Pyx_FMT_TYPENAME, type_obj_name); + __Pyx_DECREF_TypeName(type_obj_name); + } + ret = -1; +__PYX_GOOD: +#if !CYTHON_USE_PYTYPE_LOOKUP + Py_XDECREF(object_reduce); + Py_XDECREF(object_reduce_ex); + Py_XDECREF(object_getstate); + Py_XDECREF(getstate); +#endif + Py_XDECREF(reduce); + Py_XDECREF(reduce_ex); + Py_XDECREF(reduce_cython); + Py_XDECREF(setstate); + Py_XDECREF(setstate_cython); + return ret; +} +#endif + +/* ImportDottedModule */ +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx__ImportDottedModule_Error(PyObject *name, PyObject *parts_tuple, Py_ssize_t count) { + PyObject *partial_name = NULL, *slice = NULL, *sep = NULL; + if (unlikely(PyErr_Occurred())) { + PyErr_Clear(); + } + if (likely(PyTuple_GET_SIZE(parts_tuple) == count)) { + partial_name = name; + } else { + slice = PySequence_GetSlice(parts_tuple, 0, count); + if (unlikely(!slice)) + goto bad; + sep = PyUnicode_FromStringAndSize(".", 1); + if (unlikely(!sep)) + goto bad; + partial_name = PyUnicode_Join(sep, slice); + } + PyErr_Format( +#if PY_MAJOR_VERSION < 3 + PyExc_ImportError, + "No module named '%s'", PyString_AS_STRING(partial_name)); +#else +#if PY_VERSION_HEX >= 0x030600B1 + PyExc_ModuleNotFoundError, +#else + PyExc_ImportError, +#endif + "No module named '%U'", partial_name); +#endif +bad: + Py_XDECREF(sep); + Py_XDECREF(slice); + Py_XDECREF(partial_name); + return NULL; +} +#endif +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx__ImportDottedModule_Lookup(PyObject *name) { + PyObject *imported_module; +#if PY_VERSION_HEX < 0x030700A1 || (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM < 0x07030400) + PyObject *modules = PyImport_GetModuleDict(); + if (unlikely(!modules)) + return NULL; + imported_module = __Pyx_PyDict_GetItemStr(modules, name); + Py_XINCREF(imported_module); +#else + imported_module = PyImport_GetModule(name); +#endif + return imported_module; +} +#endif +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple) { + Py_ssize_t i, nparts; + nparts = PyTuple_GET_SIZE(parts_tuple); + for (i=1; i < nparts && module; i++) { + PyObject *part, *submodule; +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + part = PyTuple_GET_ITEM(parts_tuple, i); +#else + part = PySequence_ITEM(parts_tuple, i); +#endif + submodule = __Pyx_PyObject_GetAttrStrNoError(module, part); +#if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) + Py_DECREF(part); +#endif + Py_DECREF(module); + module = submodule; + } + if (unlikely(!module)) { + return __Pyx__ImportDottedModule_Error(name, parts_tuple, i); + } + return module; +} +#endif +static PyObject *__Pyx__ImportDottedModule(PyObject *name, PyObject *parts_tuple) { +#if PY_MAJOR_VERSION < 3 + PyObject *module, *from_list, *star = __pyx_n_s__5; + CYTHON_UNUSED_VAR(parts_tuple); + from_list = PyList_New(1); + if (unlikely(!from_list)) + return NULL; + Py_INCREF(star); + PyList_SET_ITEM(from_list, 0, star); + module = __Pyx_Import(name, from_list, 0); + Py_DECREF(from_list); + return module; +#else + PyObject *imported_module; + PyObject *module = __Pyx_Import(name, NULL, 0); + if (!parts_tuple || unlikely(!module)) + return module; + imported_module = __Pyx__ImportDottedModule_Lookup(name); + if (likely(imported_module)) { + Py_DECREF(module); + return imported_module; + } + PyErr_Clear(); + return __Pyx_ImportDottedModule_WalkParts(module, name, parts_tuple); +#endif +} +static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030400B1 + PyObject *module = __Pyx__ImportDottedModule_Lookup(name); + if (likely(module)) { + PyObject *spec = __Pyx_PyObject_GetAttrStrNoError(module, __pyx_n_s_spec); + if (likely(spec)) { + PyObject *unsafe = __Pyx_PyObject_GetAttrStrNoError(spec, __pyx_n_s_initializing); + if (likely(!unsafe || !__Pyx_PyObject_IsTrue(unsafe))) { + Py_DECREF(spec); + spec = NULL; + } + Py_XDECREF(unsafe); + } + if (likely(!spec)) { + PyErr_Clear(); + return module; + } + Py_DECREF(spec); + Py_DECREF(module); + } else if (PyErr_Occurred()) { + PyErr_Clear(); + } +#endif + return __Pyx__ImportDottedModule(name, parts_tuple); +} + +/* FetchSharedCythonModule */ +static PyObject *__Pyx_FetchSharedCythonABIModule(void) { + return __Pyx_PyImport_AddModuleRef((char*) __PYX_ABI_MODULE_NAME); +} + +/* FetchCommonType */ +static int __Pyx_VerifyCachedType(PyObject *cached_type, + const char *name, + Py_ssize_t basicsize, + Py_ssize_t expected_basicsize) { + if (!PyType_Check(cached_type)) { + PyErr_Format(PyExc_TypeError, + "Shared Cython type %.200s is not a type object", name); + return -1; + } + if (basicsize != expected_basicsize) { + PyErr_Format(PyExc_TypeError, + "Shared Cython type %.200s has the wrong size, try recompiling", + name); + return -1; + } + return 0; +} +#if !CYTHON_USE_TYPE_SPECS +static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) { + PyObject* abi_module; + const char* object_name; + PyTypeObject *cached_type = NULL; + abi_module = __Pyx_FetchSharedCythonABIModule(); + if (!abi_module) return NULL; + object_name = strrchr(type->tp_name, '.'); + object_name = object_name ? object_name+1 : type->tp_name; + cached_type = (PyTypeObject*) PyObject_GetAttrString(abi_module, object_name); + if (cached_type) { + if (__Pyx_VerifyCachedType( + (PyObject *)cached_type, + object_name, + cached_type->tp_basicsize, + type->tp_basicsize) < 0) { + goto bad; + } + goto done; + } + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; + PyErr_Clear(); + if (PyType_Ready(type) < 0) goto bad; + if (PyObject_SetAttrString(abi_module, object_name, (PyObject *)type) < 0) + goto bad; + Py_INCREF(type); + cached_type = type; +done: + Py_DECREF(abi_module); + return cached_type; +bad: + Py_XDECREF(cached_type); + cached_type = NULL; + goto done; +} +#else +static PyTypeObject *__Pyx_FetchCommonTypeFromSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) { + PyObject *abi_module, *cached_type = NULL; + const char* object_name = strrchr(spec->name, '.'); + object_name = object_name ? object_name+1 : spec->name; + abi_module = __Pyx_FetchSharedCythonABIModule(); + if (!abi_module) return NULL; + cached_type = PyObject_GetAttrString(abi_module, object_name); + if (cached_type) { + Py_ssize_t basicsize; +#if CYTHON_COMPILING_IN_LIMITED_API + PyObject *py_basicsize; + py_basicsize = PyObject_GetAttrString(cached_type, "__basicsize__"); + if (unlikely(!py_basicsize)) goto bad; + basicsize = PyLong_AsSsize_t(py_basicsize); + Py_DECREF(py_basicsize); + py_basicsize = 0; + if (unlikely(basicsize == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad; +#else + basicsize = likely(PyType_Check(cached_type)) ? ((PyTypeObject*) cached_type)->tp_basicsize : -1; +#endif + if (__Pyx_VerifyCachedType( + cached_type, + object_name, + basicsize, + spec->basicsize) < 0) { + goto bad; + } + goto done; + } + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; + PyErr_Clear(); + CYTHON_UNUSED_VAR(module); + cached_type = __Pyx_PyType_FromModuleAndSpec(abi_module, spec, bases); + if (unlikely(!cached_type)) goto bad; + if (unlikely(__Pyx_fix_up_extension_type_from_spec(spec, (PyTypeObject *) cached_type) < 0)) goto bad; + if (PyObject_SetAttrString(abi_module, object_name, cached_type) < 0) goto bad; +done: + Py_DECREF(abi_module); + assert(cached_type == NULL || PyType_Check(cached_type)); + return (PyTypeObject *) cached_type; +bad: + Py_XDECREF(cached_type); + cached_type = NULL; + goto done; +} +#endif + +/* PyVectorcallFastCallDict */ +#if CYTHON_METH_FASTCALL +static PyObject *__Pyx_PyVectorcall_FastCallDict_kw(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw) +{ + PyObject *res = NULL; + PyObject *kwnames; + PyObject **newargs; + PyObject **kwvalues; + Py_ssize_t i, pos; + size_t j; + PyObject *key, *value; + unsigned long keys_are_strings; + Py_ssize_t nkw = PyDict_GET_SIZE(kw); + newargs = (PyObject **)PyMem_Malloc((nargs + (size_t)nkw) * sizeof(args[0])); + if (unlikely(newargs == NULL)) { + PyErr_NoMemory(); + return NULL; + } + for (j = 0; j < nargs; j++) newargs[j] = args[j]; + kwnames = PyTuple_New(nkw); + if (unlikely(kwnames == NULL)) { + PyMem_Free(newargs); + return NULL; + } + kwvalues = newargs + nargs; + pos = i = 0; + keys_are_strings = Py_TPFLAGS_UNICODE_SUBCLASS; + while (PyDict_Next(kw, &pos, &key, &value)) { + keys_are_strings &= Py_TYPE(key)->tp_flags; + Py_INCREF(key); + Py_INCREF(value); + PyTuple_SET_ITEM(kwnames, i, key); + kwvalues[i] = value; + i++; + } + if (unlikely(!keys_are_strings)) { + PyErr_SetString(PyExc_TypeError, "keywords must be strings"); + goto cleanup; + } + res = vc(func, newargs, nargs, kwnames); +cleanup: + Py_DECREF(kwnames); + for (i = 0; i < nkw; i++) + Py_DECREF(kwvalues[i]); + PyMem_Free(newargs); + return res; +} +static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw) +{ + if (likely(kw == NULL) || PyDict_GET_SIZE(kw) == 0) { + return vc(func, args, nargs, NULL); + } + return __Pyx_PyVectorcall_FastCallDict_kw(func, vc, args, nargs, kw); +} +#endif + +/* CythonFunctionShared */ +#if CYTHON_COMPILING_IN_LIMITED_API +static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc) { + if (__Pyx_CyFunction_Check(func)) { + return PyCFunction_GetFunction(((__pyx_CyFunctionObject*)func)->func) == (PyCFunction) cfunc; + } else if (PyCFunction_Check(func)) { + return PyCFunction_GetFunction(func) == (PyCFunction) cfunc; + } + return 0; +} +#else +static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc) { + return __Pyx_CyOrPyCFunction_Check(func) && __Pyx_CyOrPyCFunction_GET_FUNCTION(func) == (PyCFunction) cfunc; +} +#endif +static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj) { +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + __Pyx_Py_XDECREF_SET( + __Pyx_CyFunction_GetClassObj(f), + ((classobj) ? __Pyx_NewRef(classobj) : NULL)); +#else + __Pyx_Py_XDECREF_SET( + ((PyCMethodObject *) (f))->mm_class, + (PyTypeObject*)((classobj) ? __Pyx_NewRef(classobj) : NULL)); +#endif +} +static PyObject * +__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, void *closure) +{ + CYTHON_UNUSED_VAR(closure); + if (unlikely(op->func_doc == NULL)) { +#if CYTHON_COMPILING_IN_LIMITED_API + op->func_doc = PyObject_GetAttrString(op->func, "__doc__"); + if (unlikely(!op->func_doc)) return NULL; +#else + if (((PyCFunctionObject*)op)->m_ml->ml_doc) { +#if PY_MAJOR_VERSION >= 3 + op->func_doc = PyUnicode_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc); +#else + op->func_doc = PyString_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc); +#endif + if (unlikely(op->func_doc == NULL)) + return NULL; + } else { + Py_INCREF(Py_None); + return Py_None; + } +#endif + } + Py_INCREF(op->func_doc); + return op->func_doc; +} +static int +__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (value == NULL) { + value = Py_None; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_doc, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (unlikely(op->func_name == NULL)) { +#if CYTHON_COMPILING_IN_LIMITED_API + op->func_name = PyObject_GetAttrString(op->func, "__name__"); +#elif PY_MAJOR_VERSION >= 3 + op->func_name = PyUnicode_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name); +#else + op->func_name = PyString_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name); +#endif + if (unlikely(op->func_name == NULL)) + return NULL; + } + Py_INCREF(op->func_name); + return op->func_name; +} +static int +__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) +#else + if (unlikely(value == NULL || !PyString_Check(value))) +#endif + { + PyErr_SetString(PyExc_TypeError, + "__name__ must be set to a string object"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_name, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + Py_INCREF(op->func_qualname); + return op->func_qualname; +} +static int +__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) +#else + if (unlikely(value == NULL || !PyString_Check(value))) +#endif + { + PyErr_SetString(PyExc_TypeError, + "__qualname__ must be set to a string object"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_qualname, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (unlikely(op->func_dict == NULL)) { + op->func_dict = PyDict_New(); + if (unlikely(op->func_dict == NULL)) + return NULL; + } + Py_INCREF(op->func_dict); + return op->func_dict; +} +static int +__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (unlikely(value == NULL)) { + PyErr_SetString(PyExc_TypeError, + "function's dictionary may not be deleted"); + return -1; + } + if (unlikely(!PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "setting function's dictionary to a non-dict"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_dict, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + Py_INCREF(op->func_globals); + return op->func_globals; +} +static PyObject * +__Pyx_CyFunction_get_closure(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(op); + CYTHON_UNUSED_VAR(context); + Py_INCREF(Py_None); + return Py_None; +} +static PyObject * +__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op, void *context) +{ + PyObject* result = (op->func_code) ? op->func_code : Py_None; + CYTHON_UNUSED_VAR(context); + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) { + int result = 0; + PyObject *res = op->defaults_getter((PyObject *) op); + if (unlikely(!res)) + return -1; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + op->defaults_tuple = PyTuple_GET_ITEM(res, 0); + Py_INCREF(op->defaults_tuple); + op->defaults_kwdict = PyTuple_GET_ITEM(res, 1); + Py_INCREF(op->defaults_kwdict); + #else + op->defaults_tuple = __Pyx_PySequence_ITEM(res, 0); + if (unlikely(!op->defaults_tuple)) result = -1; + else { + op->defaults_kwdict = __Pyx_PySequence_ITEM(res, 1); + if (unlikely(!op->defaults_kwdict)) result = -1; + } + #endif + Py_DECREF(res); + return result; +} +static int +__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + if (!value) { + value = Py_None; + } else if (unlikely(value != Py_None && !PyTuple_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "__defaults__ must be set to a tuple object"); + return -1; + } + PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__defaults__ will not " + "currently affect the values used in function calls", 1); + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->defaults_tuple, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op, void *context) { + PyObject* result = op->defaults_tuple; + CYTHON_UNUSED_VAR(context); + if (unlikely(!result)) { + if (op->defaults_getter) { + if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL; + result = op->defaults_tuple; + } else { + result = Py_None; + } + } + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + if (!value) { + value = Py_None; + } else if (unlikely(value != Py_None && !PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "__kwdefaults__ must be set to a dict object"); + return -1; + } + PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__kwdefaults__ will not " + "currently affect the values used in function calls", 1); + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->defaults_kwdict, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op, void *context) { + PyObject* result = op->defaults_kwdict; + CYTHON_UNUSED_VAR(context); + if (unlikely(!result)) { + if (op->defaults_getter) { + if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL; + result = op->defaults_kwdict; + } else { + result = Py_None; + } + } + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + if (!value || value == Py_None) { + value = NULL; + } else if (unlikely(!PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "__annotations__ must be set to a dict object"); + return -1; + } + Py_XINCREF(value); + __Pyx_Py_XDECREF_SET(op->func_annotations, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op, void *context) { + PyObject* result = op->func_annotations; + CYTHON_UNUSED_VAR(context); + if (unlikely(!result)) { + result = PyDict_New(); + if (unlikely(!result)) return NULL; + op->func_annotations = result; + } + Py_INCREF(result); + return result; +} +static PyObject * +__Pyx_CyFunction_get_is_coroutine(__pyx_CyFunctionObject *op, void *context) { + int is_coroutine; + CYTHON_UNUSED_VAR(context); + if (op->func_is_coroutine) { + return __Pyx_NewRef(op->func_is_coroutine); + } + is_coroutine = op->flags & __Pyx_CYFUNCTION_COROUTINE; +#if PY_VERSION_HEX >= 0x03050000 + if (is_coroutine) { + PyObject *module, *fromlist, *marker = __pyx_n_s_is_coroutine; + fromlist = PyList_New(1); + if (unlikely(!fromlist)) return NULL; + Py_INCREF(marker); +#if CYTHON_ASSUME_SAFE_MACROS + PyList_SET_ITEM(fromlist, 0, marker); +#else + if (unlikely(PyList_SetItem(fromlist, 0, marker) < 0)) { + Py_DECREF(marker); + Py_DECREF(fromlist); + return NULL; + } +#endif + module = PyImport_ImportModuleLevelObject(__pyx_n_s_asyncio_coroutines, NULL, NULL, fromlist, 0); + Py_DECREF(fromlist); + if (unlikely(!module)) goto ignore; + op->func_is_coroutine = __Pyx_PyObject_GetAttrStr(module, marker); + Py_DECREF(module); + if (likely(op->func_is_coroutine)) { + return __Pyx_NewRef(op->func_is_coroutine); + } +ignore: + PyErr_Clear(); + } +#endif + op->func_is_coroutine = __Pyx_PyBool_FromLong(is_coroutine); + return __Pyx_NewRef(op->func_is_coroutine); +} +#if CYTHON_COMPILING_IN_LIMITED_API +static PyObject * +__Pyx_CyFunction_get_module(__pyx_CyFunctionObject *op, void *context) { + CYTHON_UNUSED_VAR(context); + return PyObject_GetAttrString(op->func, "__module__"); +} +static int +__Pyx_CyFunction_set_module(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + return PyObject_SetAttrString(op->func, "__module__", value); +} +#endif +static PyGetSetDef __pyx_CyFunction_getsets[] = { + {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, + {(char *) "__doc__", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, + {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, + {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, + {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0}, + {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, + {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, + {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, + {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, + {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, + {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, + {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, + {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, + {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, + {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, + {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0}, + {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0}, + {(char *) "_is_coroutine", (getter)__Pyx_CyFunction_get_is_coroutine, 0, 0, 0}, +#if CYTHON_COMPILING_IN_LIMITED_API + {"__module__", (getter)__Pyx_CyFunction_get_module, (setter)__Pyx_CyFunction_set_module, 0, 0}, +#endif + {0, 0, 0, 0, 0} +}; +static PyMemberDef __pyx_CyFunction_members[] = { +#if !CYTHON_COMPILING_IN_LIMITED_API + {(char *) "__module__", T_OBJECT, offsetof(PyCFunctionObject, m_module), 0, 0}, +#endif +#if CYTHON_USE_TYPE_SPECS + {(char *) "__dictoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_dict), READONLY, 0}, +#if CYTHON_METH_FASTCALL +#if CYTHON_BACKPORT_VECTORCALL + {(char *) "__vectorcalloffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_vectorcall), READONLY, 0}, +#else +#if !CYTHON_COMPILING_IN_LIMITED_API + {(char *) "__vectorcalloffset__", T_PYSSIZET, offsetof(PyCFunctionObject, vectorcall), READONLY, 0}, +#endif +#endif +#endif +#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API + {(char *) "__weaklistoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_weakreflist), READONLY, 0}, +#else + {(char *) "__weaklistoffset__", T_PYSSIZET, offsetof(PyCFunctionObject, m_weakreflist), READONLY, 0}, +#endif +#endif + {0, 0, 0, 0, 0} +}; +static PyObject * +__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, PyObject *args) +{ + CYTHON_UNUSED_VAR(args); +#if PY_MAJOR_VERSION >= 3 + Py_INCREF(m->func_qualname); + return m->func_qualname; +#else + return PyString_FromString(((PyCFunctionObject*)m)->m_ml->ml_name); +#endif +} +static PyMethodDef __pyx_CyFunction_methods[] = { + {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0}, + {0, 0, 0, 0} +}; +#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API +#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist) +#else +#define __Pyx_CyFunction_weakreflist(cyfunc) (((PyCFunctionObject*)cyfunc)->m_weakreflist) +#endif +static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject *op, PyMethodDef *ml, int flags, PyObject* qualname, + PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { +#if !CYTHON_COMPILING_IN_LIMITED_API + PyCFunctionObject *cf = (PyCFunctionObject*) op; +#endif + if (unlikely(op == NULL)) + return NULL; +#if CYTHON_COMPILING_IN_LIMITED_API + op->func = PyCFunction_NewEx(ml, (PyObject*)op, module); + if (unlikely(!op->func)) return NULL; +#endif + op->flags = flags; + __Pyx_CyFunction_weakreflist(op) = NULL; +#if !CYTHON_COMPILING_IN_LIMITED_API + cf->m_ml = ml; + cf->m_self = (PyObject *) op; +#endif + Py_XINCREF(closure); + op->func_closure = closure; +#if !CYTHON_COMPILING_IN_LIMITED_API + Py_XINCREF(module); + cf->m_module = module; +#endif + op->func_dict = NULL; + op->func_name = NULL; + Py_INCREF(qualname); + op->func_qualname = qualname; + op->func_doc = NULL; +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + op->func_classobj = NULL; +#else + ((PyCMethodObject*)op)->mm_class = NULL; +#endif + op->func_globals = globals; + Py_INCREF(op->func_globals); + Py_XINCREF(code); + op->func_code = code; + op->defaults_pyobjects = 0; + op->defaults_size = 0; + op->defaults = NULL; + op->defaults_tuple = NULL; + op->defaults_kwdict = NULL; + op->defaults_getter = NULL; + op->func_annotations = NULL; + op->func_is_coroutine = NULL; +#if CYTHON_METH_FASTCALL + switch (ml->ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O | METH_KEYWORDS | METH_METHOD)) { + case METH_NOARGS: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_NOARGS; + break; + case METH_O: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_O; + break; + case METH_METHOD | METH_FASTCALL | METH_KEYWORDS: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD; + break; + case METH_FASTCALL | METH_KEYWORDS: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS; + break; + case METH_VARARGS | METH_KEYWORDS: + __Pyx_CyFunction_func_vectorcall(op) = NULL; + break; + default: + PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction"); + Py_DECREF(op); + return NULL; + } +#endif + return (PyObject *) op; +} +static int +__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m) +{ + Py_CLEAR(m->func_closure); +#if CYTHON_COMPILING_IN_LIMITED_API + Py_CLEAR(m->func); +#else + Py_CLEAR(((PyCFunctionObject*)m)->m_module); +#endif + Py_CLEAR(m->func_dict); + Py_CLEAR(m->func_name); + Py_CLEAR(m->func_qualname); + Py_CLEAR(m->func_doc); + Py_CLEAR(m->func_globals); + Py_CLEAR(m->func_code); +#if !CYTHON_COMPILING_IN_LIMITED_API +#if PY_VERSION_HEX < 0x030900B1 + Py_CLEAR(__Pyx_CyFunction_GetClassObj(m)); +#else + { + PyObject *cls = (PyObject*) ((PyCMethodObject *) (m))->mm_class; + ((PyCMethodObject *) (m))->mm_class = NULL; + Py_XDECREF(cls); + } +#endif +#endif + Py_CLEAR(m->defaults_tuple); + Py_CLEAR(m->defaults_kwdict); + Py_CLEAR(m->func_annotations); + Py_CLEAR(m->func_is_coroutine); + if (m->defaults) { + PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); + int i; + for (i = 0; i < m->defaults_pyobjects; i++) + Py_XDECREF(pydefaults[i]); + PyObject_Free(m->defaults); + m->defaults = NULL; + } + return 0; +} +static void __Pyx__CyFunction_dealloc(__pyx_CyFunctionObject *m) +{ + if (__Pyx_CyFunction_weakreflist(m) != NULL) + PyObject_ClearWeakRefs((PyObject *) m); + __Pyx_CyFunction_clear(m); + __Pyx_PyHeapTypeObject_GC_Del(m); +} +static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m) +{ + PyObject_GC_UnTrack(m); + __Pyx__CyFunction_dealloc(m); +} +static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg) +{ + Py_VISIT(m->func_closure); +#if CYTHON_COMPILING_IN_LIMITED_API + Py_VISIT(m->func); +#else + Py_VISIT(((PyCFunctionObject*)m)->m_module); +#endif + Py_VISIT(m->func_dict); + Py_VISIT(m->func_name); + Py_VISIT(m->func_qualname); + Py_VISIT(m->func_doc); + Py_VISIT(m->func_globals); + Py_VISIT(m->func_code); +#if !CYTHON_COMPILING_IN_LIMITED_API + Py_VISIT(__Pyx_CyFunction_GetClassObj(m)); +#endif + Py_VISIT(m->defaults_tuple); + Py_VISIT(m->defaults_kwdict); + Py_VISIT(m->func_is_coroutine); + if (m->defaults) { + PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); + int i; + for (i = 0; i < m->defaults_pyobjects; i++) + Py_VISIT(pydefaults[i]); + } + return 0; +} +static PyObject* +__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op) +{ +#if PY_MAJOR_VERSION >= 3 + return PyUnicode_FromFormat("", + op->func_qualname, (void *)op); +#else + return PyString_FromFormat("", + PyString_AsString(op->func_qualname), (void *)op); +#endif +} +static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) { +#if CYTHON_COMPILING_IN_LIMITED_API + PyObject *f = ((__pyx_CyFunctionObject*)func)->func; + PyObject *py_name = NULL; + PyCFunction meth; + int flags; + meth = PyCFunction_GetFunction(f); + if (unlikely(!meth)) return NULL; + flags = PyCFunction_GetFlags(f); + if (unlikely(flags < 0)) return NULL; +#else + PyCFunctionObject* f = (PyCFunctionObject*)func; + PyCFunction meth = f->m_ml->ml_meth; + int flags = f->m_ml->ml_flags; +#endif + Py_ssize_t size; + switch (flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) { + case METH_VARARGS: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) + return (*meth)(self, arg); + break; + case METH_VARARGS | METH_KEYWORDS: + return (*(PyCFunctionWithKeywords)(void*)meth)(self, arg, kw); + case METH_NOARGS: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) { +#if CYTHON_ASSUME_SAFE_MACROS + size = PyTuple_GET_SIZE(arg); +#else + size = PyTuple_Size(arg); + if (unlikely(size < 0)) return NULL; +#endif + if (likely(size == 0)) + return (*meth)(self, NULL); +#if CYTHON_COMPILING_IN_LIMITED_API + py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); + if (!py_name) return NULL; + PyErr_Format(PyExc_TypeError, + "%.200S() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + py_name, size); + Py_DECREF(py_name); +#else + PyErr_Format(PyExc_TypeError, + "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + f->m_ml->ml_name, size); +#endif + return NULL; + } + break; + case METH_O: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) { +#if CYTHON_ASSUME_SAFE_MACROS + size = PyTuple_GET_SIZE(arg); +#else + size = PyTuple_Size(arg); + if (unlikely(size < 0)) return NULL; +#endif + if (likely(size == 1)) { + PyObject *result, *arg0; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + arg0 = PyTuple_GET_ITEM(arg, 0); + #else + arg0 = __Pyx_PySequence_ITEM(arg, 0); if (unlikely(!arg0)) return NULL; + #endif + result = (*meth)(self, arg0); + #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) + Py_DECREF(arg0); + #endif + return result; + } +#if CYTHON_COMPILING_IN_LIMITED_API + py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); + if (!py_name) return NULL; + PyErr_Format(PyExc_TypeError, + "%.200S() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + py_name, size); + Py_DECREF(py_name); +#else + PyErr_Format(PyExc_TypeError, + "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + f->m_ml->ml_name, size); +#endif + return NULL; + } + break; + default: + PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction"); + return NULL; + } +#if CYTHON_COMPILING_IN_LIMITED_API + py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); + if (!py_name) return NULL; + PyErr_Format(PyExc_TypeError, "%.200S() takes no keyword arguments", + py_name); + Py_DECREF(py_name); +#else + PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments", + f->m_ml->ml_name); +#endif + return NULL; +} +static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *self, *result; +#if CYTHON_COMPILING_IN_LIMITED_API + self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)func)->func); + if (unlikely(!self) && PyErr_Occurred()) return NULL; +#else + self = ((PyCFunctionObject*)func)->m_self; +#endif + result = __Pyx_CyFunction_CallMethod(func, self, arg, kw); + return result; +} +static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) { + PyObject *result; + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func; +#if CYTHON_METH_FASTCALL + __pyx_vectorcallfunc vc = __Pyx_CyFunction_func_vectorcall(cyfunc); + if (vc) { +#if CYTHON_ASSUME_SAFE_MACROS + return __Pyx_PyVectorcall_FastCallDict(func, vc, &PyTuple_GET_ITEM(args, 0), (size_t)PyTuple_GET_SIZE(args), kw); +#else + (void) &__Pyx_PyVectorcall_FastCallDict; + return PyVectorcall_Call(func, args, kw); +#endif + } +#endif + if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { + Py_ssize_t argc; + PyObject *new_args; + PyObject *self; +#if CYTHON_ASSUME_SAFE_MACROS + argc = PyTuple_GET_SIZE(args); +#else + argc = PyTuple_Size(args); + if (unlikely(!argc) < 0) return NULL; +#endif + new_args = PyTuple_GetSlice(args, 1, argc); + if (unlikely(!new_args)) + return NULL; + self = PyTuple_GetItem(args, 0); + if (unlikely(!self)) { + Py_DECREF(new_args); +#if PY_MAJOR_VERSION > 2 + PyErr_Format(PyExc_TypeError, + "unbound method %.200S() needs an argument", + cyfunc->func_qualname); +#else + PyErr_SetString(PyExc_TypeError, + "unbound method needs an argument"); +#endif + return NULL; + } + result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw); + Py_DECREF(new_args); + } else { + result = __Pyx_CyFunction_Call(func, args, kw); + } + return result; +} +#if CYTHON_METH_FASTCALL +static CYTHON_INLINE int __Pyx_CyFunction_Vectorcall_CheckArgs(__pyx_CyFunctionObject *cyfunc, Py_ssize_t nargs, PyObject *kwnames) +{ + int ret = 0; + if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { + if (unlikely(nargs < 1)) { + PyErr_Format(PyExc_TypeError, "%.200s() needs an argument", + ((PyCFunctionObject*)cyfunc)->m_ml->ml_name); + return -1; + } + ret = 1; + } + if (unlikely(kwnames) && unlikely(PyTuple_GET_SIZE(kwnames))) { + PyErr_Format(PyExc_TypeError, + "%.200s() takes no keyword arguments", ((PyCFunctionObject*)cyfunc)->m_ml->ml_name); + return -1; + } + return ret; +} +static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + if (unlikely(nargs != 0)) { + PyErr_Format(PyExc_TypeError, + "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + def->ml_name, nargs); + return NULL; + } + return def->ml_meth(self, NULL); +} +static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + if (unlikely(nargs != 1)) { + PyErr_Format(PyExc_TypeError, + "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + def->ml_name, nargs); + return NULL; + } + return def->ml_meth(self, args[0]); +} +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + return ((__Pyx_PyCFunctionFastWithKeywords)(void(*)(void))def->ml_meth)(self, args, nargs, kwnames); +} +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; + PyTypeObject *cls = (PyTypeObject *) __Pyx_CyFunction_GetClassObj(cyfunc); +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + return ((__Pyx_PyCMethod)(void(*)(void))def->ml_meth)(self, cls, args, (size_t)nargs, kwnames); +} +#endif +#if CYTHON_USE_TYPE_SPECS +static PyType_Slot __pyx_CyFunctionType_slots[] = { + {Py_tp_dealloc, (void *)__Pyx_CyFunction_dealloc}, + {Py_tp_repr, (void *)__Pyx_CyFunction_repr}, + {Py_tp_call, (void *)__Pyx_CyFunction_CallAsMethod}, + {Py_tp_traverse, (void *)__Pyx_CyFunction_traverse}, + {Py_tp_clear, (void *)__Pyx_CyFunction_clear}, + {Py_tp_methods, (void *)__pyx_CyFunction_methods}, + {Py_tp_members, (void *)__pyx_CyFunction_members}, + {Py_tp_getset, (void *)__pyx_CyFunction_getsets}, + {Py_tp_descr_get, (void *)__Pyx_PyMethod_New}, + {0, 0}, +}; +static PyType_Spec __pyx_CyFunctionType_spec = { + __PYX_TYPE_MODULE_PREFIX "cython_function_or_method", + sizeof(__pyx_CyFunctionObject), + 0, +#ifdef Py_TPFLAGS_METHOD_DESCRIPTOR + Py_TPFLAGS_METHOD_DESCRIPTOR | +#endif +#if (defined(_Py_TPFLAGS_HAVE_VECTORCALL) && CYTHON_METH_FASTCALL) + _Py_TPFLAGS_HAVE_VECTORCALL | +#endif + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, + __pyx_CyFunctionType_slots +}; +#else +static PyTypeObject __pyx_CyFunctionType_type = { + PyVarObject_HEAD_INIT(0, 0) + __PYX_TYPE_MODULE_PREFIX "cython_function_or_method", + sizeof(__pyx_CyFunctionObject), + 0, + (destructor) __Pyx_CyFunction_dealloc, +#if !CYTHON_METH_FASTCALL + 0, +#elif CYTHON_BACKPORT_VECTORCALL + (printfunc)offsetof(__pyx_CyFunctionObject, func_vectorcall), +#else + offsetof(PyCFunctionObject, vectorcall), +#endif + 0, + 0, +#if PY_MAJOR_VERSION < 3 + 0, +#else + 0, +#endif + (reprfunc) __Pyx_CyFunction_repr, + 0, + 0, + 0, + 0, + __Pyx_CyFunction_CallAsMethod, + 0, + 0, + 0, + 0, +#ifdef Py_TPFLAGS_METHOD_DESCRIPTOR + Py_TPFLAGS_METHOD_DESCRIPTOR | +#endif +#if defined(_Py_TPFLAGS_HAVE_VECTORCALL) && CYTHON_METH_FASTCALL + _Py_TPFLAGS_HAVE_VECTORCALL | +#endif + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, + 0, + (traverseproc) __Pyx_CyFunction_traverse, + (inquiry) __Pyx_CyFunction_clear, + 0, +#if PY_VERSION_HEX < 0x030500A0 + offsetof(__pyx_CyFunctionObject, func_weakreflist), +#else + offsetof(PyCFunctionObject, m_weakreflist), +#endif + 0, + 0, + __pyx_CyFunction_methods, + __pyx_CyFunction_members, + __pyx_CyFunction_getsets, + 0, + 0, + __Pyx_PyMethod_New, + 0, + offsetof(__pyx_CyFunctionObject, func_dict), + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +#if PY_VERSION_HEX >= 0x030400a1 + 0, +#endif +#if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) + 0, +#endif +#if __PYX_NEED_TP_PRINT_SLOT + 0, +#endif +#if PY_VERSION_HEX >= 0x030C0000 + 0, +#endif +#if PY_VERSION_HEX >= 0x030d00A4 + 0, +#endif +#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 + 0, +#endif +}; +#endif +static int __pyx_CyFunction_init(PyObject *module) { +#if CYTHON_USE_TYPE_SPECS + __pyx_CyFunctionType = __Pyx_FetchCommonTypeFromSpec(module, &__pyx_CyFunctionType_spec, NULL); +#else + CYTHON_UNUSED_VAR(module); + __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type); +#endif + if (unlikely(__pyx_CyFunctionType == NULL)) { + return -1; + } + return 0; +} +static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults = PyObject_Malloc(size); + if (unlikely(!m->defaults)) + return PyErr_NoMemory(); + memset(m->defaults, 0, size); + m->defaults_pyobjects = pyobjects; + m->defaults_size = size; + return m->defaults; +} +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults_tuple = tuple; + Py_INCREF(tuple); +} +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults_kwdict = dict; + Py_INCREF(dict); +} +static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->func_annotations = dict; + Py_INCREF(dict); +} + +/* CythonFunction */ +static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, int flags, PyObject* qualname, + PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { + PyObject *op = __Pyx_CyFunction_Init( + PyObject_GC_New(__pyx_CyFunctionObject, __pyx_CyFunctionType), + ml, flags, qualname, closure, module, globals, code + ); + if (likely(op)) { + PyObject_GC_Track(op); + } + return op; +} + +/* CLineInTraceback */ +#ifndef CYTHON_CLINE_IN_TRACEBACK +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line) { + PyObject *use_cline; + PyObject *ptype, *pvalue, *ptraceback; +#if CYTHON_COMPILING_IN_CPYTHON + PyObject **cython_runtime_dict; +#endif + CYTHON_MAYBE_UNUSED_VAR(tstate); + if (unlikely(!__pyx_cython_runtime)) { + return c_line; + } + __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); +#if CYTHON_COMPILING_IN_CPYTHON + cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime); + if (likely(cython_runtime_dict)) { + __PYX_PY_DICT_LOOKUP_IF_MODIFIED( + use_cline, *cython_runtime_dict, + __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback)) + } else +#endif + { + PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStrNoError(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback); + if (use_cline_obj) { + use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True; + Py_DECREF(use_cline_obj); + } else { + PyErr_Clear(); + use_cline = NULL; + } + } + if (!use_cline) { + c_line = 0; + (void) PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False); + } + else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) { + c_line = 0; + } + __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); + return c_line; +} +#endif + +/* CodeObjectCache */ +#if !CYTHON_COMPILING_IN_LIMITED_API +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { + int start = 0, mid = 0, end = count - 1; + if (end >= 0 && code_line > entries[end].code_line) { + return count; + } + while (start < end) { + mid = start + (end - start) / 2; + if (code_line < entries[mid].code_line) { + end = mid; + } else if (code_line > entries[mid].code_line) { + start = mid + 1; + } else { + return mid; + } + } + if (code_line <= entries[mid].code_line) { + return mid; + } else { + return mid + 1; + } +} +static PyCodeObject *__pyx_find_code_object(int code_line) { + PyCodeObject* code_object; + int pos; + if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { + return NULL; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { + return NULL; + } + code_object = __pyx_code_cache.entries[pos].code_object; + Py_INCREF(code_object); + return code_object; +} +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { + int pos, i; + __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; + if (unlikely(!code_line)) { + return; + } + if (unlikely(!entries)) { + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); + if (likely(entries)) { + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = 64; + __pyx_code_cache.count = 1; + entries[0].code_line = code_line; + entries[0].code_object = code_object; + Py_INCREF(code_object); + } + return; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { + PyCodeObject* tmp = entries[pos].code_object; + entries[pos].code_object = code_object; + Py_DECREF(tmp); + return; + } + if (__pyx_code_cache.count == __pyx_code_cache.max_count) { + int new_max = __pyx_code_cache.max_count + 64; + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( + __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry)); + if (unlikely(!entries)) { + return; + } + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = new_max; + } + for (i=__pyx_code_cache.count; i>pos; i--) { + entries[i] = entries[i-1]; + } + entries[pos].code_line = code_line; + entries[pos].code_object = code_object; + __pyx_code_cache.count++; + Py_INCREF(code_object); +} +#endif + +/* AddTraceback */ +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" +#if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API + #ifndef Py_BUILD_CORE + #define Py_BUILD_CORE 1 + #endif + #include "internal/pycore_frame.h" +#endif +#if CYTHON_COMPILING_IN_LIMITED_API +static PyObject *__Pyx_PyCode_Replace_For_AddTraceback(PyObject *code, PyObject *scratch_dict, + PyObject *firstlineno, PyObject *name) { + PyObject *replace = NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "co_firstlineno", firstlineno))) return NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "co_name", name))) return NULL; + replace = PyObject_GetAttrString(code, "replace"); + if (likely(replace)) { + PyObject *result; + result = PyObject_Call(replace, __pyx_empty_tuple, scratch_dict); + Py_DECREF(replace); + return result; + } + PyErr_Clear(); + #if __PYX_LIMITED_VERSION_HEX < 0x030780000 + { + PyObject *compiled = NULL, *result = NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "code", code))) return NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "type", (PyObject*)(&PyType_Type)))) return NULL; + compiled = Py_CompileString( + "out = type(code)(\n" + " code.co_argcount, code.co_kwonlyargcount, code.co_nlocals, code.co_stacksize,\n" + " code.co_flags, code.co_code, code.co_consts, code.co_names,\n" + " code.co_varnames, code.co_filename, co_name, co_firstlineno,\n" + " code.co_lnotab)\n", "", Py_file_input); + if (!compiled) return NULL; + result = PyEval_EvalCode(compiled, scratch_dict, scratch_dict); + Py_DECREF(compiled); + if (!result) PyErr_Print(); + Py_DECREF(result); + result = PyDict_GetItemString(scratch_dict, "out"); + if (result) Py_INCREF(result); + return result; + } + #else + return NULL; + #endif +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyObject *code_object = NULL, *py_py_line = NULL, *py_funcname = NULL, *dict = NULL; + PyObject *replace = NULL, *getframe = NULL, *frame = NULL; + PyObject *exc_type, *exc_value, *exc_traceback; + int success = 0; + if (c_line) { + (void) __pyx_cfilenm; + (void) __Pyx_CLineForTraceback(__Pyx_PyThreadState_Current, c_line); + } + PyErr_Fetch(&exc_type, &exc_value, &exc_traceback); + code_object = Py_CompileString("_getframe()", filename, Py_eval_input); + if (unlikely(!code_object)) goto bad; + py_py_line = PyLong_FromLong(py_line); + if (unlikely(!py_py_line)) goto bad; + py_funcname = PyUnicode_FromString(funcname); + if (unlikely(!py_funcname)) goto bad; + dict = PyDict_New(); + if (unlikely(!dict)) goto bad; + { + PyObject *old_code_object = code_object; + code_object = __Pyx_PyCode_Replace_For_AddTraceback(code_object, dict, py_py_line, py_funcname); + Py_DECREF(old_code_object); + } + if (unlikely(!code_object)) goto bad; + getframe = PySys_GetObject("_getframe"); + if (unlikely(!getframe)) goto bad; + if (unlikely(PyDict_SetItemString(dict, "_getframe", getframe))) goto bad; + frame = PyEval_EvalCode(code_object, dict, dict); + if (unlikely(!frame) || frame == Py_None) goto bad; + success = 1; + bad: + PyErr_Restore(exc_type, exc_value, exc_traceback); + Py_XDECREF(code_object); + Py_XDECREF(py_py_line); + Py_XDECREF(py_funcname); + Py_XDECREF(dict); + Py_XDECREF(replace); + if (success) { + PyTraceBack_Here( + (struct _frame*)frame); + } + Py_XDECREF(frame); +} +#else +static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( + const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = NULL; + PyObject *py_funcname = NULL; + #if PY_MAJOR_VERSION < 3 + PyObject *py_srcfile = NULL; + py_srcfile = PyString_FromString(filename); + if (!py_srcfile) goto bad; + #endif + if (c_line) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + if (!py_funcname) goto bad; + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + if (!py_funcname) goto bad; + funcname = PyUnicode_AsUTF8(py_funcname); + if (!funcname) goto bad; + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + if (!py_funcname) goto bad; + #endif + } + #if PY_MAJOR_VERSION < 3 + py_code = __Pyx_PyCode_New( + 0, + 0, + 0, + 0, + 0, + 0, + __pyx_empty_bytes, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + py_line, + __pyx_empty_bytes /*PyObject *lnotab*/ + ); + Py_DECREF(py_srcfile); + #else + py_code = PyCode_NewEmpty(filename, funcname, py_line); + #endif + Py_XDECREF(py_funcname); + return py_code; +bad: + Py_XDECREF(py_funcname); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(py_srcfile); + #endif + return NULL; +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject *ptype, *pvalue, *ptraceback; + if (c_line) { + c_line = __Pyx_CLineForTraceback(tstate, c_line); + } + py_code = __pyx_find_code_object(c_line ? -c_line : py_line); + if (!py_code) { + __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); + py_code = __Pyx_CreateCodeObjectForTraceback( + funcname, c_line, py_line, filename); + if (!py_code) { + /* If the code object creation fails, then we should clear the + fetched exception references and propagate the new exception */ + Py_XDECREF(ptype); + Py_XDECREF(pvalue); + Py_XDECREF(ptraceback); + goto bad; + } + __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); + __pyx_insert_code_object(c_line ? -c_line : py_line, py_code); + } + py_frame = PyFrame_New( + tstate, /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + __pyx_d, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + __Pyx_PyFrame_SetLineNumber(py_frame, py_line); + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} +#endif + +/* CIntFromPyVerify */ +#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) +#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) +#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ + {\ + func_type value = func_value;\ + if (sizeof(target_type) < sizeof(func_type)) {\ + if (unlikely(value != (func_type) (target_type) value)) {\ + func_type zero = 0;\ + if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ + return (target_type) -1;\ + if (is_unsigned && unlikely(value < zero))\ + goto raise_neg_overflow;\ + else\ + goto raise_overflow;\ + }\ + }\ + return (target_type) value;\ + } + +/* CIntFromPy */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if ((sizeof(long) < sizeof(long))) { + __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (long) val; + } + } +#endif + if (unlikely(!PyLong_Check(x))) { + long val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (long) -1; + val = __Pyx_PyInt_As_long(tmp); + Py_DECREF(tmp); + return val; + } + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + if (unlikely(__Pyx_PyLong_IsNeg(x))) { + goto raise_neg_overflow; + } else if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_DigitCount(x)) { + case 2: + if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) >= 2 * PyLong_SHIFT)) { + return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 3: + if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) >= 3 * PyLong_SHIFT)) { + return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 4: + if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) >= 4 * PyLong_SHIFT)) { + return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + } + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7 + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (long) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if ((sizeof(long) <= sizeof(unsigned long))) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(long) <= sizeof(unsigned PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_SignedDigitCount(x)) { + case -2: + if ((8 * sizeof(long) - 1 > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) { + return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 2: + if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) { + return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -3: + if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) { + return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 3: + if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) { + return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -4: + if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) { + return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 4: + if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) { + return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + } + } +#endif + if ((sizeof(long) <= sizeof(long))) { + __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(long) <= sizeof(PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { + long val; + int ret = -1; +#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API + Py_ssize_t bytes_copied = PyLong_AsNativeBytes( + x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0)); + if (unlikely(bytes_copied == -1)) { + } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) { + goto raise_overflow; + } else { + ret = 0; + } +#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray) + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + ret = _PyLong_AsByteArray((PyLongObject *)x, + bytes, sizeof(val), + is_little, !is_unsigned); +#else + PyObject *v; + PyObject *stepval = NULL, *mask = NULL, *shift = NULL; + int bits, remaining_bits, is_negative = 0; + int chunk_size = (sizeof(long) < 8) ? 30 : 62; + if (likely(PyLong_CheckExact(x))) { + v = __Pyx_NewRef(x); + } else { + v = PyNumber_Long(x); + if (unlikely(!v)) return (long) -1; + assert(PyLong_CheckExact(v)); + } + { + int result = PyObject_RichCompareBool(v, Py_False, Py_LT); + if (unlikely(result < 0)) { + Py_DECREF(v); + return (long) -1; + } + is_negative = result == 1; + } + if (is_unsigned && unlikely(is_negative)) { + Py_DECREF(v); + goto raise_neg_overflow; + } else if (is_negative) { + stepval = PyNumber_Invert(v); + Py_DECREF(v); + if (unlikely(!stepval)) + return (long) -1; + } else { + stepval = v; + } + v = NULL; + val = (long) 0; + mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done; + shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done; + for (bits = 0; bits < (int) sizeof(long) * 8 - chunk_size; bits += chunk_size) { + PyObject *tmp, *digit; + long idigit; + digit = PyNumber_And(stepval, mask); + if (unlikely(!digit)) goto done; + idigit = PyLong_AsLong(digit); + Py_DECREF(digit); + if (unlikely(idigit < 0)) goto done; + val |= ((long) idigit) << bits; + tmp = PyNumber_Rshift(stepval, shift); + if (unlikely(!tmp)) goto done; + Py_DECREF(stepval); stepval = tmp; + } + Py_DECREF(shift); shift = NULL; + Py_DECREF(mask); mask = NULL; + { + long idigit = PyLong_AsLong(stepval); + if (unlikely(idigit < 0)) goto done; + remaining_bits = ((int) sizeof(long) * 8) - bits - (is_unsigned ? 0 : 1); + if (unlikely(idigit >= (1L << remaining_bits))) + goto raise_overflow; + val |= ((long) idigit) << bits; + } + if (!is_unsigned) { + if (unlikely(val & (((long) 1) << (sizeof(long) * 8 - 1)))) + goto raise_overflow; + if (is_negative) + val = ~val; + } + ret = 0; + done: + Py_XDECREF(shift); + Py_XDECREF(mask); + Py_XDECREF(stepval); +#endif + if (unlikely(ret)) + return (long) -1; + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to long"); + return (long) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long) -1; +} + +/* CIntToPy */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(long) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(long) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + unsigned char *bytes = (unsigned char *)&value; +#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4 + if (is_unsigned) { + return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1); + } else { + return PyLong_FromNativeBytes(bytes, sizeof(value), -1); + } +#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000 + int one = 1; int little = (int)*(unsigned char *)&one; + return _PyLong_FromByteArray(bytes, sizeof(long), + little, !is_unsigned); +#else + int one = 1; int little = (int)*(unsigned char *)&one; + PyObject *from_bytes, *result = NULL; + PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL; + from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes"); + if (!from_bytes) return NULL; + py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(long)); + if (!py_bytes) goto limited_bad; + order_str = PyUnicode_FromString(little ? "little" : "big"); + if (!order_str) goto limited_bad; + arg_tuple = PyTuple_Pack(2, py_bytes, order_str); + if (!arg_tuple) goto limited_bad; + if (!is_unsigned) { + kwds = PyDict_New(); + if (!kwds) goto limited_bad; + if (PyDict_SetItemString(kwds, "signed", __Pyx_NewRef(Py_True))) goto limited_bad; + } + result = PyObject_Call(from_bytes, arg_tuple, kwds); + limited_bad: + Py_XDECREF(kwds); + Py_XDECREF(arg_tuple); + Py_XDECREF(order_str); + Py_XDECREF(py_bytes); + Py_XDECREF(from_bytes); + return result; +#endif + } +} + +/* FormatTypeName */ +#if CYTHON_COMPILING_IN_LIMITED_API +static __Pyx_TypeName +__Pyx_PyType_GetName(PyTypeObject* tp) +{ + PyObject *name = __Pyx_PyObject_GetAttrStr((PyObject *)tp, + __pyx_n_s_name); + if (unlikely(name == NULL) || unlikely(!PyUnicode_Check(name))) { + PyErr_Clear(); + Py_XDECREF(name); + name = __Pyx_NewRef(__pyx_n_s__14); + } + return name; +} +#endif + +/* CIntFromPy */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const int neg_one = (int) -1, const_zero = (int) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if ((sizeof(int) < sizeof(long))) { + __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (int) val; + } + } +#endif + if (unlikely(!PyLong_Check(x))) { + int val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (int) -1; + val = __Pyx_PyInt_As_int(tmp); + Py_DECREF(tmp); + return val; + } + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + if (unlikely(__Pyx_PyLong_IsNeg(x))) { + goto raise_neg_overflow; + } else if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_DigitCount(x)) { + case 2: + if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) >= 2 * PyLong_SHIFT)) { + return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 3: + if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) >= 3 * PyLong_SHIFT)) { + return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 4: + if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) >= 4 * PyLong_SHIFT)) { + return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + } + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7 + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (int) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if ((sizeof(int) <= sizeof(unsigned long))) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(int) <= sizeof(unsigned PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_SignedDigitCount(x)) { + case -2: + if ((8 * sizeof(int) - 1 > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) { + return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 2: + if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) { + return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -3: + if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) { + return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 3: + if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) { + return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -4: + if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) { + return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 4: + if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) { + return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + } + } +#endif + if ((sizeof(int) <= sizeof(long))) { + __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(int) <= sizeof(PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { + int val; + int ret = -1; +#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API + Py_ssize_t bytes_copied = PyLong_AsNativeBytes( + x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0)); + if (unlikely(bytes_copied == -1)) { + } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) { + goto raise_overflow; + } else { + ret = 0; + } +#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray) + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + ret = _PyLong_AsByteArray((PyLongObject *)x, + bytes, sizeof(val), + is_little, !is_unsigned); +#else + PyObject *v; + PyObject *stepval = NULL, *mask = NULL, *shift = NULL; + int bits, remaining_bits, is_negative = 0; + int chunk_size = (sizeof(long) < 8) ? 30 : 62; + if (likely(PyLong_CheckExact(x))) { + v = __Pyx_NewRef(x); + } else { + v = PyNumber_Long(x); + if (unlikely(!v)) return (int) -1; + assert(PyLong_CheckExact(v)); + } + { + int result = PyObject_RichCompareBool(v, Py_False, Py_LT); + if (unlikely(result < 0)) { + Py_DECREF(v); + return (int) -1; + } + is_negative = result == 1; + } + if (is_unsigned && unlikely(is_negative)) { + Py_DECREF(v); + goto raise_neg_overflow; + } else if (is_negative) { + stepval = PyNumber_Invert(v); + Py_DECREF(v); + if (unlikely(!stepval)) + return (int) -1; + } else { + stepval = v; + } + v = NULL; + val = (int) 0; + mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done; + shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done; + for (bits = 0; bits < (int) sizeof(int) * 8 - chunk_size; bits += chunk_size) { + PyObject *tmp, *digit; + long idigit; + digit = PyNumber_And(stepval, mask); + if (unlikely(!digit)) goto done; + idigit = PyLong_AsLong(digit); + Py_DECREF(digit); + if (unlikely(idigit < 0)) goto done; + val |= ((int) idigit) << bits; + tmp = PyNumber_Rshift(stepval, shift); + if (unlikely(!tmp)) goto done; + Py_DECREF(stepval); stepval = tmp; + } + Py_DECREF(shift); shift = NULL; + Py_DECREF(mask); mask = NULL; + { + long idigit = PyLong_AsLong(stepval); + if (unlikely(idigit < 0)) goto done; + remaining_bits = ((int) sizeof(int) * 8) - bits - (is_unsigned ? 0 : 1); + if (unlikely(idigit >= (1L << remaining_bits))) + goto raise_overflow; + val |= ((int) idigit) << bits; + } + if (!is_unsigned) { + if (unlikely(val & (((int) 1) << (sizeof(int) * 8 - 1)))) + goto raise_overflow; + if (is_negative) + val = ~val; + } + ret = 0; + done: + Py_XDECREF(shift); + Py_XDECREF(mask); + Py_XDECREF(stepval); +#endif + if (unlikely(ret)) + return (int) -1; + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to int"); + return (int) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int"); + return (int) -1; +} + +/* CheckBinaryVersion */ +static unsigned long __Pyx_get_runtime_version(void) { +#if __PYX_LIMITED_VERSION_HEX >= 0x030B00A4 + return Py_Version & ~0xFFUL; +#else + const char* rt_version = Py_GetVersion(); + unsigned long version = 0; + unsigned long factor = 0x01000000UL; + unsigned int digit = 0; + int i = 0; + while (factor) { + while ('0' <= rt_version[i] && rt_version[i] <= '9') { + digit = digit * 10 + (unsigned int) (rt_version[i] - '0'); + ++i; + } + version += factor * digit; + if (rt_version[i] != '.') + break; + digit = 0; + factor >>= 8; + ++i; + } + return version; +#endif +} +static int __Pyx_check_binary_version(unsigned long ct_version, unsigned long rt_version, int allow_newer) { + const unsigned long MAJOR_MINOR = 0xFFFF0000UL; + if ((rt_version & MAJOR_MINOR) == (ct_version & MAJOR_MINOR)) + return 0; + if (likely(allow_newer && (rt_version & MAJOR_MINOR) > (ct_version & MAJOR_MINOR))) + return 1; + { + char message[200]; + PyOS_snprintf(message, sizeof(message), + "compile time Python version %d.%d " + "of module '%.100s' " + "%s " + "runtime version %d.%d", + (int) (ct_version >> 24), (int) ((ct_version >> 16) & 0xFF), + __Pyx_MODULE_NAME, + (allow_newer) ? "was newer than" : "does not match", + (int) (rt_version >> 24), (int) ((rt_version >> 16) & 0xFF) + ); + return PyErr_WarnEx(NULL, message, 1); + } +} + +/* InitStrings */ +#if PY_MAJOR_VERSION >= 3 +static int __Pyx_InitString(__Pyx_StringTabEntry t, PyObject **str) { + if (t.is_unicode | t.is_str) { + if (t.intern) { + *str = PyUnicode_InternFromString(t.s); + } else if (t.encoding) { + *str = PyUnicode_Decode(t.s, t.n - 1, t.encoding, NULL); + } else { + *str = PyUnicode_FromStringAndSize(t.s, t.n - 1); + } + } else { + *str = PyBytes_FromStringAndSize(t.s, t.n - 1); + } + if (!*str) + return -1; + if (PyObject_Hash(*str) == -1) + return -1; + return 0; +} +#endif +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + #if PY_MAJOR_VERSION >= 3 + __Pyx_InitString(*t, t->p); + #else + if (t->is_unicode) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + if (!*t->p) + return -1; + if (PyObject_Hash(*t->p) == -1) + return -1; + #endif + ++t; + } + return 0; +} + +#include +static CYTHON_INLINE Py_ssize_t __Pyx_ssize_strlen(const char *s) { + size_t len = strlen(s); + if (unlikely(len > (size_t) PY_SSIZE_T_MAX)) { + PyErr_SetString(PyExc_OverflowError, "byte string is too long"); + return -1; + } + return (Py_ssize_t) len; +} +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { + Py_ssize_t len = __Pyx_ssize_strlen(c_str); + if (unlikely(len < 0)) return NULL; + return __Pyx_PyUnicode_FromStringAndSize(c_str, len); +} +static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char* c_str) { + Py_ssize_t len = __Pyx_ssize_strlen(c_str); + if (unlikely(len < 0)) return NULL; + return PyByteArray_FromStringAndSize(c_str, len); +} +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) { + Py_ssize_t ignore; + return __Pyx_PyObject_AsStringAndSize(o, &ignore); +} +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +#if !CYTHON_PEP393_ENABLED +static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + char* defenc_c; + PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); + if (!defenc) return NULL; + defenc_c = PyBytes_AS_STRING(defenc); +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + { + char* end = defenc_c + PyBytes_GET_SIZE(defenc); + char* c; + for (c = defenc_c; c < end; c++) { + if ((unsigned char) (*c) >= 128) { + PyUnicode_AsASCIIString(o); + return NULL; + } + } + } +#endif + *length = PyBytes_GET_SIZE(defenc); + return defenc_c; +} +#else +static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL; +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + if (likely(PyUnicode_IS_ASCII(o))) { + *length = PyUnicode_GET_LENGTH(o); + return PyUnicode_AsUTF8(o); + } else { + PyUnicode_AsASCIIString(o); + return NULL; + } +#else + return PyUnicode_AsUTF8AndSize(o, length); +#endif +} +#endif +#endif +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT + if ( +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + __Pyx_sys_getdefaultencoding_not_ascii && +#endif + PyUnicode_Check(o)) { + return __Pyx_PyUnicode_AsStringAndSize(o, length); + } else +#endif +#if (!CYTHON_COMPILING_IN_PYPY && !CYTHON_COMPILING_IN_LIMITED_API) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) + if (PyByteArray_Check(o)) { + *length = PyByteArray_GET_SIZE(o); + return PyByteArray_AS_STRING(o); + } else +#endif + { + char* result; + int r = PyBytes_AsStringAndSize(o, &result, length); + if (unlikely(r < 0)) { + return NULL; + } else { + return result; + } + } +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + int is_true = x == Py_True; + if (is_true | (x == Py_False) | (x == Py_None)) return is_true; + else return PyObject_IsTrue(x); +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { + int retval; + if (unlikely(!x)) return -1; + retval = __Pyx_PyObject_IsTrue(x); + Py_DECREF(x); + return retval; +} +static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) { + __Pyx_TypeName result_type_name = __Pyx_PyType_GetName(Py_TYPE(result)); +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(result)) { + if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + "__int__ returned non-int (type " __Pyx_FMT_TYPENAME "). " + "The ability to return an instance of a strict subclass of int is deprecated, " + "and may be removed in a future version of Python.", + result_type_name)) { + __Pyx_DECREF_TypeName(result_type_name); + Py_DECREF(result); + return NULL; + } + __Pyx_DECREF_TypeName(result_type_name); + return result; + } +#endif + PyErr_Format(PyExc_TypeError, + "__%.4s__ returned non-%.4s (type " __Pyx_FMT_TYPENAME ")", + type_name, type_name, result_type_name); + __Pyx_DECREF_TypeName(result_type_name); + Py_DECREF(result); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { +#if CYTHON_USE_TYPE_SLOTS + PyNumberMethods *m; +#endif + const char *name = NULL; + PyObject *res = NULL; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x) || PyLong_Check(x))) +#else + if (likely(PyLong_Check(x))) +#endif + return __Pyx_NewRef(x); +#if CYTHON_USE_TYPE_SLOTS + m = Py_TYPE(x)->tp_as_number; + #if PY_MAJOR_VERSION < 3 + if (m && m->nb_int) { + name = "int"; + res = m->nb_int(x); + } + else if (m && m->nb_long) { + name = "long"; + res = m->nb_long(x); + } + #else + if (likely(m && m->nb_int)) { + name = "int"; + res = m->nb_int(x); + } + #endif +#else + if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) { + res = PyNumber_Int(x); + } +#endif + if (likely(res)) { +#if PY_MAJOR_VERSION < 3 + if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) { +#else + if (unlikely(!PyLong_CheckExact(res))) { +#endif + return __Pyx_PyNumber_IntOrLongWrongResultType(res, name); + } + } + else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); + } + return res; +} +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject *x; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(b))) { + if (sizeof(Py_ssize_t) >= sizeof(long)) + return PyInt_AS_LONG(b); + else + return PyInt_AsSsize_t(b); + } +#endif + if (likely(PyLong_CheckExact(b))) { + #if CYTHON_USE_PYLONG_INTERNALS + if (likely(__Pyx_PyLong_IsCompact(b))) { + return __Pyx_PyLong_CompactValue(b); + } else { + const digit* digits = __Pyx_PyLong_Digits(b); + const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount(b); + switch (size) { + case 2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + } + } + #endif + return PyLong_AsSsize_t(b); + } + x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} +static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject* o) { + if (sizeof(Py_hash_t) == sizeof(Py_ssize_t)) { + return (Py_hash_t) __Pyx_PyIndex_AsSsize_t(o); +#if PY_MAJOR_VERSION < 3 + } else if (likely(PyInt_CheckExact(o))) { + return PyInt_AS_LONG(o); +#endif + } else { + Py_ssize_t ival; + PyObject *x; + x = PyNumber_Index(o); + if (!x) return -1; + ival = PyInt_AsLong(x); + Py_DECREF(x); + return ival; + } +} +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) { + return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False); +} +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { + return PyInt_FromSize_t(ival); +} + + +/* #### Code section: utility_code_pragmas_end ### */ +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + + + +/* #### Code section: end ### */ +#endif /* Py_PYTHON_H */ diff --git a/bot/build/cython_code/send_ads.c b/bot/build/cython_code/send_ads.c new file mode 100644 index 0000000..f1045f9 --- /dev/null +++ b/bot/build/cython_code/send_ads.c @@ -0,0 +1,14874 @@ +/* Generated by Cython 3.0.11 */ + +/* BEGIN: Cython Metadata +{ + "distutils": { + "name": "cython_code.send_ads", + "sources": [ + "cython_code/send_ads.pyx" + ] + }, + "module_name": "cython_code.send_ads" +} +END: Cython Metadata */ + +#ifndef PY_SSIZE_T_CLEAN +#define PY_SSIZE_T_CLEAN +#endif /* PY_SSIZE_T_CLEAN */ +#if defined(CYTHON_LIMITED_API) && 0 + #ifndef Py_LIMITED_API + #if CYTHON_LIMITED_API+0 > 0x03030000 + #define Py_LIMITED_API CYTHON_LIMITED_API + #else + #define Py_LIMITED_API 0x03030000 + #endif + #endif +#endif + +#include "Python.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#elif PY_VERSION_HEX < 0x02070000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) + #error Cython requires Python 2.7+ or Python 3.3+. +#else +#if defined(CYTHON_LIMITED_API) && CYTHON_LIMITED_API +#define __PYX_EXTRA_ABI_MODULE_NAME "limited" +#else +#define __PYX_EXTRA_ABI_MODULE_NAME "" +#endif +#define CYTHON_ABI "3_0_11" __PYX_EXTRA_ABI_MODULE_NAME +#define __PYX_ABI_MODULE_NAME "_cython_" CYTHON_ABI +#define __PYX_TYPE_MODULE_PREFIX __PYX_ABI_MODULE_NAME "." +#define CYTHON_HEX_VERSION 0x03000BF0 +#define CYTHON_FUTURE_DIVISION 1 +#include +#ifndef offsetof + #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) +#endif +#if !defined(_WIN32) && !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#endif +#ifndef DL_IMPORT + #define DL_IMPORT(t) t +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif +#define __PYX_COMMA , +#ifndef HAVE_LONG_LONG + #define HAVE_LONG_LONG +#endif +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifndef Py_HUGE_VAL + #define Py_HUGE_VAL HUGE_VAL +#endif +#define __PYX_LIMITED_VERSION_HEX PY_VERSION_HEX +#if defined(GRAALVM_PYTHON) + /* For very preliminary testing purposes. Most variables are set the same as PyPy. + The existence of this section does not imply that anything works or is even tested */ + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 1 + #define CYTHON_COMPILING_IN_NOGIL 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #undef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS (PY_MAJOR_VERSION >= 3) + #endif + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #undef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #endif + #undef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 +#elif defined(PYPY_VERSION) + #define CYTHON_COMPILING_IN_PYPY 1 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #ifndef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #undef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS (PY_MAJOR_VERSION >= 3) + #endif + #if PY_VERSION_HEX < 0x03090000 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #elif !defined(CYTHON_PEP489_MULTI_PHASE_INIT) + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #undef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1 && PYPY_VERSION_NUM >= 0x07030C00) + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #endif + #undef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 +#elif defined(CYTHON_LIMITED_API) + #ifdef Py_LIMITED_API + #undef __PYX_LIMITED_VERSION_HEX + #define __PYX_LIMITED_VERSION_HEX Py_LIMITED_API + #endif + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 1 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 0 + #undef CYTHON_CLINE_IN_TRACEBACK + #define CYTHON_CLINE_IN_TRACEBACK 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 1 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #endif + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #undef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS 1 + #endif + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #undef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 1 + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #endif + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #endif + #undef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 +#elif defined(Py_GIL_DISABLED) || defined(Py_NOGIL) + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 1 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #ifndef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #ifndef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #ifndef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #ifndef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 1 + #endif + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS 1 + #endif + #ifndef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #ifndef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #endif + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 1 + #endif + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 1 + #endif + #ifndef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 + #endif +#else + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 1 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 0 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #ifndef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #endif + #ifndef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 1 + #endif + #if PY_MAJOR_VERSION < 3 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #ifndef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 1 + #endif + #ifndef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 1 + #endif + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #if PY_VERSION_HEX < 0x030300F0 || PY_VERSION_HEX >= 0x030B00A2 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #elif !defined(CYTHON_USE_UNICODE_WRITER) + #define CYTHON_USE_UNICODE_WRITER 1 + #endif + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #ifndef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 1 + #endif + #ifndef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL (PY_MAJOR_VERSION < 3 || PY_VERSION_HEX >= 0x03060000 && PY_VERSION_HEX < 0x030C00A6) + #endif + #ifndef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL (PY_VERSION_HEX >= 0x030700A1) + #endif + #ifndef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 1 + #endif + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS 1 + #endif + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #elif !defined(CYTHON_PEP489_MULTI_PHASE_INIT) + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #ifndef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #endif + #if PY_VERSION_HEX < 0x030400a1 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #elif !defined(CYTHON_USE_TP_FINALIZE) + #define CYTHON_USE_TP_FINALIZE 1 + #endif + #if PY_VERSION_HEX < 0x030600B1 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #elif !defined(CYTHON_USE_DICT_VERSIONS) + #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX < 0x030C00A5) + #endif + #if PY_VERSION_HEX < 0x030700A3 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #elif !defined(CYTHON_USE_EXC_INFO_STACK) + #define CYTHON_USE_EXC_INFO_STACK 1 + #endif + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 1 + #endif + #ifndef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 1 + #endif +#endif +#if !defined(CYTHON_FAST_PYCCALL) +#define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) +#endif +#if !defined(CYTHON_VECTORCALL) +#define CYTHON_VECTORCALL (CYTHON_FAST_PYCCALL && PY_VERSION_HEX >= 0x030800B1) +#endif +#define CYTHON_BACKPORT_VECTORCALL (CYTHON_METH_FASTCALL && PY_VERSION_HEX < 0x030800B1) +#if CYTHON_USE_PYLONG_INTERNALS + #if PY_MAJOR_VERSION < 3 + #include "longintrepr.h" + #endif + #undef SHIFT + #undef BASE + #undef MASK + #ifdef SIZEOF_VOID_P + enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; + #endif +#endif +#ifndef __has_attribute + #define __has_attribute(x) 0 +#endif +#ifndef __has_cpp_attribute + #define __has_cpp_attribute(x) 0 +#endif +#ifndef CYTHON_RESTRICT + #if defined(__GNUC__) + #define CYTHON_RESTRICT __restrict__ + #elif defined(_MSC_VER) && _MSC_VER >= 1400 + #define CYTHON_RESTRICT __restrict + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_RESTRICT restrict + #else + #define CYTHON_RESTRICT + #endif +#endif +#ifndef CYTHON_UNUSED + #if defined(__cplusplus) + /* for clang __has_cpp_attribute(maybe_unused) is true even before C++17 + * but leads to warnings with -pedantic, since it is a C++17 feature */ + #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) + #if __has_cpp_attribute(maybe_unused) + #define CYTHON_UNUSED [[maybe_unused]] + #endif + #endif + #endif +#endif +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_UNUSED_VAR +# if defined(__cplusplus) + template void CYTHON_UNUSED_VAR( const T& ) { } +# else +# define CYTHON_UNUSED_VAR(x) (void)(x) +# endif +#endif +#ifndef CYTHON_MAYBE_UNUSED_VAR + #define CYTHON_MAYBE_UNUSED_VAR(x) CYTHON_UNUSED_VAR(x) +#endif +#ifndef CYTHON_NCP_UNUSED +# if CYTHON_COMPILING_IN_CPYTHON +# define CYTHON_NCP_UNUSED +# else +# define CYTHON_NCP_UNUSED CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_USE_CPP_STD_MOVE + #if defined(__cplusplus) && (\ + __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600)) + #define CYTHON_USE_CPP_STD_MOVE 1 + #else + #define CYTHON_USE_CPP_STD_MOVE 0 + #endif +#endif +#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) +#ifdef _MSC_VER + #ifndef _MSC_STDINT_H_ + #if _MSC_VER < 1300 + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + typedef unsigned int uint32_t; + #else + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; + #endif + #endif + #if _MSC_VER < 1300 + #ifdef _WIN64 + typedef unsigned long long __pyx_uintptr_t; + #else + typedef unsigned int __pyx_uintptr_t; + #endif + #else + #ifdef _WIN64 + typedef unsigned __int64 __pyx_uintptr_t; + #else + typedef unsigned __int32 __pyx_uintptr_t; + #endif + #endif +#else + #include + typedef uintptr_t __pyx_uintptr_t; +#endif +#ifndef CYTHON_FALLTHROUGH + #if defined(__cplusplus) + /* for clang __has_cpp_attribute(fallthrough) is true even before C++17 + * but leads to warnings with -pedantic, since it is a C++17 feature */ + #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) + #if __has_cpp_attribute(fallthrough) + #define CYTHON_FALLTHROUGH [[fallthrough]] + #endif + #endif + #ifndef CYTHON_FALLTHROUGH + #if __has_cpp_attribute(clang::fallthrough) + #define CYTHON_FALLTHROUGH [[clang::fallthrough]] + #elif __has_cpp_attribute(gnu::fallthrough) + #define CYTHON_FALLTHROUGH [[gnu::fallthrough]] + #endif + #endif + #endif + #ifndef CYTHON_FALLTHROUGH + #if __has_attribute(fallthrough) + #define CYTHON_FALLTHROUGH __attribute__((fallthrough)) + #else + #define CYTHON_FALLTHROUGH + #endif + #endif + #if defined(__clang__) && defined(__apple_build_version__) + #if __apple_build_version__ < 7000000 + #undef CYTHON_FALLTHROUGH + #define CYTHON_FALLTHROUGH + #endif + #endif +#endif +#ifdef __cplusplus + template + struct __PYX_IS_UNSIGNED_IMPL {static const bool value = T(0) < T(-1);}; + #define __PYX_IS_UNSIGNED(type) (__PYX_IS_UNSIGNED_IMPL::value) +#else + #define __PYX_IS_UNSIGNED(type) (((type)-1) > 0) +#endif +#if CYTHON_COMPILING_IN_PYPY == 1 + #define __PYX_NEED_TP_PRINT_SLOT (PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x030A0000) +#else + #define __PYX_NEED_TP_PRINT_SLOT (PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000) +#endif +#define __PYX_REINTERPRET_FUNCION(func_pointer, other_pointer) ((func_pointer)(void(*)(void))(other_pointer)) + +#ifndef CYTHON_INLINE + #if defined(__clang__) + #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) + #elif defined(__GNUC__) + #define CYTHON_INLINE __inline__ + #elif defined(_MSC_VER) + #define CYTHON_INLINE __inline + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_INLINE inline + #else + #define CYTHON_INLINE + #endif +#endif + +#define __PYX_BUILD_PY_SSIZE_T "n" +#define CYTHON_FORMAT_SSIZE_T "z" +#if PY_MAJOR_VERSION < 3 + #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" + #define __Pyx_DefaultClassType PyClass_Type + #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #define __Pyx_BUILTIN_MODULE_NAME "builtins" + #define __Pyx_DefaultClassType PyType_Type +#if CYTHON_COMPILING_IN_LIMITED_API + static CYTHON_INLINE PyObject* __Pyx_PyCode_New(int a, int p, int k, int l, int s, int f, + PyObject *code, PyObject *c, PyObject* n, PyObject *v, + PyObject *fv, PyObject *cell, PyObject* fn, + PyObject *name, int fline, PyObject *lnos) { + PyObject *exception_table = NULL; + PyObject *types_module=NULL, *code_type=NULL, *result=NULL; + #if __PYX_LIMITED_VERSION_HEX < 0x030B0000 + PyObject *version_info; + PyObject *py_minor_version = NULL; + #endif + long minor_version = 0; + PyObject *type, *value, *traceback; + PyErr_Fetch(&type, &value, &traceback); + #if __PYX_LIMITED_VERSION_HEX >= 0x030B0000 + minor_version = 11; + #else + if (!(version_info = PySys_GetObject("version_info"))) goto end; + if (!(py_minor_version = PySequence_GetItem(version_info, 1))) goto end; + minor_version = PyLong_AsLong(py_minor_version); + Py_DECREF(py_minor_version); + if (minor_version == -1 && PyErr_Occurred()) goto end; + #endif + if (!(types_module = PyImport_ImportModule("types"))) goto end; + if (!(code_type = PyObject_GetAttrString(types_module, "CodeType"))) goto end; + if (minor_version <= 7) { + (void)p; + result = PyObject_CallFunction(code_type, "iiiiiOOOOOOiOO", a, k, l, s, f, code, + c, n, v, fn, name, fline, lnos, fv, cell); + } else if (minor_version <= 10) { + result = PyObject_CallFunction(code_type, "iiiiiiOOOOOOiOO", a,p, k, l, s, f, code, + c, n, v, fn, name, fline, lnos, fv, cell); + } else { + if (!(exception_table = PyBytes_FromStringAndSize(NULL, 0))) goto end; + result = PyObject_CallFunction(code_type, "iiiiiiOOOOOOOiOO", a,p, k, l, s, f, code, + c, n, v, fn, name, name, fline, lnos, exception_table, fv, cell); + } + end: + Py_XDECREF(code_type); + Py_XDECREF(exception_table); + Py_XDECREF(types_module); + if (type) { + PyErr_Restore(type, value, traceback); + } + return result; + } + #ifndef CO_OPTIMIZED + #define CO_OPTIMIZED 0x0001 + #endif + #ifndef CO_NEWLOCALS + #define CO_NEWLOCALS 0x0002 + #endif + #ifndef CO_VARARGS + #define CO_VARARGS 0x0004 + #endif + #ifndef CO_VARKEYWORDS + #define CO_VARKEYWORDS 0x0008 + #endif + #ifndef CO_ASYNC_GENERATOR + #define CO_ASYNC_GENERATOR 0x0200 + #endif + #ifndef CO_GENERATOR + #define CO_GENERATOR 0x0020 + #endif + #ifndef CO_COROUTINE + #define CO_COROUTINE 0x0080 + #endif +#elif PY_VERSION_HEX >= 0x030B0000 + static CYTHON_INLINE PyCodeObject* __Pyx_PyCode_New(int a, int p, int k, int l, int s, int f, + PyObject *code, PyObject *c, PyObject* n, PyObject *v, + PyObject *fv, PyObject *cell, PyObject* fn, + PyObject *name, int fline, PyObject *lnos) { + PyCodeObject *result; + PyObject *empty_bytes = PyBytes_FromStringAndSize("", 0); + if (!empty_bytes) return NULL; + result = + #if PY_VERSION_HEX >= 0x030C0000 + PyUnstable_Code_NewWithPosOnlyArgs + #else + PyCode_NewWithPosOnlyArgs + #endif + (a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, name, fline, lnos, empty_bytes); + Py_DECREF(empty_bytes); + return result; + } +#elif PY_VERSION_HEX >= 0x030800B2 && !CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_NewWithPosOnlyArgs(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#endif +#endif +#if PY_VERSION_HEX >= 0x030900A4 || defined(Py_IS_TYPE) + #define __Pyx_IS_TYPE(ob, type) Py_IS_TYPE(ob, type) +#else + #define __Pyx_IS_TYPE(ob, type) (((const PyObject*)ob)->ob_type == (type)) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_Is) + #define __Pyx_Py_Is(x, y) Py_Is(x, y) +#else + #define __Pyx_Py_Is(x, y) ((x) == (y)) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsNone) + #define __Pyx_Py_IsNone(ob) Py_IsNone(ob) +#else + #define __Pyx_Py_IsNone(ob) __Pyx_Py_Is((ob), Py_None) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsTrue) + #define __Pyx_Py_IsTrue(ob) Py_IsTrue(ob) +#else + #define __Pyx_Py_IsTrue(ob) __Pyx_Py_Is((ob), Py_True) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsFalse) + #define __Pyx_Py_IsFalse(ob) Py_IsFalse(ob) +#else + #define __Pyx_Py_IsFalse(ob) __Pyx_Py_Is((ob), Py_False) +#endif +#define __Pyx_NoneAsNull(obj) (__Pyx_Py_IsNone(obj) ? NULL : (obj)) +#if PY_VERSION_HEX >= 0x030900F0 && !CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyObject_GC_IsFinalized(o) PyObject_GC_IsFinalized(o) +#else + #define __Pyx_PyObject_GC_IsFinalized(o) _PyGC_FINALIZED(o) +#endif +#ifndef CO_COROUTINE + #define CO_COROUTINE 0x80 +#endif +#ifndef CO_ASYNC_GENERATOR + #define CO_ASYNC_GENERATOR 0x200 +#endif +#ifndef Py_TPFLAGS_CHECKTYPES + #define Py_TPFLAGS_CHECKTYPES 0 +#endif +#ifndef Py_TPFLAGS_HAVE_INDEX + #define Py_TPFLAGS_HAVE_INDEX 0 +#endif +#ifndef Py_TPFLAGS_HAVE_NEWBUFFER + #define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif +#ifndef Py_TPFLAGS_HAVE_FINALIZE + #define Py_TPFLAGS_HAVE_FINALIZE 0 +#endif +#ifndef Py_TPFLAGS_SEQUENCE + #define Py_TPFLAGS_SEQUENCE 0 +#endif +#ifndef Py_TPFLAGS_MAPPING + #define Py_TPFLAGS_MAPPING 0 +#endif +#ifndef METH_STACKLESS + #define METH_STACKLESS 0 +#endif +#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL) + #ifndef METH_FASTCALL + #define METH_FASTCALL 0x80 + #endif + typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs); + typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args, + Py_ssize_t nargs, PyObject *kwnames); +#else + #if PY_VERSION_HEX >= 0x030d00A4 + # define __Pyx_PyCFunctionFast PyCFunctionFast + # define __Pyx_PyCFunctionFastWithKeywords PyCFunctionFastWithKeywords + #else + # define __Pyx_PyCFunctionFast _PyCFunctionFast + # define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords + #endif +#endif +#if CYTHON_METH_FASTCALL + #define __Pyx_METH_FASTCALL METH_FASTCALL + #define __Pyx_PyCFunction_FastCall __Pyx_PyCFunctionFast + #define __Pyx_PyCFunction_FastCallWithKeywords __Pyx_PyCFunctionFastWithKeywords +#else + #define __Pyx_METH_FASTCALL METH_VARARGS + #define __Pyx_PyCFunction_FastCall PyCFunction + #define __Pyx_PyCFunction_FastCallWithKeywords PyCFunctionWithKeywords +#endif +#if CYTHON_VECTORCALL + #define __pyx_vectorcallfunc vectorcallfunc + #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET PY_VECTORCALL_ARGUMENTS_OFFSET + #define __Pyx_PyVectorcall_NARGS(n) PyVectorcall_NARGS((size_t)(n)) +#elif CYTHON_BACKPORT_VECTORCALL + typedef PyObject *(*__pyx_vectorcallfunc)(PyObject *callable, PyObject *const *args, + size_t nargsf, PyObject *kwnames); + #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET ((size_t)1 << (8 * sizeof(size_t) - 1)) + #define __Pyx_PyVectorcall_NARGS(n) ((Py_ssize_t)(((size_t)(n)) & ~__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)) +#else + #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET 0 + #define __Pyx_PyVectorcall_NARGS(n) ((Py_ssize_t)(n)) +#endif +#if PY_MAJOR_VERSION >= 0x030900B1 +#define __Pyx_PyCFunction_CheckExact(func) PyCFunction_CheckExact(func) +#else +#define __Pyx_PyCFunction_CheckExact(func) PyCFunction_Check(func) +#endif +#define __Pyx_CyOrPyCFunction_Check(func) PyCFunction_Check(func) +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_CyOrPyCFunction_GET_FUNCTION(func) (((PyCFunctionObject*)(func))->m_ml->ml_meth) +#elif !CYTHON_COMPILING_IN_LIMITED_API +#define __Pyx_CyOrPyCFunction_GET_FUNCTION(func) PyCFunction_GET_FUNCTION(func) +#endif +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_CyOrPyCFunction_GET_FLAGS(func) (((PyCFunctionObject*)(func))->m_ml->ml_flags) +static CYTHON_INLINE PyObject* __Pyx_CyOrPyCFunction_GET_SELF(PyObject *func) { + return (__Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_STATIC) ? NULL : ((PyCFunctionObject*)func)->m_self; +} +#endif +static CYTHON_INLINE int __Pyx__IsSameCFunction(PyObject *func, void *cfunc) { +#if CYTHON_COMPILING_IN_LIMITED_API + return PyCFunction_Check(func) && PyCFunction_GetFunction(func) == (PyCFunction) cfunc; +#else + return PyCFunction_Check(func) && PyCFunction_GET_FUNCTION(func) == (PyCFunction) cfunc; +#endif +} +#define __Pyx_IsSameCFunction(func, cfunc) __Pyx__IsSameCFunction(func, cfunc) +#if __PYX_LIMITED_VERSION_HEX < 0x030900B1 + #define __Pyx_PyType_FromModuleAndSpec(m, s, b) ((void)m, PyType_FromSpecWithBases(s, b)) + typedef PyObject *(*__Pyx_PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *, size_t, PyObject *); +#else + #define __Pyx_PyType_FromModuleAndSpec(m, s, b) PyType_FromModuleAndSpec(m, s, b) + #define __Pyx_PyCMethod PyCMethod +#endif +#ifndef METH_METHOD + #define METH_METHOD 0x200 +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) + #define PyObject_Malloc(s) PyMem_Malloc(s) + #define PyObject_Free(p) PyMem_Free(p) + #define PyObject_Realloc(p) PyMem_Realloc(p) +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) +#else + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_PyThreadState_Current PyThreadState_Get() +#elif !CYTHON_FAST_THREAD_STATE + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#elif PY_VERSION_HEX >= 0x030d00A1 + #define __Pyx_PyThreadState_Current PyThreadState_GetUnchecked() +#elif PY_VERSION_HEX >= 0x03060000 + #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet() +#elif PY_VERSION_HEX >= 0x03000000 + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#else + #define __Pyx_PyThreadState_Current _PyThreadState_Current +#endif +#if CYTHON_COMPILING_IN_LIMITED_API +static CYTHON_INLINE void *__Pyx_PyModule_GetState(PyObject *op) +{ + void *result; + result = PyModule_GetState(op); + if (!result) + Py_FatalError("Couldn't find the module state"); + return result; +} +#endif +#define __Pyx_PyObject_GetSlot(obj, name, func_ctype) __Pyx_PyType_GetSlot(Py_TYPE(obj), name, func_ctype) +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_PyType_GetSlot(type, name, func_ctype) ((func_ctype) PyType_GetSlot((type), Py_##name)) +#else + #define __Pyx_PyType_GetSlot(type, name, func_ctype) ((type)->name) +#endif +#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT) +#include "pythread.h" +#define Py_tss_NEEDS_INIT 0 +typedef int Py_tss_t; +static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) { + *key = PyThread_create_key(); + return 0; +} +static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) { + Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t)); + *key = Py_tss_NEEDS_INIT; + return key; +} +static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) { + PyObject_Free(key); +} +static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) { + return *key != Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) { + PyThread_delete_key(*key); + *key = Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) { + return PyThread_set_key_value(*key, value); +} +static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { + return PyThread_get_key_value(*key); +} +#endif +#if PY_MAJOR_VERSION < 3 + #if CYTHON_COMPILING_IN_PYPY + #if PYPY_VERSION_NUM < 0x07030600 + #if defined(__cplusplus) && __cplusplus >= 201402L + [[deprecated("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6")]] + #elif defined(__GNUC__) || defined(__clang__) + __attribute__ ((__deprecated__("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6"))) + #elif defined(_MSC_VER) + __declspec(deprecated("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6")) + #endif + static CYTHON_INLINE int PyGILState_Check(void) { + return 0; + } + #else // PYPY_VERSION_NUM < 0x07030600 + #endif // PYPY_VERSION_NUM < 0x07030600 + #else + static CYTHON_INLINE int PyGILState_Check(void) { + PyThreadState * tstate = _PyThreadState_Current; + return tstate && (tstate == PyGILState_GetThisThreadState()); + } + #endif +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000 || defined(_PyDict_NewPresized) +#define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n)) +#else +#define __Pyx_PyDict_NewPresized(n) PyDict_New() +#endif +#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX > 0x030600B4 && PY_VERSION_HEX < 0x030d0000 && CYTHON_USE_UNICODE_INTERNALS +#define __Pyx_PyDict_GetItemStrWithError(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash) +static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStr(PyObject *dict, PyObject *name) { + PyObject *res = __Pyx_PyDict_GetItemStrWithError(dict, name); + if (res == NULL) PyErr_Clear(); + return res; +} +#elif PY_MAJOR_VERSION >= 3 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07020000) +#define __Pyx_PyDict_GetItemStrWithError PyDict_GetItemWithError +#define __Pyx_PyDict_GetItemStr PyDict_GetItem +#else +static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict, PyObject *name) { +#if CYTHON_COMPILING_IN_PYPY + return PyDict_GetItem(dict, name); +#else + PyDictEntry *ep; + PyDictObject *mp = (PyDictObject*) dict; + long hash = ((PyStringObject *) name)->ob_shash; + assert(hash != -1); + ep = (mp->ma_lookup)(mp, name, hash); + if (ep == NULL) { + return NULL; + } + return ep->me_value; +#endif +} +#define __Pyx_PyDict_GetItemStr PyDict_GetItem +#endif +#if CYTHON_USE_TYPE_SLOTS + #define __Pyx_PyType_GetFlags(tp) (((PyTypeObject *)tp)->tp_flags) + #define __Pyx_PyType_HasFeature(type, feature) ((__Pyx_PyType_GetFlags(type) & (feature)) != 0) + #define __Pyx_PyObject_GetIterNextFunc(obj) (Py_TYPE(obj)->tp_iternext) +#else + #define __Pyx_PyType_GetFlags(tp) (PyType_GetFlags((PyTypeObject *)tp)) + #define __Pyx_PyType_HasFeature(type, feature) PyType_HasFeature(type, feature) + #define __Pyx_PyObject_GetIterNextFunc(obj) PyIter_Next +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_SetItemOnTypeDict(tp, k, v) PyObject_GenericSetAttr((PyObject*)tp, k, v) +#else + #define __Pyx_SetItemOnTypeDict(tp, k, v) PyDict_SetItem(tp->tp_dict, k, v) +#endif +#if CYTHON_USE_TYPE_SPECS && PY_VERSION_HEX >= 0x03080000 +#define __Pyx_PyHeapTypeObject_GC_Del(obj) {\ + PyTypeObject *type = Py_TYPE((PyObject*)obj);\ + assert(__Pyx_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE));\ + PyObject_GC_Del(obj);\ + Py_DECREF(type);\ +} +#else +#define __Pyx_PyHeapTypeObject_GC_Del(obj) PyObject_GC_Del(obj) +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define CYTHON_PEP393_ENABLED 1 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GetLength(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_ReadChar(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((void)u, 1114111U) + #define __Pyx_PyUnicode_KIND(u) ((void)u, (0)) + #define __Pyx_PyUnicode_DATA(u) ((void*)u) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)k, PyUnicode_ReadChar((PyObject*)(d), i)) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GetLength(u)) +#elif PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) + #define CYTHON_PEP393_ENABLED 1 + #if PY_VERSION_HEX >= 0x030C0000 + #define __Pyx_PyUnicode_READY(op) (0) + #else + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ + 0 : _PyUnicode_Ready((PyObject *)(op))) + #endif + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) + #define __Pyx_PyUnicode_KIND(u) ((int)PyUnicode_KIND(u)) + #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) + #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, (Py_UCS4) ch) + #if PY_VERSION_HEX >= 0x030C0000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) + #else + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length)) + #else + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) + #endif + #endif +#else + #define CYTHON_PEP393_ENABLED 0 + #define PyUnicode_1BYTE_KIND 1 + #define PyUnicode_2BYTE_KIND 2 + #define PyUnicode_4BYTE_KIND 4 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535U : 1114111U) + #define __Pyx_PyUnicode_KIND(u) ((int)sizeof(Py_UNICODE)) + #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = (Py_UNICODE) ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) +#endif +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) +#else + #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ + PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) +#endif +#if CYTHON_COMPILING_IN_PYPY + #if !defined(PyUnicode_DecodeUnicodeEscape) + #define PyUnicode_DecodeUnicodeEscape(s, size, errors) PyUnicode_Decode(s, size, "unicode_escape", errors) + #endif + #if !defined(PyUnicode_Contains) || (PY_MAJOR_VERSION == 2 && PYPY_VERSION_NUM < 0x07030500) + #undef PyUnicode_Contains + #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) + #endif + #if !defined(PyByteArray_Check) + #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) + #endif + #if !defined(PyObject_Format) + #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) + #endif +#endif +#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) +#else + #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) +#endif +#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) + #define PyObject_ASCII(o) PyObject_Repr(o) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBaseString_Type PyUnicode_Type + #define PyStringObject PyUnicodeObject + #define PyString_Type PyUnicode_Type + #define PyString_Check PyUnicode_Check + #define PyString_CheckExact PyUnicode_CheckExact +#ifndef PyObject_Unicode + #define PyObject_Unicode PyObject_Str +#endif +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) + #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) +#else + #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) + #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) +#endif +#if CYTHON_COMPILING_IN_CPYTHON + #define __Pyx_PySequence_ListKeepNew(obj)\ + (likely(PyList_CheckExact(obj) && Py_REFCNT(obj) == 1) ? __Pyx_NewRef(obj) : PySequence_List(obj)) +#else + #define __Pyx_PySequence_ListKeepNew(obj) PySequence_List(obj) +#endif +#ifndef PySet_CheckExact + #define PySet_CheckExact(obj) __Pyx_IS_TYPE(obj, &PySet_Type) +#endif +#if PY_VERSION_HEX >= 0x030900A4 + #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) +#else + #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) +#endif +#if CYTHON_ASSUME_SAFE_MACROS + #define __Pyx_PySequence_ITEM(o, i) PySequence_ITEM(o, i) + #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq) + #define __Pyx_PyTuple_SET_ITEM(o, i, v) (PyTuple_SET_ITEM(o, i, v), (0)) + #define __Pyx_PyList_SET_ITEM(o, i, v) (PyList_SET_ITEM(o, i, v), (0)) + #define __Pyx_PyTuple_GET_SIZE(o) PyTuple_GET_SIZE(o) + #define __Pyx_PyList_GET_SIZE(o) PyList_GET_SIZE(o) + #define __Pyx_PySet_GET_SIZE(o) PySet_GET_SIZE(o) + #define __Pyx_PyBytes_GET_SIZE(o) PyBytes_GET_SIZE(o) + #define __Pyx_PyByteArray_GET_SIZE(o) PyByteArray_GET_SIZE(o) +#else + #define __Pyx_PySequence_ITEM(o, i) PySequence_GetItem(o, i) + #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq) + #define __Pyx_PyTuple_SET_ITEM(o, i, v) PyTuple_SetItem(o, i, v) + #define __Pyx_PyList_SET_ITEM(o, i, v) PyList_SetItem(o, i, v) + #define __Pyx_PyTuple_GET_SIZE(o) PyTuple_Size(o) + #define __Pyx_PyList_GET_SIZE(o) PyList_Size(o) + #define __Pyx_PySet_GET_SIZE(o) PySet_Size(o) + #define __Pyx_PyBytes_GET_SIZE(o) PyBytes_Size(o) + #define __Pyx_PyByteArray_GET_SIZE(o) PyByteArray_Size(o) +#endif +#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1 + #define __Pyx_PyImport_AddModuleRef(name) PyImport_AddModuleRef(name) +#else + static CYTHON_INLINE PyObject *__Pyx_PyImport_AddModuleRef(const char *name) { + PyObject *module = PyImport_AddModule(name); + Py_XINCREF(module); + return module; + } +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyIntObject PyLongObject + #define PyInt_Type PyLong_Type + #define PyInt_Check(op) PyLong_Check(op) + #define PyInt_CheckExact(op) PyLong_CheckExact(op) + #define __Pyx_Py3Int_Check(op) PyLong_Check(op) + #define __Pyx_Py3Int_CheckExact(op) PyLong_CheckExact(op) + #define PyInt_FromString PyLong_FromString + #define PyInt_FromUnicode PyLong_FromUnicode + #define PyInt_FromLong PyLong_FromLong + #define PyInt_FromSize_t PyLong_FromSize_t + #define PyInt_FromSsize_t PyLong_FromSsize_t + #define PyInt_AsLong PyLong_AsLong + #define PyInt_AS_LONG PyLong_AS_LONG + #define PyInt_AsSsize_t PyLong_AsSsize_t + #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask + #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask + #define PyNumber_Int PyNumber_Long +#else + #define __Pyx_Py3Int_Check(op) (PyLong_Check(op) || PyInt_Check(op)) + #define __Pyx_Py3Int_CheckExact(op) (PyLong_CheckExact(op) || PyInt_CheckExact(op)) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBoolObject PyLongObject +#endif +#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY + #ifndef PyUnicode_InternFromString + #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) + #endif +#endif +#if PY_VERSION_HEX < 0x030200A4 + typedef long Py_hash_t; + #define __Pyx_PyInt_FromHash_t PyInt_FromLong + #define __Pyx_PyInt_AsHash_t __Pyx_PyIndex_AsHash_t +#else + #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t + #define __Pyx_PyInt_AsHash_t __Pyx_PyIndex_AsSsize_t +#endif +#if CYTHON_USE_ASYNC_SLOTS + #if PY_VERSION_HEX >= 0x030500B1 + #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods + #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) + #else + #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) + #endif +#else + #define __Pyx_PyType_AsAsync(obj) NULL +#endif +#ifndef __Pyx_PyAsyncMethodsStruct + typedef struct { + unaryfunc am_await; + unaryfunc am_aiter; + unaryfunc am_anext; + } __Pyx_PyAsyncMethodsStruct; +#endif + +#if defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS) + #if !defined(_USE_MATH_DEFINES) + #define _USE_MATH_DEFINES + #endif +#endif +#include +#ifdef NAN +#define __PYX_NAN() ((float) NAN) +#else +static CYTHON_INLINE float __PYX_NAN() { + float value; + memset(&value, 0xFF, sizeof(value)); + return value; +} +#endif +#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) +#define __Pyx_truncl trunc +#else +#define __Pyx_truncl truncl +#endif + +#define __PYX_MARK_ERR_POS(f_index, lineno) \ + { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } +#define __PYX_ERR(f_index, lineno, Ln_error) \ + { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; } + +#ifdef CYTHON_EXTERN_C + #undef __PYX_EXTERN_C + #define __PYX_EXTERN_C CYTHON_EXTERN_C +#elif defined(__PYX_EXTERN_C) + #ifdef _MSC_VER + #pragma message ("Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.") + #else + #warning Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead. + #endif +#else + #ifdef __cplusplus + #define __PYX_EXTERN_C extern "C" + #else + #define __PYX_EXTERN_C extern + #endif +#endif + +#define __PYX_HAVE__cython_code__send_ads +#define __PYX_HAVE_API__cython_code__send_ads +/* Early includes */ +#ifdef _OPENMP +#include +#endif /* _OPENMP */ + +#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS) +#define CYTHON_WITHOUT_ASSERTIONS +#endif + +typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; + const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; + +#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) +#define __PYX_DEFAULT_STRING_ENCODING "" +#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString +#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#define __Pyx_uchar_cast(c) ((unsigned char)c) +#define __Pyx_long_cast(x) ((long)x) +#define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ + (sizeof(type) < sizeof(Py_ssize_t)) ||\ + (sizeof(type) > sizeof(Py_ssize_t) &&\ + likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX) &&\ + (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ + v == (type)PY_SSIZE_T_MIN))) ||\ + (sizeof(type) == sizeof(Py_ssize_t) &&\ + (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX))) ) +static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { + return (size_t) i < (size_t) limit; +} +#if defined (__cplusplus) && __cplusplus >= 201103L + #include + #define __Pyx_sst_abs(value) std::abs(value) +#elif SIZEOF_INT >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) abs(value) +#elif SIZEOF_LONG >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) labs(value) +#elif defined (_MSC_VER) + #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value)) +#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define __Pyx_sst_abs(value) llabs(value) +#elif defined (__GNUC__) + #define __Pyx_sst_abs(value) __builtin_llabs(value) +#else + #define __Pyx_sst_abs(value) ((value<0) ? -value : value) +#endif +static CYTHON_INLINE Py_ssize_t __Pyx_ssize_strlen(const char *s); +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*); +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); +static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char*); +#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) +#define __Pyx_PyBytes_FromString PyBytes_FromString +#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); +#if PY_MAJOR_VERSION < 3 + #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#else + #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize +#endif +#define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyObject_AsWritableString(s) ((char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableSString(s) ((signed char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) +#define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) +#define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) +#define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) +#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) +#define __Pyx_PyUnicode_FromOrdinal(o) PyUnicode_FromOrdinal((int)o) +#define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode +#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) +#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b); +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*); +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); +#define __Pyx_PySequence_Tuple(obj)\ + (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj)) +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*); +#if CYTHON_ASSUME_SAFE_MACROS +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) +#else +#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) +#endif +#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) +#else +#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) +#endif +#if CYTHON_USE_PYLONG_INTERNALS + #if PY_VERSION_HEX >= 0x030C00A7 + #ifndef _PyLong_SIGN_MASK + #define _PyLong_SIGN_MASK 3 + #endif + #ifndef _PyLong_NON_SIZE_BITS + #define _PyLong_NON_SIZE_BITS 3 + #endif + #define __Pyx_PyLong_Sign(x) (((PyLongObject*)x)->long_value.lv_tag & _PyLong_SIGN_MASK) + #define __Pyx_PyLong_IsNeg(x) ((__Pyx_PyLong_Sign(x) & 2) != 0) + #define __Pyx_PyLong_IsNonNeg(x) (!__Pyx_PyLong_IsNeg(x)) + #define __Pyx_PyLong_IsZero(x) (__Pyx_PyLong_Sign(x) & 1) + #define __Pyx_PyLong_IsPos(x) (__Pyx_PyLong_Sign(x) == 0) + #define __Pyx_PyLong_CompactValueUnsigned(x) (__Pyx_PyLong_Digits(x)[0]) + #define __Pyx_PyLong_DigitCount(x) ((Py_ssize_t) (((PyLongObject*)x)->long_value.lv_tag >> _PyLong_NON_SIZE_BITS)) + #define __Pyx_PyLong_SignedDigitCount(x)\ + ((1 - (Py_ssize_t) __Pyx_PyLong_Sign(x)) * __Pyx_PyLong_DigitCount(x)) + #if defined(PyUnstable_Long_IsCompact) && defined(PyUnstable_Long_CompactValue) + #define __Pyx_PyLong_IsCompact(x) PyUnstable_Long_IsCompact((PyLongObject*) x) + #define __Pyx_PyLong_CompactValue(x) PyUnstable_Long_CompactValue((PyLongObject*) x) + #else + #define __Pyx_PyLong_IsCompact(x) (((PyLongObject*)x)->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS)) + #define __Pyx_PyLong_CompactValue(x) ((1 - (Py_ssize_t) __Pyx_PyLong_Sign(x)) * (Py_ssize_t) __Pyx_PyLong_Digits(x)[0]) + #endif + typedef Py_ssize_t __Pyx_compact_pylong; + typedef size_t __Pyx_compact_upylong; + #else + #define __Pyx_PyLong_IsNeg(x) (Py_SIZE(x) < 0) + #define __Pyx_PyLong_IsNonNeg(x) (Py_SIZE(x) >= 0) + #define __Pyx_PyLong_IsZero(x) (Py_SIZE(x) == 0) + #define __Pyx_PyLong_IsPos(x) (Py_SIZE(x) > 0) + #define __Pyx_PyLong_CompactValueUnsigned(x) ((Py_SIZE(x) == 0) ? 0 : __Pyx_PyLong_Digits(x)[0]) + #define __Pyx_PyLong_DigitCount(x) __Pyx_sst_abs(Py_SIZE(x)) + #define __Pyx_PyLong_SignedDigitCount(x) Py_SIZE(x) + #define __Pyx_PyLong_IsCompact(x) (Py_SIZE(x) == 0 || Py_SIZE(x) == 1 || Py_SIZE(x) == -1) + #define __Pyx_PyLong_CompactValue(x)\ + ((Py_SIZE(x) == 0) ? (sdigit) 0 : ((Py_SIZE(x) < 0) ? -(sdigit)__Pyx_PyLong_Digits(x)[0] : (sdigit)__Pyx_PyLong_Digits(x)[0])) + typedef sdigit __Pyx_compact_pylong; + typedef digit __Pyx_compact_upylong; + #endif + #if PY_VERSION_HEX >= 0x030C00A5 + #define __Pyx_PyLong_Digits(x) (((PyLongObject*)x)->long_value.ob_digit) + #else + #define __Pyx_PyLong_Digits(x) (((PyLongObject*)x)->ob_digit) + #endif +#endif +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII +#include +static int __Pyx_sys_getdefaultencoding_not_ascii; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + PyObject* ascii_chars_u = NULL; + PyObject* ascii_chars_b = NULL; + const char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + if (strcmp(default_encoding_c, "ascii") == 0) { + __Pyx_sys_getdefaultencoding_not_ascii = 0; + } else { + char ascii_chars[128]; + int c; + for (c = 0; c < 128; c++) { + ascii_chars[c] = (char) c; + } + __Pyx_sys_getdefaultencoding_not_ascii = 1; + ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); + if (!ascii_chars_u) goto bad; + ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); + if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { + PyErr_Format( + PyExc_ValueError, + "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", + default_encoding_c); + goto bad; + } + Py_DECREF(ascii_chars_u); + Py_DECREF(ascii_chars_b); + } + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + Py_XDECREF(ascii_chars_u); + Py_XDECREF(ascii_chars_b); + return -1; +} +#endif +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) +#else +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +#include +static char* __PYX_DEFAULT_STRING_ENCODING; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1); + if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; + strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + return -1; +} +#endif +#endif + + +/* Test for GCC > 2.95 */ +#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) +#else /* !__GNUC__ or GCC < 2.95 */ + #define likely(x) (x) + #define unlikely(x) (x) +#endif /* __GNUC__ */ +static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; } + +#if !CYTHON_USE_MODULE_STATE +static PyObject *__pyx_m = NULL; +#endif +static int __pyx_lineno; +static int __pyx_clineno = 0; +static const char * __pyx_cfilenm = __FILE__; +static const char *__pyx_filename; + +/* #### Code section: filename_table ### */ + +static const char *__pyx_f[] = { + "cython_code/send_ads.pyx", + "", +}; +/* #### Code section: utility_code_proto_before_types ### */ +/* ForceInitThreads.proto */ +#ifndef __PYX_FORCE_INIT_THREADS + #define __PYX_FORCE_INIT_THREADS 0 +#endif + +/* #### Code section: numeric_typedefs ### */ +/* #### Code section: complex_type_declarations ### */ +/* #### Code section: type_declarations ### */ + +/*--- Type declarations ---*/ +struct __pyx_obj_11cython_code_8send_ads_MyDatabase; + +/* "cython_code/send_ads.pyx":9 + * from loader import db, file_db + * + * cdef class MyDatabase: # <<<<<<<<<<<<<< + * cdef str host, user, password, database + * cdef object connection # Use 'object' since it's a generic Python object + */ +struct __pyx_obj_11cython_code_8send_ads_MyDatabase { + PyObject_HEAD + PyObject *host; + PyObject *user; + PyObject *password; + PyObject *database; + PyObject *connection; + PyObject *cursor; +}; + +/* #### Code section: utility_code_proto ### */ + +/* --- Runtime support code (head) --- */ +/* Refnanny.proto */ +#ifndef CYTHON_REFNANNY + #define CYTHON_REFNANNY 0 +#endif +#if CYTHON_REFNANNY + typedef struct { + void (*INCREF)(void*, PyObject*, Py_ssize_t); + void (*DECREF)(void*, PyObject*, Py_ssize_t); + void (*GOTREF)(void*, PyObject*, Py_ssize_t); + void (*GIVEREF)(void*, PyObject*, Py_ssize_t); + void* (*SetupContext)(const char*, Py_ssize_t, const char*); + void (*FinishContext)(void**); + } __Pyx_RefNannyAPIStruct; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); + #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; +#ifdef WITH_THREAD + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + if (acquire_gil) {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__));\ + PyGILState_Release(__pyx_gilstate_save);\ + } else {\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__));\ + } + #define __Pyx_RefNannyFinishContextNogil() {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __Pyx_RefNannyFinishContext();\ + PyGILState_Release(__pyx_gilstate_save);\ + } +#else + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__)) + #define __Pyx_RefNannyFinishContextNogil() __Pyx_RefNannyFinishContext() +#endif + #define __Pyx_RefNannyFinishContextNogil() {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __Pyx_RefNannyFinishContext();\ + PyGILState_Release(__pyx_gilstate_save);\ + } + #define __Pyx_RefNannyFinishContext()\ + __Pyx_RefNanny->FinishContext(&__pyx_refnanny) + #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_XINCREF(r) do { if((r) == NULL); else {__Pyx_INCREF(r); }} while(0) + #define __Pyx_XDECREF(r) do { if((r) == NULL); else {__Pyx_DECREF(r); }} while(0) + #define __Pyx_XGOTREF(r) do { if((r) == NULL); else {__Pyx_GOTREF(r); }} while(0) + #define __Pyx_XGIVEREF(r) do { if((r) == NULL); else {__Pyx_GIVEREF(r);}} while(0) +#else + #define __Pyx_RefNannyDeclarations + #define __Pyx_RefNannySetupContext(name, acquire_gil) + #define __Pyx_RefNannyFinishContextNogil() + #define __Pyx_RefNannyFinishContext() + #define __Pyx_INCREF(r) Py_INCREF(r) + #define __Pyx_DECREF(r) Py_DECREF(r) + #define __Pyx_GOTREF(r) + #define __Pyx_GIVEREF(r) + #define __Pyx_XINCREF(r) Py_XINCREF(r) + #define __Pyx_XDECREF(r) Py_XDECREF(r) + #define __Pyx_XGOTREF(r) + #define __Pyx_XGIVEREF(r) +#endif +#define __Pyx_Py_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; Py_XDECREF(tmp);\ + } while (0) +#define __Pyx_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_XDECREF(tmp);\ + } while (0) +#define __Pyx_DECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_DECREF(tmp);\ + } while (0) +#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) +#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) + +/* TupleAndListFromArray.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n); +static CYTHON_INLINE PyObject* __Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n); +#endif + +/* IncludeStringH.proto */ +#include + +/* BytesEquals.proto */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); + +/* UnicodeEquals.proto */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); + +/* fastcall.proto */ +#if CYTHON_AVOID_BORROWED_REFS + #define __Pyx_Arg_VARARGS(args, i) PySequence_GetItem(args, i) +#elif CYTHON_ASSUME_SAFE_MACROS + #define __Pyx_Arg_VARARGS(args, i) PyTuple_GET_ITEM(args, i) +#else + #define __Pyx_Arg_VARARGS(args, i) PyTuple_GetItem(args, i) +#endif +#if CYTHON_AVOID_BORROWED_REFS + #define __Pyx_Arg_NewRef_VARARGS(arg) __Pyx_NewRef(arg) + #define __Pyx_Arg_XDECREF_VARARGS(arg) Py_XDECREF(arg) +#else + #define __Pyx_Arg_NewRef_VARARGS(arg) arg + #define __Pyx_Arg_XDECREF_VARARGS(arg) +#endif +#define __Pyx_NumKwargs_VARARGS(kwds) PyDict_Size(kwds) +#define __Pyx_KwValues_VARARGS(args, nargs) NULL +#define __Pyx_GetKwValue_VARARGS(kw, kwvalues, s) __Pyx_PyDict_GetItemStrWithError(kw, s) +#define __Pyx_KwargsAsDict_VARARGS(kw, kwvalues) PyDict_Copy(kw) +#if CYTHON_METH_FASTCALL + #define __Pyx_Arg_FASTCALL(args, i) args[i] + #define __Pyx_NumKwargs_FASTCALL(kwds) PyTuple_GET_SIZE(kwds) + #define __Pyx_KwValues_FASTCALL(args, nargs) ((args) + (nargs)) + static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s); +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000 + CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues); + #else + #define __Pyx_KwargsAsDict_FASTCALL(kw, kwvalues) _PyStack_AsDict(kwvalues, kw) + #endif + #define __Pyx_Arg_NewRef_FASTCALL(arg) arg /* no-op, __Pyx_Arg_FASTCALL is direct and this needs + to have the same reference counting */ + #define __Pyx_Arg_XDECREF_FASTCALL(arg) +#else + #define __Pyx_Arg_FASTCALL __Pyx_Arg_VARARGS + #define __Pyx_NumKwargs_FASTCALL __Pyx_NumKwargs_VARARGS + #define __Pyx_KwValues_FASTCALL __Pyx_KwValues_VARARGS + #define __Pyx_GetKwValue_FASTCALL __Pyx_GetKwValue_VARARGS + #define __Pyx_KwargsAsDict_FASTCALL __Pyx_KwargsAsDict_VARARGS + #define __Pyx_Arg_NewRef_FASTCALL(arg) __Pyx_Arg_NewRef_VARARGS(arg) + #define __Pyx_Arg_XDECREF_FASTCALL(arg) __Pyx_Arg_XDECREF_VARARGS(arg) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS +#define __Pyx_ArgsSlice_VARARGS(args, start, stop) __Pyx_PyTuple_FromArray(&__Pyx_Arg_VARARGS(args, start), stop - start) +#define __Pyx_ArgsSlice_FASTCALL(args, start, stop) __Pyx_PyTuple_FromArray(&__Pyx_Arg_FASTCALL(args, start), stop - start) +#else +#define __Pyx_ArgsSlice_VARARGS(args, start, stop) PyTuple_GetSlice(args, start, stop) +#define __Pyx_ArgsSlice_FASTCALL(args, start, stop) PyTuple_GetSlice(args, start, stop) +#endif + +/* RaiseArgTupleInvalid.proto */ +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); + +/* RaiseDoubleKeywords.proto */ +static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); + +/* ParseKeywords.proto */ +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject *const *kwvalues, + PyObject **argnames[], + PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, + const char* function_name); + +/* ArgTypeTest.proto */ +#define __Pyx_ArgTypeTest(obj, type, none_allowed, name, exact)\ + ((likely(__Pyx_IS_TYPE(obj, type) | (none_allowed && (obj == Py_None)))) ? 1 :\ + __Pyx__ArgTypeTest(obj, type, name, exact)) +static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact); + +/* PyObjectGetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) +#endif + +/* PyFunctionFastCall.proto */ +#if CYTHON_FAST_PYCALL +#if !CYTHON_VECTORCALL +#define __Pyx_PyFunction_FastCall(func, args, nargs)\ + __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL) +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs); +#endif +#define __Pyx_BUILD_ASSERT_EXPR(cond)\ + (sizeof(char [1 - 2*!(cond)]) - 1) +#ifndef Py_MEMBER_SIZE +#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) +#endif +#if !CYTHON_VECTORCALL +#if PY_VERSION_HEX >= 0x03080000 + #include "frameobject.h" +#if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API + #ifndef Py_BUILD_CORE + #define Py_BUILD_CORE 1 + #endif + #include "internal/pycore_frame.h" +#endif + #define __Pxy_PyFrame_Initialize_Offsets() + #define __Pyx_PyFrame_GetLocalsplus(frame) ((frame)->f_localsplus) +#else + static size_t __pyx_pyframe_localsplus_offset = 0; + #include "frameobject.h" + #define __Pxy_PyFrame_Initialize_Offsets()\ + ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ + (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) + #define __Pyx_PyFrame_GetLocalsplus(frame)\ + (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) +#endif +#endif +#endif + +/* PyObjectCall.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); +#else +#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) +#endif + +/* PyObjectCallMethO.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); +#endif + +/* PyObjectFastCall.proto */ +#define __Pyx_PyObject_FastCall(func, args, nargs) __Pyx_PyObject_FastCallDict(func, args, (size_t)(nargs), NULL) +static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject **args, size_t nargs, PyObject *kwargs); + +/* KeywordStringCheck.proto */ +static int __Pyx_CheckKeywordStrings(PyObject *kw, const char* function_name, int kw_allowed); + +/* PyErrExceptionMatches.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err) +static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err); +#else +#define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(err) +#endif + +/* PyThreadStateGet.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; +#define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current; +#if PY_VERSION_HEX >= 0x030C00A6 +#define __Pyx_PyErr_Occurred() (__pyx_tstate->current_exception != NULL) +#define __Pyx_PyErr_CurrentExceptionType() (__pyx_tstate->current_exception ? (PyObject*) Py_TYPE(__pyx_tstate->current_exception) : (PyObject*) NULL) +#else +#define __Pyx_PyErr_Occurred() (__pyx_tstate->curexc_type != NULL) +#define __Pyx_PyErr_CurrentExceptionType() (__pyx_tstate->curexc_type) +#endif +#else +#define __Pyx_PyThreadState_declare +#define __Pyx_PyThreadState_assign +#define __Pyx_PyErr_Occurred() (PyErr_Occurred() != NULL) +#define __Pyx_PyErr_CurrentExceptionType() PyErr_Occurred() +#endif + +/* PyErrFetchRestore.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL) +#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A6 +#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL)) +#else +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#endif +#else +#define __Pyx_PyErr_Clear() PyErr_Clear() +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) +#endif + +/* PyObjectGetAttrStrNoError.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name); + +/* GetBuiltinName.proto */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name); + +/* PyDictVersioning.proto */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) +#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ + (version_var) = __PYX_GET_DICT_VERSION(dict);\ + (cache_var) = (value); +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ + (VAR) = __pyx_dict_cached_value;\ + } else {\ + (VAR) = __pyx_dict_cached_value = (LOOKUP);\ + __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ + }\ +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); +#else +#define __PYX_GET_DICT_VERSION(dict) (0) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); +#endif + +/* GetModuleGlobalName.proto */ +#if CYTHON_USE_DICT_VERSIONS +#define __Pyx_GetModuleGlobalName(var, name) do {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ + (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ + __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} while(0) +#define __Pyx_GetModuleGlobalNameUncached(var, name) do {\ + PY_UINT64_T __pyx_dict_version;\ + PyObject *__pyx_dict_cached_value;\ + (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} while(0) +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); +#else +#define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) +#define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); +#endif + +/* GetTopmostException.proto */ +#if CYTHON_USE_EXC_INFO_STACK && CYTHON_FAST_THREAD_STATE +static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate); +#endif + +/* SaveResetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#define __Pyx_ExceptionReset(type, value, tb) __Pyx__ExceptionReset(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +#else +#define __Pyx_ExceptionSave(type, value, tb) PyErr_GetExcInfo(type, value, tb) +#define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb) +#endif + +/* FastTypeChecks.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type) +#define __Pyx_TypeCheck2(obj, type1, type2) __Pyx_IsAnySubtype2(Py_TYPE(obj), (PyTypeObject *)type1, (PyTypeObject *)type2) +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b); +static CYTHON_INLINE int __Pyx_IsAnySubtype2(PyTypeObject *cls, PyTypeObject *a, PyTypeObject *b); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2); +#else +#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) +#define __Pyx_TypeCheck2(obj, type1, type2) (PyObject_TypeCheck(obj, (PyTypeObject *)type1) || PyObject_TypeCheck(obj, (PyTypeObject *)type2)) +#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type) +#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2)) +#endif +#define __Pyx_PyErr_ExceptionMatches2(err1, err2) __Pyx_PyErr_GivenExceptionMatches2(__Pyx_PyErr_CurrentExceptionType(), err1, err2) +#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) + +/* GetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_GetException(type, value, tb) __Pyx__GetException(__pyx_tstate, type, value, tb) +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* SwapException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* RaiseUnexpectedTypeError.proto */ +static int __Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj); + +/* GetAttr3.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *, PyObject *, PyObject *); + +/* PyObjectFormatSimple.proto */ +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyObject_FormatSimple(s, f) (\ + likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ + PyObject_Format(s, f)) +#elif PY_MAJOR_VERSION < 3 + #define __Pyx_PyObject_FormatSimple(s, f) (\ + likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ + likely(PyString_CheckExact(s)) ? PyUnicode_FromEncodedObject(s, NULL, "strict") :\ + PyObject_Format(s, f)) +#elif CYTHON_USE_TYPE_SLOTS + #define __Pyx_PyObject_FormatSimple(s, f) (\ + likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ + likely(PyLong_CheckExact(s)) ? PyLong_Type.tp_repr(s) :\ + likely(PyFloat_CheckExact(s)) ? PyFloat_Type.tp_repr(s) :\ + PyObject_Format(s, f)) +#else + #define __Pyx_PyObject_FormatSimple(s, f) (\ + likely(PyUnicode_CheckExact(s)) ? (Py_INCREF(s), s) :\ + PyObject_Format(s, f)) +#endif + +/* JoinPyUnicode.proto */ +static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, + Py_UCS4 max_char); + +/* UnpackUnboundCMethod.proto */ +typedef struct { + PyObject *type; + PyObject **method_name; + PyCFunction func; + PyObject *method; + int flag; +} __Pyx_CachedCFunction; + +/* CallUnboundCMethod1.proto */ +static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg); +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg); +#else +#define __Pyx_CallUnboundCMethod1(cfunc, self, arg) __Pyx__CallUnboundCMethod1(cfunc, self, arg) +#endif + +/* DictGetItem.proto */ +#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY +static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key); +#define __Pyx_PyObject_Dict_GetItem(obj, name)\ + (likely(PyDict_CheckExact(obj)) ?\ + __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name)) +#else +#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key) +#define __Pyx_PyObject_Dict_GetItem(obj, name) PyObject_GetItem(obj, name) +#endif + +/* GCCDiagnostics.proto */ +#if !defined(__INTEL_COMPILER) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +#define __Pyx_HAS_GCC_DIAGNOSTIC +#endif + +/* BuildPyUnicode.proto */ +static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength, + int prepend_sign, char padding_char); + +/* CIntToPyUnicode.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_int(int value, Py_ssize_t width, char padding_char, char format_char); + +/* CIntToPyUnicode.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_Py_ssize_t(Py_ssize_t value, Py_ssize_t width, char padding_char, char format_char); + +/* GetItemInt.proto */ +#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\ + (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\ + __Pyx_GetItemInt_Generic(o, to_py_func(i)))) +#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ + (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ + (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, + int is_list, int wraparound, int boundscheck); + +/* PyIntBinop.proto */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); +#else +#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace, zerodivision_check)\ + (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2)) +#endif + +/* PySequenceContains.proto */ +static CYTHON_INLINE int __Pyx_PySequence_ContainsTF(PyObject* item, PyObject* seq, int eq) { + int result = PySequence_Contains(seq, item); + return unlikely(result < 0) ? result : (result == (eq == Py_EQ)); +} + +/* Import.proto */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); + +/* ImportFrom.proto */ +static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); + +/* RaiseException.proto */ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); + +/* GetAttr.proto */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *, PyObject *); + +/* HasAttr.proto */ +static CYTHON_INLINE int __Pyx_HasAttr(PyObject *, PyObject *); + +/* IncludeStructmemberH.proto */ +#include + +/* FixUpExtensionType.proto */ +#if CYTHON_USE_TYPE_SPECS +static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type); +#endif + +/* PyObjectCallNoArg.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); + +/* PyObjectCallOneArg.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); + +/* PyObjectGetMethod.proto */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); + +/* PyObjectCallMethod0.proto */ +static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); + +/* ValidateBasesTuple.proto */ +#if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS +static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases); +#endif + +/* PyType_Ready.proto */ +CYTHON_UNUSED static int __Pyx_PyType_Ready(PyTypeObject *t); + +/* PyObject_GenericGetAttrNoDict.proto */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr +#endif + +/* PyObject_GenericGetAttr.proto */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GenericGetAttr PyObject_GenericGetAttr +#endif + +/* SetupReduce.proto */ +#if !CYTHON_COMPILING_IN_LIMITED_API +static int __Pyx_setup_reduce(PyObject* type_obj); +#endif + +/* ImportDottedModule.proto */ +static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple); +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple); +#endif + +/* FetchSharedCythonModule.proto */ +static PyObject *__Pyx_FetchSharedCythonABIModule(void); + +/* FetchCommonType.proto */ +#if !CYTHON_USE_TYPE_SPECS +static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type); +#else +static PyTypeObject* __Pyx_FetchCommonTypeFromSpec(PyObject *module, PyType_Spec *spec, PyObject *bases); +#endif + +/* PyMethodNew.proto */ +#if CYTHON_COMPILING_IN_LIMITED_API +static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) { + PyObject *typesModule=NULL, *methodType=NULL, *result=NULL; + CYTHON_UNUSED_VAR(typ); + if (!self) + return __Pyx_NewRef(func); + typesModule = PyImport_ImportModule("types"); + if (!typesModule) return NULL; + methodType = PyObject_GetAttrString(typesModule, "MethodType"); + Py_DECREF(typesModule); + if (!methodType) return NULL; + result = PyObject_CallFunctionObjArgs(methodType, func, self, NULL); + Py_DECREF(methodType); + return result; +} +#elif PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) { + CYTHON_UNUSED_VAR(typ); + if (!self) + return __Pyx_NewRef(func); + return PyMethod_New(func, self); +} +#else + #define __Pyx_PyMethod_New PyMethod_New +#endif + +/* PyVectorcallFastCallDict.proto */ +#if CYTHON_METH_FASTCALL +static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw); +#endif + +/* CythonFunctionShared.proto */ +#define __Pyx_CyFunction_USED +#define __Pyx_CYFUNCTION_STATICMETHOD 0x01 +#define __Pyx_CYFUNCTION_CLASSMETHOD 0x02 +#define __Pyx_CYFUNCTION_CCLASS 0x04 +#define __Pyx_CYFUNCTION_COROUTINE 0x08 +#define __Pyx_CyFunction_GetClosure(f)\ + (((__pyx_CyFunctionObject *) (f))->func_closure) +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_CyFunction_GetClassObj(f)\ + (((__pyx_CyFunctionObject *) (f))->func_classobj) +#else + #define __Pyx_CyFunction_GetClassObj(f)\ + ((PyObject*) ((PyCMethodObject *) (f))->mm_class) +#endif +#define __Pyx_CyFunction_SetClassObj(f, classobj)\ + __Pyx__CyFunction_SetClassObj((__pyx_CyFunctionObject *) (f), (classobj)) +#define __Pyx_CyFunction_Defaults(type, f)\ + ((type *)(((__pyx_CyFunctionObject *) (f))->defaults)) +#define __Pyx_CyFunction_SetDefaultsGetter(f, g)\ + ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g) +typedef struct { +#if CYTHON_COMPILING_IN_LIMITED_API + PyObject_HEAD + PyObject *func; +#elif PY_VERSION_HEX < 0x030900B1 + PyCFunctionObject func; +#else + PyCMethodObject func; +#endif +#if CYTHON_BACKPORT_VECTORCALL + __pyx_vectorcallfunc func_vectorcall; +#endif +#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API + PyObject *func_weakreflist; +#endif + PyObject *func_dict; + PyObject *func_name; + PyObject *func_qualname; + PyObject *func_doc; + PyObject *func_globals; + PyObject *func_code; + PyObject *func_closure; +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + PyObject *func_classobj; +#endif + void *defaults; + int defaults_pyobjects; + size_t defaults_size; + int flags; + PyObject *defaults_tuple; + PyObject *defaults_kwdict; + PyObject *(*defaults_getter)(PyObject *); + PyObject *func_annotations; + PyObject *func_is_coroutine; +} __pyx_CyFunctionObject; +#undef __Pyx_CyOrPyCFunction_Check +#define __Pyx_CyFunction_Check(obj) __Pyx_TypeCheck(obj, __pyx_CyFunctionType) +#define __Pyx_CyOrPyCFunction_Check(obj) __Pyx_TypeCheck2(obj, __pyx_CyFunctionType, &PyCFunction_Type) +#define __Pyx_CyFunction_CheckExact(obj) __Pyx_IS_TYPE(obj, __pyx_CyFunctionType) +static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc); +#undef __Pyx_IsSameCFunction +#define __Pyx_IsSameCFunction(func, cfunc) __Pyx__IsSameCyOrCFunction(func, cfunc) +static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject* op, PyMethodDef *ml, + int flags, PyObject* qualname, + PyObject *closure, + PyObject *module, PyObject *globals, + PyObject* code); +static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj); +static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m, + size_t size, + int pyobjects); +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m, + PyObject *tuple); +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m, + PyObject *dict); +static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m, + PyObject *dict); +static int __pyx_CyFunction_init(PyObject *module); +#if CYTHON_METH_FASTCALL +static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +#if CYTHON_BACKPORT_VECTORCALL +#define __Pyx_CyFunction_func_vectorcall(f) (((__pyx_CyFunctionObject*)f)->func_vectorcall) +#else +#define __Pyx_CyFunction_func_vectorcall(f) (((PyCFunctionObject*)f)->vectorcall) +#endif +#endif + +/* CythonFunction.proto */ +static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, + int flags, PyObject* qualname, + PyObject *closure, + PyObject *module, PyObject *globals, + PyObject* code); + +/* CLineInTraceback.proto */ +#ifdef CYTHON_CLINE_IN_TRACEBACK +#define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0) +#else +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line); +#endif + +/* CodeObjectCache.proto */ +#if !CYTHON_COMPILING_IN_LIMITED_API +typedef struct { + PyCodeObject* code_object; + int code_line; +} __Pyx_CodeObjectCacheEntry; +struct __Pyx_CodeObjectCache { + int count; + int max_count; + __Pyx_CodeObjectCacheEntry* entries; +}; +static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); +static PyCodeObject *__pyx_find_code_object(int code_line); +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); +#endif + +/* AddTraceback.proto */ +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename); + +/* ExtTypeTest.proto */ +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type); + +/* CIntFromPy.proto */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); + +/* CIntFromPy.proto */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value); + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + +/* FormatTypeName.proto */ +#if CYTHON_COMPILING_IN_LIMITED_API +typedef PyObject *__Pyx_TypeName; +#define __Pyx_FMT_TYPENAME "%U" +static __Pyx_TypeName __Pyx_PyType_GetName(PyTypeObject* tp); +#define __Pyx_DECREF_TypeName(obj) Py_XDECREF(obj) +#else +typedef const char *__Pyx_TypeName; +#define __Pyx_FMT_TYPENAME "%.200s" +#define __Pyx_PyType_GetName(tp) ((tp)->tp_name) +#define __Pyx_DECREF_TypeName(obj) +#endif + +/* CStringEquals.proto */ +static CYTHON_INLINE int __Pyx_StrEq(const char *, const char *); + +/* CheckBinaryVersion.proto */ +static unsigned long __Pyx_get_runtime_version(void); +static int __Pyx_check_binary_version(unsigned long ct_version, unsigned long rt_version, int allow_newer); + +/* InitStrings.proto */ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); + +/* #### Code section: module_declarations ### */ + +/* Module declarations from "cython_code.send_ads" */ +static struct __pyx_obj_11cython_code_8send_ads_MyDatabase *__pyx_v_11cython_code_8send_ads_my_db = 0; +static PyObject *__pyx_f_11cython_code_8send_ads___pyx_unpickle_MyDatabase__set_state(struct __pyx_obj_11cython_code_8send_ads_MyDatabase *, PyObject *); /*proto*/ +/* #### Code section: typeinfo ### */ +/* #### Code section: before_global_var ### */ +#define __Pyx_MODULE_NAME "cython_code.send_ads" +extern int __pyx_module_is_main_cython_code__send_ads; +int __pyx_module_is_main_cython_code__send_ads = 0; + +/* Implementation of "cython_code.send_ads" */ +/* #### Code section: global_var ### */ +/* #### Code section: string_decls ### */ +static const char __pyx_k_[] = " - "; +static const char __pyx_k__2[] = ")"; +static const char __pyx_k__5[] = "."; +static const char __pyx_k__6[] = "*"; +static const char __pyx_k_db[] = "db"; +static const char __pyx_k_gc[] = "gc"; +static const char __pyx_k__24[] = "?"; +static const char __pyx_k_ads[] = "ads"; +static const char __pyx_k_err[] = "err"; +static const char __pyx_k_key[] = "key"; +static const char __pyx_k_new[] = "__new__"; +static const char __pyx_k_url[] = "url"; +static const char __pyx_k_HOST[] = "HOST"; +static const char __pyx_k_Sent[] = "\n\342\234\205 Sent: "; +static const char __pyx_k_data[] = "data"; +static const char __pyx_k_dict[] = "__dict__"; +static const char __pyx_k_host[] = "host"; +static const char __pyx_k_info[] = "info"; +static const char __pyx_k_json[] = "json"; +static const char __pyx_k_list[] = "list"; +static const char __pyx_k_main[] = "__main__"; +static const char __pyx_k_name[] = "__name__"; +static const char __pyx_k_post[] = "post"; +static const char __pyx_k_self[] = "self"; +static const char __pyx_k_spec[] = "__spec__"; +static const char __pyx_k_test[] = "__test__"; +static const char __pyx_k_text[] = "text"; +static const char __pyx_k_time[] = "time"; +static const char __pyx_k_user[] = "user"; +static const char __pyx_k_Error[] = "Error"; +static const char __pyx_k_Total[] = " (Total: "; +static const char __pyx_k_error[] = "error"; +static const char __pyx_k_mysql[] = "mysql"; +static const char __pyx_k_sleep[] = "sleep"; +static const char __pyx_k_start[] = "start"; +static const char __pyx_k_state[] = "state"; +static const char __pyx_k_Failed[] = "\n\342\235\214 Failed: "; +static const char __pyx_k_cursor[] = "cursor"; +static const char __pyx_k_dict_2[] = "_dict"; +static const char __pyx_k_enable[] = "enable"; +static const char __pyx_k_end_id[] = "end_id"; +static const char __pyx_k_import[] = "__import__"; +static const char __pyx_k_kwargs[] = "kwargs"; +static const char __pyx_k_loader[] = "loader"; +static const char __pyx_k_pickle[] = "pickle"; +static const char __pyx_k_reduce[] = "__reduce__"; +static const char __pyx_k_result[] = "result"; +static const char __pyx_k_return[] = "return"; +static const char __pyx_k_update[] = "update"; +static const char __pyx_k_caption[] = "caption"; +static const char __pyx_k_chat_id[] = "chat_id"; +static const char __pyx_k_connect[] = "connect"; +static const char __pyx_k_disable[] = "disable"; +static const char __pyx_k_execute[] = "execute"; +static const char __pyx_k_file_db[] = "file_db"; +static const char __pyx_k_logging[] = "logging"; +static const char __pyx_k_End_Time[] = "\n\360\237\225\222 End Time: "; +static const char __pyx_k_add_data[] = "add_data"; +static const char __pyx_k_ads_data[] = "ads_data"; +static const char __pyx_k_database[] = "database"; +static const char __pyx_k_end_time[] = "end_time"; +static const char __pyx_k_fetchall[] = "fetchall"; +static const char __pyx_k_getstate[] = "__getstate__"; +static const char __pyx_k_password[] = "password"; +static const char __pyx_k_per_time[] = "per_time"; +static const char __pyx_k_pyx_type[] = "__pyx_type"; +static const char __pyx_k_requests[] = "requests"; +static const char __pyx_k_response[] = "response"; +static const char __pyx_k_send_ads[] = "send_ads"; +static const char __pyx_k_setstate[] = "__setstate__"; +static const char __pyx_k_start_id[] = "start_id"; +static const char __pyx_k_strftime[] = "strftime"; +static const char __pyx_k_BOT_TOKEN[] = "BOT_TOKEN"; +static const char __pyx_k_connector[] = "connector"; +static const char __pyx_k_end_index[] = "end_index"; +static const char __pyx_k_isenabled[] = "isenabled"; +static const char __pyx_k_localtime[] = "localtime"; +static const char __pyx_k_pyx_state[] = "__pyx_state"; +static const char __pyx_k_reconnect[] = "reconnect"; +static const char __pyx_k_reduce_ex[] = "__reduce_ex__"; +static const char __pyx_k_sql_query[] = "sql_query"; +static const char __pyx_k_MYSQL_USER[] = "MYSQL_USER"; +static const char __pyx_k_MyDatabase[] = "MyDatabase"; +static const char __pyx_k_Start_Time[] = "\n\342\217\260 Start Time: "; +static const char __pyx_k_autocommit[] = "autocommit"; +static const char __pyx_k_done_count[] = "done_count"; +static const char __pyx_k_fail_count[] = "fail_count"; +static const char __pyx_k_message_id[] = "message_id"; +static const char __pyx_k_pyx_result[] = "__pyx_result"; +static const char __pyx_k_reading_db[] = "reading_db"; +static const char __pyx_k_start_time[] = "start-time"; +static const char __pyx_k_total_time[] = "total_time"; +static const char __pyx_k_PickleError[] = "PickleError"; +static const char __pyx_k_Y_m_d_H_M_S[] = "%Y-%m-%d %H:%M:%S"; +static const char __pyx_k_copyMessage[] = "/copyMessage"; +static const char __pyx_k_data_config[] = "data.config"; +static const char __pyx_k_sendMessage[] = "/sendMessage"; +static const char __pyx_k_start_index[] = "start_index"; +static const char __pyx_k_total_users[] = "total_users"; +static const char __pyx_k_users_batch[] = "users_batch"; +static const char __pyx_k_from_chat_id[] = "from_chat_id"; +static const char __pyx_k_initializing[] = "_initializing"; +static const char __pyx_k_is_coroutine[] = "_is_coroutine"; +static const char __pyx_k_pyx_checksum[] = "__pyx_checksum"; +static const char __pyx_k_query_values[] = "query_values"; +static const char __pyx_k_reply_markup[] = "reply_markup"; +static const char __pyx_k_start_time_2[] = "start_time"; +static const char __pyx_k_stringsource[] = ""; +static const char __pyx_k_use_setstate[] = "use_setstate"; +static const char __pyx_k_reduce_cython[] = "__reduce_cython__"; +static const char __pyx_k_MYSQL_DATABASE[] = "MYSQL_DATABASE"; +static const char __pyx_k_MYSQL_PASSWORD[] = "MYSQL_PASSWORD"; +static const char __pyx_k_mysql_connector[] = "mysql.connector"; +static const char __pyx_k_pyx_PickleError[] = "__pyx_PickleError"; +static const char __pyx_k_setstate_cython[] = "__setstate_cython__"; +static const char __pyx_k_summary_message[] = "summary_message"; +static const char __pyx_k_copy_message_sync[] = "copy_message_sync"; +static const char __pyx_k_send_message_sync[] = "send_message_sync"; +static const char __pyx_k_asyncio_coroutines[] = "asyncio.coroutines"; +static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; +static const char __pyx_k_select_users_by_id[] = "select_users_by_id"; +static const char __pyx_k_MyDatabase_reconnect[] = "MyDatabase.reconnect"; +static const char __pyx_k_Sending_ads_to_users[] = "Sending ads to users "; +static const char __pyx_k_cython_code_send_ads[] = "cython_code.send_ads"; +static const char __pyx_k_pyx_unpickle_MyDatabase[] = "__pyx_unpickle_MyDatabase"; +static const char __pyx_k_cython_code_send_ads_pyx[] = "cython_code/send_ads.pyx"; +static const char __pyx_k_MyDatabase___reduce_cython[] = "MyDatabase.__reduce_cython__"; +static const char __pyx_k_https_api_telegram_org_bot[] = "https://api.telegram.org/bot"; +static const char __pyx_k_MyDatabase___setstate_cython[] = "MyDatabase.__setstate_cython__"; +static const char __pyx_k_MyDatabase_select_users_by_id[] = "MyDatabase.select_users_by_id"; +static const char __pyx_k_Advertisement_Sending_Completed[] = "\360\237\223\254 Advertisement Sending Completed\n\n\360\237\221\245 Total Users: "; +static const char __pyx_k_Incompatible_checksums_0x_x_vs_0[] = "Incompatible checksums (0x%x vs (0xc59a5d0, 0xee418c5, 0x43b1ea3) = (connection, cursor, database, host, password, user))"; +static const char __pyx_k_SELECT_FROM_users_WHERE_id_s_AND[] = "SELECT * FROM `users` WHERE `id` >= %s AND `id` < %s;"; +/* #### Code section: decls ### */ +static int __pyx_pf_11cython_code_8send_ads_10MyDatabase___init__(struct __pyx_obj_11cython_code_8send_ads_MyDatabase *__pyx_v_self, PyObject *__pyx_v_host, PyObject *__pyx_v_user, PyObject *__pyx_v_password, PyObject *__pyx_v_database); /* proto */ +static PyObject *__pyx_pf_11cython_code_8send_ads_10MyDatabase_2reconnect(struct __pyx_obj_11cython_code_8send_ads_MyDatabase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_11cython_code_8send_ads_10MyDatabase_4select_users_by_id(struct __pyx_obj_11cython_code_8send_ads_MyDatabase *__pyx_v_self, int __pyx_v_start_id, int __pyx_v_end_id); /* proto */ +static PyObject *__pyx_pf_11cython_code_8send_ads_10MyDatabase_6__reduce_cython__(struct __pyx_obj_11cython_code_8send_ads_MyDatabase *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_11cython_code_8send_ads_10MyDatabase_8__setstate_cython__(struct __pyx_obj_11cython_code_8send_ads_MyDatabase *__pyx_v_self, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_pf_11cython_code_8send_ads_copy_message_sync(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_chat_id, int __pyx_v_from_chat_id, int __pyx_v_message_id, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_11cython_code_8send_ads_2send_message_sync(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_chat_id, PyObject *__pyx_v_text, PyObject *__pyx_v_kwargs); /* proto */ +static PyObject *__pyx_pf_11cython_code_8send_ads_4send_ads(CYTHON_UNUSED PyObject *__pyx_self); /* proto */ +static PyObject *__pyx_pf_11cython_code_8send_ads_6__pyx_unpickle_MyDatabase(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state); /* proto */ +static PyObject *__pyx_tp_new_11cython_code_8send_ads_MyDatabase(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +static __Pyx_CachedCFunction __pyx_umethod_PyDict_Type_update = {0, 0, 0, 0, 0}; +/* #### Code section: late_includes ### */ +/* #### Code section: module_state ### */ +typedef struct { + PyObject *__pyx_d; + PyObject *__pyx_b; + PyObject *__pyx_cython_runtime; + PyObject *__pyx_empty_tuple; + PyObject *__pyx_empty_bytes; + PyObject *__pyx_empty_unicode; + #ifdef __Pyx_CyFunction_USED + PyTypeObject *__pyx_CyFunctionType; + #endif + #ifdef __Pyx_FusedFunction_USED + PyTypeObject *__pyx_FusedFunctionType; + #endif + #ifdef __Pyx_Generator_USED + PyTypeObject *__pyx_GeneratorType; + #endif + #ifdef __Pyx_IterableCoroutine_USED + PyTypeObject *__pyx_IterableCoroutineType; + #endif + #ifdef __Pyx_Coroutine_USED + PyTypeObject *__pyx_CoroutineAwaitType; + #endif + #ifdef __Pyx_Coroutine_USED + PyTypeObject *__pyx_CoroutineType; + #endif + #if CYTHON_USE_MODULE_STATE + PyObject *__pyx_type_11cython_code_8send_ads_MyDatabase; + #endif + PyTypeObject *__pyx_ptype_11cython_code_8send_ads_MyDatabase; + PyObject *__pyx_kp_u_; + PyObject *__pyx_kp_u_Advertisement_Sending_Completed; + PyObject *__pyx_n_s_BOT_TOKEN; + PyObject *__pyx_kp_u_End_Time; + PyObject *__pyx_n_s_Error; + PyObject *__pyx_kp_u_Failed; + PyObject *__pyx_n_s_HOST; + PyObject *__pyx_kp_s_Incompatible_checksums_0x_x_vs_0; + PyObject *__pyx_n_s_MYSQL_DATABASE; + PyObject *__pyx_n_s_MYSQL_PASSWORD; + PyObject *__pyx_n_s_MYSQL_USER; + PyObject *__pyx_n_s_MyDatabase; + PyObject *__pyx_n_s_MyDatabase___reduce_cython; + PyObject *__pyx_n_s_MyDatabase___setstate_cython; + PyObject *__pyx_n_s_MyDatabase_reconnect; + PyObject *__pyx_n_s_MyDatabase_select_users_by_id; + PyObject *__pyx_n_s_PickleError; + PyObject *__pyx_kp_u_SELECT_FROM_users_WHERE_id_s_AND; + PyObject *__pyx_kp_u_Sending_ads_to_users; + PyObject *__pyx_kp_u_Sent; + PyObject *__pyx_kp_u_Start_Time; + PyObject *__pyx_kp_u_Total; + PyObject *__pyx_kp_u_Y_m_d_H_M_S; + PyObject *__pyx_kp_u__2; + PyObject *__pyx_n_s__24; + PyObject *__pyx_kp_u__5; + PyObject *__pyx_n_s__6; + PyObject *__pyx_n_s_add_data; + PyObject *__pyx_n_u_ads; + PyObject *__pyx_n_s_ads_data; + PyObject *__pyx_n_s_asyncio_coroutines; + PyObject *__pyx_n_s_autocommit; + PyObject *__pyx_n_s_caption; + PyObject *__pyx_n_u_caption; + PyObject *__pyx_n_s_chat_id; + PyObject *__pyx_n_u_chat_id; + PyObject *__pyx_n_s_cline_in_traceback; + PyObject *__pyx_n_s_connect; + PyObject *__pyx_n_s_connector; + PyObject *__pyx_kp_u_copyMessage; + PyObject *__pyx_n_s_copy_message_sync; + PyObject *__pyx_n_s_cursor; + PyObject *__pyx_n_s_cython_code_send_ads; + PyObject *__pyx_kp_s_cython_code_send_ads_pyx; + PyObject *__pyx_n_s_data; + PyObject *__pyx_n_s_data_config; + PyObject *__pyx_n_s_database; + PyObject *__pyx_n_s_db; + PyObject *__pyx_n_s_dict; + PyObject *__pyx_n_s_dict_2; + PyObject *__pyx_kp_u_disable; + PyObject *__pyx_n_u_done_count; + PyObject *__pyx_kp_u_enable; + PyObject *__pyx_n_s_end_id; + PyObject *__pyx_n_s_end_index; + PyObject *__pyx_n_s_end_time; + PyObject *__pyx_n_s_err; + PyObject *__pyx_n_s_error; + PyObject *__pyx_n_s_execute; + PyObject *__pyx_n_u_fail_count; + PyObject *__pyx_n_s_fetchall; + PyObject *__pyx_n_s_file_db; + PyObject *__pyx_n_s_from_chat_id; + PyObject *__pyx_n_u_from_chat_id; + PyObject *__pyx_kp_u_gc; + PyObject *__pyx_n_s_getstate; + PyObject *__pyx_n_s_host; + PyObject *__pyx_kp_u_https_api_telegram_org_bot; + PyObject *__pyx_n_s_import; + PyObject *__pyx_n_s_info; + PyObject *__pyx_n_s_initializing; + PyObject *__pyx_n_s_is_coroutine; + PyObject *__pyx_kp_u_isenabled; + PyObject *__pyx_n_s_json; + PyObject *__pyx_n_s_key; + PyObject *__pyx_n_s_kwargs; + PyObject *__pyx_n_s_list; + PyObject *__pyx_n_s_loader; + PyObject *__pyx_n_s_localtime; + PyObject *__pyx_n_s_logging; + PyObject *__pyx_n_s_main; + PyObject *__pyx_n_s_message_id; + PyObject *__pyx_n_u_message_id; + PyObject *__pyx_n_s_mysql; + PyObject *__pyx_n_s_mysql_connector; + PyObject *__pyx_n_s_name; + PyObject *__pyx_n_s_new; + PyObject *__pyx_n_s_password; + PyObject *__pyx_n_s_per_time; + PyObject *__pyx_n_u_per_time; + PyObject *__pyx_n_s_pickle; + PyObject *__pyx_n_s_post; + PyObject *__pyx_n_s_pyx_PickleError; + PyObject *__pyx_n_s_pyx_checksum; + PyObject *__pyx_n_s_pyx_result; + PyObject *__pyx_n_s_pyx_state; + PyObject *__pyx_n_s_pyx_type; + PyObject *__pyx_n_s_pyx_unpickle_MyDatabase; + PyObject *__pyx_n_s_query_values; + PyObject *__pyx_n_s_reading_db; + PyObject *__pyx_n_s_reconnect; + PyObject *__pyx_n_s_reduce; + PyObject *__pyx_n_s_reduce_cython; + PyObject *__pyx_n_s_reduce_ex; + PyObject *__pyx_n_s_reply_markup; + PyObject *__pyx_n_u_reply_markup; + PyObject *__pyx_n_s_requests; + PyObject *__pyx_n_s_response; + PyObject *__pyx_n_s_result; + PyObject *__pyx_n_s_return; + PyObject *__pyx_n_s_select_users_by_id; + PyObject *__pyx_n_s_self; + PyObject *__pyx_kp_u_sendMessage; + PyObject *__pyx_n_s_send_ads; + PyObject *__pyx_n_s_send_message_sync; + PyObject *__pyx_n_s_setstate; + PyObject *__pyx_n_s_setstate_cython; + PyObject *__pyx_n_s_sleep; + PyObject *__pyx_n_s_spec; + PyObject *__pyx_n_s_sql_query; + PyObject *__pyx_n_u_start; + PyObject *__pyx_n_s_start_id; + PyObject *__pyx_n_s_start_index; + PyObject *__pyx_kp_u_start_time; + PyObject *__pyx_n_s_start_time_2; + PyObject *__pyx_n_s_state; + PyObject *__pyx_n_s_strftime; + PyObject *__pyx_kp_s_stringsource; + PyObject *__pyx_n_s_summary_message; + PyObject *__pyx_n_s_test; + PyObject *__pyx_n_s_text; + PyObject *__pyx_n_u_text; + PyObject *__pyx_n_s_time; + PyObject *__pyx_n_s_total_time; + PyObject *__pyx_n_s_total_users; + PyObject *__pyx_n_u_total_users; + PyObject *__pyx_n_s_update; + PyObject *__pyx_n_s_url; + PyObject *__pyx_n_s_use_setstate; + PyObject *__pyx_n_s_user; + PyObject *__pyx_n_s_users_batch; + PyObject *__pyx_int_1; + PyObject *__pyx_int_2; + PyObject *__pyx_int_70983331; + PyObject *__pyx_int_207201744; + PyObject *__pyx_int_249829573; + PyObject *__pyx_tuple__3; + PyObject *__pyx_tuple__4; + PyObject *__pyx_tuple__7; + PyObject *__pyx_tuple__8; + PyObject *__pyx_tuple__10; + PyObject *__pyx_tuple__12; + PyObject *__pyx_tuple__14; + PyObject *__pyx_tuple__16; + PyObject *__pyx_tuple__18; + PyObject *__pyx_tuple__20; + PyObject *__pyx_tuple__22; + PyObject *__pyx_codeobj__9; + PyObject *__pyx_codeobj__11; + PyObject *__pyx_codeobj__13; + PyObject *__pyx_codeobj__15; + PyObject *__pyx_codeobj__17; + PyObject *__pyx_codeobj__19; + PyObject *__pyx_codeobj__21; + PyObject *__pyx_codeobj__23; +} __pyx_mstate; + +#if CYTHON_USE_MODULE_STATE +#ifdef __cplusplus +namespace { + extern struct PyModuleDef __pyx_moduledef; +} /* anonymous namespace */ +#else +static struct PyModuleDef __pyx_moduledef; +#endif + +#define __pyx_mstate(o) ((__pyx_mstate *)__Pyx_PyModule_GetState(o)) + +#define __pyx_mstate_global (__pyx_mstate(PyState_FindModule(&__pyx_moduledef))) + +#define __pyx_m (PyState_FindModule(&__pyx_moduledef)) +#else +static __pyx_mstate __pyx_mstate_global_static = +#ifdef __cplusplus + {}; +#else + {0}; +#endif +static __pyx_mstate *__pyx_mstate_global = &__pyx_mstate_global_static; +#endif +/* #### Code section: module_state_clear ### */ +#if CYTHON_USE_MODULE_STATE +static int __pyx_m_clear(PyObject *m) { + __pyx_mstate *clear_module_state = __pyx_mstate(m); + if (!clear_module_state) return 0; + Py_CLEAR(clear_module_state->__pyx_d); + Py_CLEAR(clear_module_state->__pyx_b); + Py_CLEAR(clear_module_state->__pyx_cython_runtime); + Py_CLEAR(clear_module_state->__pyx_empty_tuple); + Py_CLEAR(clear_module_state->__pyx_empty_bytes); + Py_CLEAR(clear_module_state->__pyx_empty_unicode); + #ifdef __Pyx_CyFunction_USED + Py_CLEAR(clear_module_state->__pyx_CyFunctionType); + #endif + #ifdef __Pyx_FusedFunction_USED + Py_CLEAR(clear_module_state->__pyx_FusedFunctionType); + #endif + Py_CLEAR(clear_module_state->__pyx_ptype_11cython_code_8send_ads_MyDatabase); + Py_CLEAR(clear_module_state->__pyx_type_11cython_code_8send_ads_MyDatabase); + Py_CLEAR(clear_module_state->__pyx_kp_u_); + Py_CLEAR(clear_module_state->__pyx_kp_u_Advertisement_Sending_Completed); + Py_CLEAR(clear_module_state->__pyx_n_s_BOT_TOKEN); + Py_CLEAR(clear_module_state->__pyx_kp_u_End_Time); + Py_CLEAR(clear_module_state->__pyx_n_s_Error); + Py_CLEAR(clear_module_state->__pyx_kp_u_Failed); + Py_CLEAR(clear_module_state->__pyx_n_s_HOST); + Py_CLEAR(clear_module_state->__pyx_kp_s_Incompatible_checksums_0x_x_vs_0); + Py_CLEAR(clear_module_state->__pyx_n_s_MYSQL_DATABASE); + Py_CLEAR(clear_module_state->__pyx_n_s_MYSQL_PASSWORD); + Py_CLEAR(clear_module_state->__pyx_n_s_MYSQL_USER); + Py_CLEAR(clear_module_state->__pyx_n_s_MyDatabase); + Py_CLEAR(clear_module_state->__pyx_n_s_MyDatabase___reduce_cython); + Py_CLEAR(clear_module_state->__pyx_n_s_MyDatabase___setstate_cython); + Py_CLEAR(clear_module_state->__pyx_n_s_MyDatabase_reconnect); + Py_CLEAR(clear_module_state->__pyx_n_s_MyDatabase_select_users_by_id); + Py_CLEAR(clear_module_state->__pyx_n_s_PickleError); + Py_CLEAR(clear_module_state->__pyx_kp_u_SELECT_FROM_users_WHERE_id_s_AND); + Py_CLEAR(clear_module_state->__pyx_kp_u_Sending_ads_to_users); + Py_CLEAR(clear_module_state->__pyx_kp_u_Sent); + Py_CLEAR(clear_module_state->__pyx_kp_u_Start_Time); + Py_CLEAR(clear_module_state->__pyx_kp_u_Total); + Py_CLEAR(clear_module_state->__pyx_kp_u_Y_m_d_H_M_S); + Py_CLEAR(clear_module_state->__pyx_kp_u__2); + Py_CLEAR(clear_module_state->__pyx_n_s__24); + Py_CLEAR(clear_module_state->__pyx_kp_u__5); + Py_CLEAR(clear_module_state->__pyx_n_s__6); + Py_CLEAR(clear_module_state->__pyx_n_s_add_data); + Py_CLEAR(clear_module_state->__pyx_n_u_ads); + Py_CLEAR(clear_module_state->__pyx_n_s_ads_data); + Py_CLEAR(clear_module_state->__pyx_n_s_asyncio_coroutines); + Py_CLEAR(clear_module_state->__pyx_n_s_autocommit); + Py_CLEAR(clear_module_state->__pyx_n_s_caption); + Py_CLEAR(clear_module_state->__pyx_n_u_caption); + Py_CLEAR(clear_module_state->__pyx_n_s_chat_id); + Py_CLEAR(clear_module_state->__pyx_n_u_chat_id); + Py_CLEAR(clear_module_state->__pyx_n_s_cline_in_traceback); + Py_CLEAR(clear_module_state->__pyx_n_s_connect); + Py_CLEAR(clear_module_state->__pyx_n_s_connector); + Py_CLEAR(clear_module_state->__pyx_kp_u_copyMessage); + Py_CLEAR(clear_module_state->__pyx_n_s_copy_message_sync); + Py_CLEAR(clear_module_state->__pyx_n_s_cursor); + Py_CLEAR(clear_module_state->__pyx_n_s_cython_code_send_ads); + Py_CLEAR(clear_module_state->__pyx_kp_s_cython_code_send_ads_pyx); + Py_CLEAR(clear_module_state->__pyx_n_s_data); + Py_CLEAR(clear_module_state->__pyx_n_s_data_config); + Py_CLEAR(clear_module_state->__pyx_n_s_database); + Py_CLEAR(clear_module_state->__pyx_n_s_db); + Py_CLEAR(clear_module_state->__pyx_n_s_dict); + Py_CLEAR(clear_module_state->__pyx_n_s_dict_2); + Py_CLEAR(clear_module_state->__pyx_kp_u_disable); + Py_CLEAR(clear_module_state->__pyx_n_u_done_count); + Py_CLEAR(clear_module_state->__pyx_kp_u_enable); + Py_CLEAR(clear_module_state->__pyx_n_s_end_id); + Py_CLEAR(clear_module_state->__pyx_n_s_end_index); + Py_CLEAR(clear_module_state->__pyx_n_s_end_time); + Py_CLEAR(clear_module_state->__pyx_n_s_err); + Py_CLEAR(clear_module_state->__pyx_n_s_error); + Py_CLEAR(clear_module_state->__pyx_n_s_execute); + Py_CLEAR(clear_module_state->__pyx_n_u_fail_count); + Py_CLEAR(clear_module_state->__pyx_n_s_fetchall); + Py_CLEAR(clear_module_state->__pyx_n_s_file_db); + Py_CLEAR(clear_module_state->__pyx_n_s_from_chat_id); + Py_CLEAR(clear_module_state->__pyx_n_u_from_chat_id); + Py_CLEAR(clear_module_state->__pyx_kp_u_gc); + Py_CLEAR(clear_module_state->__pyx_n_s_getstate); + Py_CLEAR(clear_module_state->__pyx_n_s_host); + Py_CLEAR(clear_module_state->__pyx_kp_u_https_api_telegram_org_bot); + Py_CLEAR(clear_module_state->__pyx_n_s_import); + Py_CLEAR(clear_module_state->__pyx_n_s_info); + Py_CLEAR(clear_module_state->__pyx_n_s_initializing); + Py_CLEAR(clear_module_state->__pyx_n_s_is_coroutine); + Py_CLEAR(clear_module_state->__pyx_kp_u_isenabled); + Py_CLEAR(clear_module_state->__pyx_n_s_json); + Py_CLEAR(clear_module_state->__pyx_n_s_key); + Py_CLEAR(clear_module_state->__pyx_n_s_kwargs); + Py_CLEAR(clear_module_state->__pyx_n_s_list); + Py_CLEAR(clear_module_state->__pyx_n_s_loader); + Py_CLEAR(clear_module_state->__pyx_n_s_localtime); + Py_CLEAR(clear_module_state->__pyx_n_s_logging); + Py_CLEAR(clear_module_state->__pyx_n_s_main); + Py_CLEAR(clear_module_state->__pyx_n_s_message_id); + Py_CLEAR(clear_module_state->__pyx_n_u_message_id); + Py_CLEAR(clear_module_state->__pyx_n_s_mysql); + Py_CLEAR(clear_module_state->__pyx_n_s_mysql_connector); + Py_CLEAR(clear_module_state->__pyx_n_s_name); + Py_CLEAR(clear_module_state->__pyx_n_s_new); + Py_CLEAR(clear_module_state->__pyx_n_s_password); + Py_CLEAR(clear_module_state->__pyx_n_s_per_time); + Py_CLEAR(clear_module_state->__pyx_n_u_per_time); + Py_CLEAR(clear_module_state->__pyx_n_s_pickle); + Py_CLEAR(clear_module_state->__pyx_n_s_post); + Py_CLEAR(clear_module_state->__pyx_n_s_pyx_PickleError); + Py_CLEAR(clear_module_state->__pyx_n_s_pyx_checksum); + Py_CLEAR(clear_module_state->__pyx_n_s_pyx_result); + Py_CLEAR(clear_module_state->__pyx_n_s_pyx_state); + Py_CLEAR(clear_module_state->__pyx_n_s_pyx_type); + Py_CLEAR(clear_module_state->__pyx_n_s_pyx_unpickle_MyDatabase); + Py_CLEAR(clear_module_state->__pyx_n_s_query_values); + Py_CLEAR(clear_module_state->__pyx_n_s_reading_db); + Py_CLEAR(clear_module_state->__pyx_n_s_reconnect); + Py_CLEAR(clear_module_state->__pyx_n_s_reduce); + Py_CLEAR(clear_module_state->__pyx_n_s_reduce_cython); + Py_CLEAR(clear_module_state->__pyx_n_s_reduce_ex); + Py_CLEAR(clear_module_state->__pyx_n_s_reply_markup); + Py_CLEAR(clear_module_state->__pyx_n_u_reply_markup); + Py_CLEAR(clear_module_state->__pyx_n_s_requests); + Py_CLEAR(clear_module_state->__pyx_n_s_response); + Py_CLEAR(clear_module_state->__pyx_n_s_result); + Py_CLEAR(clear_module_state->__pyx_n_s_return); + Py_CLEAR(clear_module_state->__pyx_n_s_select_users_by_id); + Py_CLEAR(clear_module_state->__pyx_n_s_self); + Py_CLEAR(clear_module_state->__pyx_kp_u_sendMessage); + Py_CLEAR(clear_module_state->__pyx_n_s_send_ads); + Py_CLEAR(clear_module_state->__pyx_n_s_send_message_sync); + Py_CLEAR(clear_module_state->__pyx_n_s_setstate); + Py_CLEAR(clear_module_state->__pyx_n_s_setstate_cython); + Py_CLEAR(clear_module_state->__pyx_n_s_sleep); + Py_CLEAR(clear_module_state->__pyx_n_s_spec); + Py_CLEAR(clear_module_state->__pyx_n_s_sql_query); + Py_CLEAR(clear_module_state->__pyx_n_u_start); + Py_CLEAR(clear_module_state->__pyx_n_s_start_id); + Py_CLEAR(clear_module_state->__pyx_n_s_start_index); + Py_CLEAR(clear_module_state->__pyx_kp_u_start_time); + Py_CLEAR(clear_module_state->__pyx_n_s_start_time_2); + Py_CLEAR(clear_module_state->__pyx_n_s_state); + Py_CLEAR(clear_module_state->__pyx_n_s_strftime); + Py_CLEAR(clear_module_state->__pyx_kp_s_stringsource); + Py_CLEAR(clear_module_state->__pyx_n_s_summary_message); + Py_CLEAR(clear_module_state->__pyx_n_s_test); + Py_CLEAR(clear_module_state->__pyx_n_s_text); + Py_CLEAR(clear_module_state->__pyx_n_u_text); + Py_CLEAR(clear_module_state->__pyx_n_s_time); + Py_CLEAR(clear_module_state->__pyx_n_s_total_time); + Py_CLEAR(clear_module_state->__pyx_n_s_total_users); + Py_CLEAR(clear_module_state->__pyx_n_u_total_users); + Py_CLEAR(clear_module_state->__pyx_n_s_update); + Py_CLEAR(clear_module_state->__pyx_n_s_url); + Py_CLEAR(clear_module_state->__pyx_n_s_use_setstate); + Py_CLEAR(clear_module_state->__pyx_n_s_user); + Py_CLEAR(clear_module_state->__pyx_n_s_users_batch); + Py_CLEAR(clear_module_state->__pyx_int_1); + Py_CLEAR(clear_module_state->__pyx_int_2); + Py_CLEAR(clear_module_state->__pyx_int_70983331); + Py_CLEAR(clear_module_state->__pyx_int_207201744); + Py_CLEAR(clear_module_state->__pyx_int_249829573); + Py_CLEAR(clear_module_state->__pyx_tuple__3); + Py_CLEAR(clear_module_state->__pyx_tuple__4); + Py_CLEAR(clear_module_state->__pyx_tuple__7); + Py_CLEAR(clear_module_state->__pyx_tuple__8); + Py_CLEAR(clear_module_state->__pyx_tuple__10); + Py_CLEAR(clear_module_state->__pyx_tuple__12); + Py_CLEAR(clear_module_state->__pyx_tuple__14); + Py_CLEAR(clear_module_state->__pyx_tuple__16); + Py_CLEAR(clear_module_state->__pyx_tuple__18); + Py_CLEAR(clear_module_state->__pyx_tuple__20); + Py_CLEAR(clear_module_state->__pyx_tuple__22); + Py_CLEAR(clear_module_state->__pyx_codeobj__9); + Py_CLEAR(clear_module_state->__pyx_codeobj__11); + Py_CLEAR(clear_module_state->__pyx_codeobj__13); + Py_CLEAR(clear_module_state->__pyx_codeobj__15); + Py_CLEAR(clear_module_state->__pyx_codeobj__17); + Py_CLEAR(clear_module_state->__pyx_codeobj__19); + Py_CLEAR(clear_module_state->__pyx_codeobj__21); + Py_CLEAR(clear_module_state->__pyx_codeobj__23); + return 0; +} +#endif +/* #### Code section: module_state_traverse ### */ +#if CYTHON_USE_MODULE_STATE +static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { + __pyx_mstate *traverse_module_state = __pyx_mstate(m); + if (!traverse_module_state) return 0; + Py_VISIT(traverse_module_state->__pyx_d); + Py_VISIT(traverse_module_state->__pyx_b); + Py_VISIT(traverse_module_state->__pyx_cython_runtime); + Py_VISIT(traverse_module_state->__pyx_empty_tuple); + Py_VISIT(traverse_module_state->__pyx_empty_bytes); + Py_VISIT(traverse_module_state->__pyx_empty_unicode); + #ifdef __Pyx_CyFunction_USED + Py_VISIT(traverse_module_state->__pyx_CyFunctionType); + #endif + #ifdef __Pyx_FusedFunction_USED + Py_VISIT(traverse_module_state->__pyx_FusedFunctionType); + #endif + Py_VISIT(traverse_module_state->__pyx_ptype_11cython_code_8send_ads_MyDatabase); + Py_VISIT(traverse_module_state->__pyx_type_11cython_code_8send_ads_MyDatabase); + Py_VISIT(traverse_module_state->__pyx_kp_u_); + Py_VISIT(traverse_module_state->__pyx_kp_u_Advertisement_Sending_Completed); + Py_VISIT(traverse_module_state->__pyx_n_s_BOT_TOKEN); + Py_VISIT(traverse_module_state->__pyx_kp_u_End_Time); + Py_VISIT(traverse_module_state->__pyx_n_s_Error); + Py_VISIT(traverse_module_state->__pyx_kp_u_Failed); + Py_VISIT(traverse_module_state->__pyx_n_s_HOST); + Py_VISIT(traverse_module_state->__pyx_kp_s_Incompatible_checksums_0x_x_vs_0); + Py_VISIT(traverse_module_state->__pyx_n_s_MYSQL_DATABASE); + Py_VISIT(traverse_module_state->__pyx_n_s_MYSQL_PASSWORD); + Py_VISIT(traverse_module_state->__pyx_n_s_MYSQL_USER); + Py_VISIT(traverse_module_state->__pyx_n_s_MyDatabase); + Py_VISIT(traverse_module_state->__pyx_n_s_MyDatabase___reduce_cython); + Py_VISIT(traverse_module_state->__pyx_n_s_MyDatabase___setstate_cython); + Py_VISIT(traverse_module_state->__pyx_n_s_MyDatabase_reconnect); + Py_VISIT(traverse_module_state->__pyx_n_s_MyDatabase_select_users_by_id); + Py_VISIT(traverse_module_state->__pyx_n_s_PickleError); + Py_VISIT(traverse_module_state->__pyx_kp_u_SELECT_FROM_users_WHERE_id_s_AND); + Py_VISIT(traverse_module_state->__pyx_kp_u_Sending_ads_to_users); + Py_VISIT(traverse_module_state->__pyx_kp_u_Sent); + Py_VISIT(traverse_module_state->__pyx_kp_u_Start_Time); + Py_VISIT(traverse_module_state->__pyx_kp_u_Total); + Py_VISIT(traverse_module_state->__pyx_kp_u_Y_m_d_H_M_S); + Py_VISIT(traverse_module_state->__pyx_kp_u__2); + Py_VISIT(traverse_module_state->__pyx_n_s__24); + Py_VISIT(traverse_module_state->__pyx_kp_u__5); + Py_VISIT(traverse_module_state->__pyx_n_s__6); + Py_VISIT(traverse_module_state->__pyx_n_s_add_data); + Py_VISIT(traverse_module_state->__pyx_n_u_ads); + Py_VISIT(traverse_module_state->__pyx_n_s_ads_data); + Py_VISIT(traverse_module_state->__pyx_n_s_asyncio_coroutines); + Py_VISIT(traverse_module_state->__pyx_n_s_autocommit); + Py_VISIT(traverse_module_state->__pyx_n_s_caption); + Py_VISIT(traverse_module_state->__pyx_n_u_caption); + Py_VISIT(traverse_module_state->__pyx_n_s_chat_id); + Py_VISIT(traverse_module_state->__pyx_n_u_chat_id); + Py_VISIT(traverse_module_state->__pyx_n_s_cline_in_traceback); + Py_VISIT(traverse_module_state->__pyx_n_s_connect); + Py_VISIT(traverse_module_state->__pyx_n_s_connector); + Py_VISIT(traverse_module_state->__pyx_kp_u_copyMessage); + Py_VISIT(traverse_module_state->__pyx_n_s_copy_message_sync); + Py_VISIT(traverse_module_state->__pyx_n_s_cursor); + Py_VISIT(traverse_module_state->__pyx_n_s_cython_code_send_ads); + Py_VISIT(traverse_module_state->__pyx_kp_s_cython_code_send_ads_pyx); + Py_VISIT(traverse_module_state->__pyx_n_s_data); + Py_VISIT(traverse_module_state->__pyx_n_s_data_config); + Py_VISIT(traverse_module_state->__pyx_n_s_database); + Py_VISIT(traverse_module_state->__pyx_n_s_db); + Py_VISIT(traverse_module_state->__pyx_n_s_dict); + Py_VISIT(traverse_module_state->__pyx_n_s_dict_2); + Py_VISIT(traverse_module_state->__pyx_kp_u_disable); + Py_VISIT(traverse_module_state->__pyx_n_u_done_count); + Py_VISIT(traverse_module_state->__pyx_kp_u_enable); + Py_VISIT(traverse_module_state->__pyx_n_s_end_id); + Py_VISIT(traverse_module_state->__pyx_n_s_end_index); + Py_VISIT(traverse_module_state->__pyx_n_s_end_time); + Py_VISIT(traverse_module_state->__pyx_n_s_err); + Py_VISIT(traverse_module_state->__pyx_n_s_error); + Py_VISIT(traverse_module_state->__pyx_n_s_execute); + Py_VISIT(traverse_module_state->__pyx_n_u_fail_count); + Py_VISIT(traverse_module_state->__pyx_n_s_fetchall); + Py_VISIT(traverse_module_state->__pyx_n_s_file_db); + Py_VISIT(traverse_module_state->__pyx_n_s_from_chat_id); + Py_VISIT(traverse_module_state->__pyx_n_u_from_chat_id); + Py_VISIT(traverse_module_state->__pyx_kp_u_gc); + Py_VISIT(traverse_module_state->__pyx_n_s_getstate); + Py_VISIT(traverse_module_state->__pyx_n_s_host); + Py_VISIT(traverse_module_state->__pyx_kp_u_https_api_telegram_org_bot); + Py_VISIT(traverse_module_state->__pyx_n_s_import); + Py_VISIT(traverse_module_state->__pyx_n_s_info); + Py_VISIT(traverse_module_state->__pyx_n_s_initializing); + Py_VISIT(traverse_module_state->__pyx_n_s_is_coroutine); + Py_VISIT(traverse_module_state->__pyx_kp_u_isenabled); + Py_VISIT(traverse_module_state->__pyx_n_s_json); + Py_VISIT(traverse_module_state->__pyx_n_s_key); + Py_VISIT(traverse_module_state->__pyx_n_s_kwargs); + Py_VISIT(traverse_module_state->__pyx_n_s_list); + Py_VISIT(traverse_module_state->__pyx_n_s_loader); + Py_VISIT(traverse_module_state->__pyx_n_s_localtime); + Py_VISIT(traverse_module_state->__pyx_n_s_logging); + Py_VISIT(traverse_module_state->__pyx_n_s_main); + Py_VISIT(traverse_module_state->__pyx_n_s_message_id); + Py_VISIT(traverse_module_state->__pyx_n_u_message_id); + Py_VISIT(traverse_module_state->__pyx_n_s_mysql); + Py_VISIT(traverse_module_state->__pyx_n_s_mysql_connector); + Py_VISIT(traverse_module_state->__pyx_n_s_name); + Py_VISIT(traverse_module_state->__pyx_n_s_new); + Py_VISIT(traverse_module_state->__pyx_n_s_password); + Py_VISIT(traverse_module_state->__pyx_n_s_per_time); + Py_VISIT(traverse_module_state->__pyx_n_u_per_time); + Py_VISIT(traverse_module_state->__pyx_n_s_pickle); + Py_VISIT(traverse_module_state->__pyx_n_s_post); + Py_VISIT(traverse_module_state->__pyx_n_s_pyx_PickleError); + Py_VISIT(traverse_module_state->__pyx_n_s_pyx_checksum); + Py_VISIT(traverse_module_state->__pyx_n_s_pyx_result); + Py_VISIT(traverse_module_state->__pyx_n_s_pyx_state); + Py_VISIT(traverse_module_state->__pyx_n_s_pyx_type); + Py_VISIT(traverse_module_state->__pyx_n_s_pyx_unpickle_MyDatabase); + Py_VISIT(traverse_module_state->__pyx_n_s_query_values); + Py_VISIT(traverse_module_state->__pyx_n_s_reading_db); + Py_VISIT(traverse_module_state->__pyx_n_s_reconnect); + Py_VISIT(traverse_module_state->__pyx_n_s_reduce); + Py_VISIT(traverse_module_state->__pyx_n_s_reduce_cython); + Py_VISIT(traverse_module_state->__pyx_n_s_reduce_ex); + Py_VISIT(traverse_module_state->__pyx_n_s_reply_markup); + Py_VISIT(traverse_module_state->__pyx_n_u_reply_markup); + Py_VISIT(traverse_module_state->__pyx_n_s_requests); + Py_VISIT(traverse_module_state->__pyx_n_s_response); + Py_VISIT(traverse_module_state->__pyx_n_s_result); + Py_VISIT(traverse_module_state->__pyx_n_s_return); + Py_VISIT(traverse_module_state->__pyx_n_s_select_users_by_id); + Py_VISIT(traverse_module_state->__pyx_n_s_self); + Py_VISIT(traverse_module_state->__pyx_kp_u_sendMessage); + Py_VISIT(traverse_module_state->__pyx_n_s_send_ads); + Py_VISIT(traverse_module_state->__pyx_n_s_send_message_sync); + Py_VISIT(traverse_module_state->__pyx_n_s_setstate); + Py_VISIT(traverse_module_state->__pyx_n_s_setstate_cython); + Py_VISIT(traverse_module_state->__pyx_n_s_sleep); + Py_VISIT(traverse_module_state->__pyx_n_s_spec); + Py_VISIT(traverse_module_state->__pyx_n_s_sql_query); + Py_VISIT(traverse_module_state->__pyx_n_u_start); + Py_VISIT(traverse_module_state->__pyx_n_s_start_id); + Py_VISIT(traverse_module_state->__pyx_n_s_start_index); + Py_VISIT(traverse_module_state->__pyx_kp_u_start_time); + Py_VISIT(traverse_module_state->__pyx_n_s_start_time_2); + Py_VISIT(traverse_module_state->__pyx_n_s_state); + Py_VISIT(traverse_module_state->__pyx_n_s_strftime); + Py_VISIT(traverse_module_state->__pyx_kp_s_stringsource); + Py_VISIT(traverse_module_state->__pyx_n_s_summary_message); + Py_VISIT(traverse_module_state->__pyx_n_s_test); + Py_VISIT(traverse_module_state->__pyx_n_s_text); + Py_VISIT(traverse_module_state->__pyx_n_u_text); + Py_VISIT(traverse_module_state->__pyx_n_s_time); + Py_VISIT(traverse_module_state->__pyx_n_s_total_time); + Py_VISIT(traverse_module_state->__pyx_n_s_total_users); + Py_VISIT(traverse_module_state->__pyx_n_u_total_users); + Py_VISIT(traverse_module_state->__pyx_n_s_update); + Py_VISIT(traverse_module_state->__pyx_n_s_url); + Py_VISIT(traverse_module_state->__pyx_n_s_use_setstate); + Py_VISIT(traverse_module_state->__pyx_n_s_user); + Py_VISIT(traverse_module_state->__pyx_n_s_users_batch); + Py_VISIT(traverse_module_state->__pyx_int_1); + Py_VISIT(traverse_module_state->__pyx_int_2); + Py_VISIT(traverse_module_state->__pyx_int_70983331); + Py_VISIT(traverse_module_state->__pyx_int_207201744); + Py_VISIT(traverse_module_state->__pyx_int_249829573); + Py_VISIT(traverse_module_state->__pyx_tuple__3); + Py_VISIT(traverse_module_state->__pyx_tuple__4); + Py_VISIT(traverse_module_state->__pyx_tuple__7); + Py_VISIT(traverse_module_state->__pyx_tuple__8); + Py_VISIT(traverse_module_state->__pyx_tuple__10); + Py_VISIT(traverse_module_state->__pyx_tuple__12); + Py_VISIT(traverse_module_state->__pyx_tuple__14); + Py_VISIT(traverse_module_state->__pyx_tuple__16); + Py_VISIT(traverse_module_state->__pyx_tuple__18); + Py_VISIT(traverse_module_state->__pyx_tuple__20); + Py_VISIT(traverse_module_state->__pyx_tuple__22); + Py_VISIT(traverse_module_state->__pyx_codeobj__9); + Py_VISIT(traverse_module_state->__pyx_codeobj__11); + Py_VISIT(traverse_module_state->__pyx_codeobj__13); + Py_VISIT(traverse_module_state->__pyx_codeobj__15); + Py_VISIT(traverse_module_state->__pyx_codeobj__17); + Py_VISIT(traverse_module_state->__pyx_codeobj__19); + Py_VISIT(traverse_module_state->__pyx_codeobj__21); + Py_VISIT(traverse_module_state->__pyx_codeobj__23); + return 0; +} +#endif +/* #### Code section: module_state_defines ### */ +#define __pyx_d __pyx_mstate_global->__pyx_d +#define __pyx_b __pyx_mstate_global->__pyx_b +#define __pyx_cython_runtime __pyx_mstate_global->__pyx_cython_runtime +#define __pyx_empty_tuple __pyx_mstate_global->__pyx_empty_tuple +#define __pyx_empty_bytes __pyx_mstate_global->__pyx_empty_bytes +#define __pyx_empty_unicode __pyx_mstate_global->__pyx_empty_unicode +#ifdef __Pyx_CyFunction_USED +#define __pyx_CyFunctionType __pyx_mstate_global->__pyx_CyFunctionType +#endif +#ifdef __Pyx_FusedFunction_USED +#define __pyx_FusedFunctionType __pyx_mstate_global->__pyx_FusedFunctionType +#endif +#ifdef __Pyx_Generator_USED +#define __pyx_GeneratorType __pyx_mstate_global->__pyx_GeneratorType +#endif +#ifdef __Pyx_IterableCoroutine_USED +#define __pyx_IterableCoroutineType __pyx_mstate_global->__pyx_IterableCoroutineType +#endif +#ifdef __Pyx_Coroutine_USED +#define __pyx_CoroutineAwaitType __pyx_mstate_global->__pyx_CoroutineAwaitType +#endif +#ifdef __Pyx_Coroutine_USED +#define __pyx_CoroutineType __pyx_mstate_global->__pyx_CoroutineType +#endif +#if CYTHON_USE_MODULE_STATE +#define __pyx_type_11cython_code_8send_ads_MyDatabase __pyx_mstate_global->__pyx_type_11cython_code_8send_ads_MyDatabase +#endif +#define __pyx_ptype_11cython_code_8send_ads_MyDatabase __pyx_mstate_global->__pyx_ptype_11cython_code_8send_ads_MyDatabase +#define __pyx_kp_u_ __pyx_mstate_global->__pyx_kp_u_ +#define __pyx_kp_u_Advertisement_Sending_Completed __pyx_mstate_global->__pyx_kp_u_Advertisement_Sending_Completed +#define __pyx_n_s_BOT_TOKEN __pyx_mstate_global->__pyx_n_s_BOT_TOKEN +#define __pyx_kp_u_End_Time __pyx_mstate_global->__pyx_kp_u_End_Time +#define __pyx_n_s_Error __pyx_mstate_global->__pyx_n_s_Error +#define __pyx_kp_u_Failed __pyx_mstate_global->__pyx_kp_u_Failed +#define __pyx_n_s_HOST __pyx_mstate_global->__pyx_n_s_HOST +#define __pyx_kp_s_Incompatible_checksums_0x_x_vs_0 __pyx_mstate_global->__pyx_kp_s_Incompatible_checksums_0x_x_vs_0 +#define __pyx_n_s_MYSQL_DATABASE __pyx_mstate_global->__pyx_n_s_MYSQL_DATABASE +#define __pyx_n_s_MYSQL_PASSWORD __pyx_mstate_global->__pyx_n_s_MYSQL_PASSWORD +#define __pyx_n_s_MYSQL_USER __pyx_mstate_global->__pyx_n_s_MYSQL_USER +#define __pyx_n_s_MyDatabase __pyx_mstate_global->__pyx_n_s_MyDatabase +#define __pyx_n_s_MyDatabase___reduce_cython __pyx_mstate_global->__pyx_n_s_MyDatabase___reduce_cython +#define __pyx_n_s_MyDatabase___setstate_cython __pyx_mstate_global->__pyx_n_s_MyDatabase___setstate_cython +#define __pyx_n_s_MyDatabase_reconnect __pyx_mstate_global->__pyx_n_s_MyDatabase_reconnect +#define __pyx_n_s_MyDatabase_select_users_by_id __pyx_mstate_global->__pyx_n_s_MyDatabase_select_users_by_id +#define __pyx_n_s_PickleError __pyx_mstate_global->__pyx_n_s_PickleError +#define __pyx_kp_u_SELECT_FROM_users_WHERE_id_s_AND __pyx_mstate_global->__pyx_kp_u_SELECT_FROM_users_WHERE_id_s_AND +#define __pyx_kp_u_Sending_ads_to_users __pyx_mstate_global->__pyx_kp_u_Sending_ads_to_users +#define __pyx_kp_u_Sent __pyx_mstate_global->__pyx_kp_u_Sent +#define __pyx_kp_u_Start_Time __pyx_mstate_global->__pyx_kp_u_Start_Time +#define __pyx_kp_u_Total __pyx_mstate_global->__pyx_kp_u_Total +#define __pyx_kp_u_Y_m_d_H_M_S __pyx_mstate_global->__pyx_kp_u_Y_m_d_H_M_S +#define __pyx_kp_u__2 __pyx_mstate_global->__pyx_kp_u__2 +#define __pyx_n_s__24 __pyx_mstate_global->__pyx_n_s__24 +#define __pyx_kp_u__5 __pyx_mstate_global->__pyx_kp_u__5 +#define __pyx_n_s__6 __pyx_mstate_global->__pyx_n_s__6 +#define __pyx_n_s_add_data __pyx_mstate_global->__pyx_n_s_add_data +#define __pyx_n_u_ads __pyx_mstate_global->__pyx_n_u_ads +#define __pyx_n_s_ads_data __pyx_mstate_global->__pyx_n_s_ads_data +#define __pyx_n_s_asyncio_coroutines __pyx_mstate_global->__pyx_n_s_asyncio_coroutines +#define __pyx_n_s_autocommit __pyx_mstate_global->__pyx_n_s_autocommit +#define __pyx_n_s_caption __pyx_mstate_global->__pyx_n_s_caption +#define __pyx_n_u_caption __pyx_mstate_global->__pyx_n_u_caption +#define __pyx_n_s_chat_id __pyx_mstate_global->__pyx_n_s_chat_id +#define __pyx_n_u_chat_id __pyx_mstate_global->__pyx_n_u_chat_id +#define __pyx_n_s_cline_in_traceback __pyx_mstate_global->__pyx_n_s_cline_in_traceback +#define __pyx_n_s_connect __pyx_mstate_global->__pyx_n_s_connect +#define __pyx_n_s_connector __pyx_mstate_global->__pyx_n_s_connector +#define __pyx_kp_u_copyMessage __pyx_mstate_global->__pyx_kp_u_copyMessage +#define __pyx_n_s_copy_message_sync __pyx_mstate_global->__pyx_n_s_copy_message_sync +#define __pyx_n_s_cursor __pyx_mstate_global->__pyx_n_s_cursor +#define __pyx_n_s_cython_code_send_ads __pyx_mstate_global->__pyx_n_s_cython_code_send_ads +#define __pyx_kp_s_cython_code_send_ads_pyx __pyx_mstate_global->__pyx_kp_s_cython_code_send_ads_pyx +#define __pyx_n_s_data __pyx_mstate_global->__pyx_n_s_data +#define __pyx_n_s_data_config __pyx_mstate_global->__pyx_n_s_data_config +#define __pyx_n_s_database __pyx_mstate_global->__pyx_n_s_database +#define __pyx_n_s_db __pyx_mstate_global->__pyx_n_s_db +#define __pyx_n_s_dict __pyx_mstate_global->__pyx_n_s_dict +#define __pyx_n_s_dict_2 __pyx_mstate_global->__pyx_n_s_dict_2 +#define __pyx_kp_u_disable __pyx_mstate_global->__pyx_kp_u_disable +#define __pyx_n_u_done_count __pyx_mstate_global->__pyx_n_u_done_count +#define __pyx_kp_u_enable __pyx_mstate_global->__pyx_kp_u_enable +#define __pyx_n_s_end_id __pyx_mstate_global->__pyx_n_s_end_id +#define __pyx_n_s_end_index __pyx_mstate_global->__pyx_n_s_end_index +#define __pyx_n_s_end_time __pyx_mstate_global->__pyx_n_s_end_time +#define __pyx_n_s_err __pyx_mstate_global->__pyx_n_s_err +#define __pyx_n_s_error __pyx_mstate_global->__pyx_n_s_error +#define __pyx_n_s_execute __pyx_mstate_global->__pyx_n_s_execute +#define __pyx_n_u_fail_count __pyx_mstate_global->__pyx_n_u_fail_count +#define __pyx_n_s_fetchall __pyx_mstate_global->__pyx_n_s_fetchall +#define __pyx_n_s_file_db __pyx_mstate_global->__pyx_n_s_file_db +#define __pyx_n_s_from_chat_id __pyx_mstate_global->__pyx_n_s_from_chat_id +#define __pyx_n_u_from_chat_id __pyx_mstate_global->__pyx_n_u_from_chat_id +#define __pyx_kp_u_gc __pyx_mstate_global->__pyx_kp_u_gc +#define __pyx_n_s_getstate __pyx_mstate_global->__pyx_n_s_getstate +#define __pyx_n_s_host __pyx_mstate_global->__pyx_n_s_host +#define __pyx_kp_u_https_api_telegram_org_bot __pyx_mstate_global->__pyx_kp_u_https_api_telegram_org_bot +#define __pyx_n_s_import __pyx_mstate_global->__pyx_n_s_import +#define __pyx_n_s_info __pyx_mstate_global->__pyx_n_s_info +#define __pyx_n_s_initializing __pyx_mstate_global->__pyx_n_s_initializing +#define __pyx_n_s_is_coroutine __pyx_mstate_global->__pyx_n_s_is_coroutine +#define __pyx_kp_u_isenabled __pyx_mstate_global->__pyx_kp_u_isenabled +#define __pyx_n_s_json __pyx_mstate_global->__pyx_n_s_json +#define __pyx_n_s_key __pyx_mstate_global->__pyx_n_s_key +#define __pyx_n_s_kwargs __pyx_mstate_global->__pyx_n_s_kwargs +#define __pyx_n_s_list __pyx_mstate_global->__pyx_n_s_list +#define __pyx_n_s_loader __pyx_mstate_global->__pyx_n_s_loader +#define __pyx_n_s_localtime __pyx_mstate_global->__pyx_n_s_localtime +#define __pyx_n_s_logging __pyx_mstate_global->__pyx_n_s_logging +#define __pyx_n_s_main __pyx_mstate_global->__pyx_n_s_main +#define __pyx_n_s_message_id __pyx_mstate_global->__pyx_n_s_message_id +#define __pyx_n_u_message_id __pyx_mstate_global->__pyx_n_u_message_id +#define __pyx_n_s_mysql __pyx_mstate_global->__pyx_n_s_mysql +#define __pyx_n_s_mysql_connector __pyx_mstate_global->__pyx_n_s_mysql_connector +#define __pyx_n_s_name __pyx_mstate_global->__pyx_n_s_name +#define __pyx_n_s_new __pyx_mstate_global->__pyx_n_s_new +#define __pyx_n_s_password __pyx_mstate_global->__pyx_n_s_password +#define __pyx_n_s_per_time __pyx_mstate_global->__pyx_n_s_per_time +#define __pyx_n_u_per_time __pyx_mstate_global->__pyx_n_u_per_time +#define __pyx_n_s_pickle __pyx_mstate_global->__pyx_n_s_pickle +#define __pyx_n_s_post __pyx_mstate_global->__pyx_n_s_post +#define __pyx_n_s_pyx_PickleError __pyx_mstate_global->__pyx_n_s_pyx_PickleError +#define __pyx_n_s_pyx_checksum __pyx_mstate_global->__pyx_n_s_pyx_checksum +#define __pyx_n_s_pyx_result __pyx_mstate_global->__pyx_n_s_pyx_result +#define __pyx_n_s_pyx_state __pyx_mstate_global->__pyx_n_s_pyx_state +#define __pyx_n_s_pyx_type __pyx_mstate_global->__pyx_n_s_pyx_type +#define __pyx_n_s_pyx_unpickle_MyDatabase __pyx_mstate_global->__pyx_n_s_pyx_unpickle_MyDatabase +#define __pyx_n_s_query_values __pyx_mstate_global->__pyx_n_s_query_values +#define __pyx_n_s_reading_db __pyx_mstate_global->__pyx_n_s_reading_db +#define __pyx_n_s_reconnect __pyx_mstate_global->__pyx_n_s_reconnect +#define __pyx_n_s_reduce __pyx_mstate_global->__pyx_n_s_reduce +#define __pyx_n_s_reduce_cython __pyx_mstate_global->__pyx_n_s_reduce_cython +#define __pyx_n_s_reduce_ex __pyx_mstate_global->__pyx_n_s_reduce_ex +#define __pyx_n_s_reply_markup __pyx_mstate_global->__pyx_n_s_reply_markup +#define __pyx_n_u_reply_markup __pyx_mstate_global->__pyx_n_u_reply_markup +#define __pyx_n_s_requests __pyx_mstate_global->__pyx_n_s_requests +#define __pyx_n_s_response __pyx_mstate_global->__pyx_n_s_response +#define __pyx_n_s_result __pyx_mstate_global->__pyx_n_s_result +#define __pyx_n_s_return __pyx_mstate_global->__pyx_n_s_return +#define __pyx_n_s_select_users_by_id __pyx_mstate_global->__pyx_n_s_select_users_by_id +#define __pyx_n_s_self __pyx_mstate_global->__pyx_n_s_self +#define __pyx_kp_u_sendMessage __pyx_mstate_global->__pyx_kp_u_sendMessage +#define __pyx_n_s_send_ads __pyx_mstate_global->__pyx_n_s_send_ads +#define __pyx_n_s_send_message_sync __pyx_mstate_global->__pyx_n_s_send_message_sync +#define __pyx_n_s_setstate __pyx_mstate_global->__pyx_n_s_setstate +#define __pyx_n_s_setstate_cython __pyx_mstate_global->__pyx_n_s_setstate_cython +#define __pyx_n_s_sleep __pyx_mstate_global->__pyx_n_s_sleep +#define __pyx_n_s_spec __pyx_mstate_global->__pyx_n_s_spec +#define __pyx_n_s_sql_query __pyx_mstate_global->__pyx_n_s_sql_query +#define __pyx_n_u_start __pyx_mstate_global->__pyx_n_u_start +#define __pyx_n_s_start_id __pyx_mstate_global->__pyx_n_s_start_id +#define __pyx_n_s_start_index __pyx_mstate_global->__pyx_n_s_start_index +#define __pyx_kp_u_start_time __pyx_mstate_global->__pyx_kp_u_start_time +#define __pyx_n_s_start_time_2 __pyx_mstate_global->__pyx_n_s_start_time_2 +#define __pyx_n_s_state __pyx_mstate_global->__pyx_n_s_state +#define __pyx_n_s_strftime __pyx_mstate_global->__pyx_n_s_strftime +#define __pyx_kp_s_stringsource __pyx_mstate_global->__pyx_kp_s_stringsource +#define __pyx_n_s_summary_message __pyx_mstate_global->__pyx_n_s_summary_message +#define __pyx_n_s_test __pyx_mstate_global->__pyx_n_s_test +#define __pyx_n_s_text __pyx_mstate_global->__pyx_n_s_text +#define __pyx_n_u_text __pyx_mstate_global->__pyx_n_u_text +#define __pyx_n_s_time __pyx_mstate_global->__pyx_n_s_time +#define __pyx_n_s_total_time __pyx_mstate_global->__pyx_n_s_total_time +#define __pyx_n_s_total_users __pyx_mstate_global->__pyx_n_s_total_users +#define __pyx_n_u_total_users __pyx_mstate_global->__pyx_n_u_total_users +#define __pyx_n_s_update __pyx_mstate_global->__pyx_n_s_update +#define __pyx_n_s_url __pyx_mstate_global->__pyx_n_s_url +#define __pyx_n_s_use_setstate __pyx_mstate_global->__pyx_n_s_use_setstate +#define __pyx_n_s_user __pyx_mstate_global->__pyx_n_s_user +#define __pyx_n_s_users_batch __pyx_mstate_global->__pyx_n_s_users_batch +#define __pyx_int_1 __pyx_mstate_global->__pyx_int_1 +#define __pyx_int_2 __pyx_mstate_global->__pyx_int_2 +#define __pyx_int_70983331 __pyx_mstate_global->__pyx_int_70983331 +#define __pyx_int_207201744 __pyx_mstate_global->__pyx_int_207201744 +#define __pyx_int_249829573 __pyx_mstate_global->__pyx_int_249829573 +#define __pyx_tuple__3 __pyx_mstate_global->__pyx_tuple__3 +#define __pyx_tuple__4 __pyx_mstate_global->__pyx_tuple__4 +#define __pyx_tuple__7 __pyx_mstate_global->__pyx_tuple__7 +#define __pyx_tuple__8 __pyx_mstate_global->__pyx_tuple__8 +#define __pyx_tuple__10 __pyx_mstate_global->__pyx_tuple__10 +#define __pyx_tuple__12 __pyx_mstate_global->__pyx_tuple__12 +#define __pyx_tuple__14 __pyx_mstate_global->__pyx_tuple__14 +#define __pyx_tuple__16 __pyx_mstate_global->__pyx_tuple__16 +#define __pyx_tuple__18 __pyx_mstate_global->__pyx_tuple__18 +#define __pyx_tuple__20 __pyx_mstate_global->__pyx_tuple__20 +#define __pyx_tuple__22 __pyx_mstate_global->__pyx_tuple__22 +#define __pyx_codeobj__9 __pyx_mstate_global->__pyx_codeobj__9 +#define __pyx_codeobj__11 __pyx_mstate_global->__pyx_codeobj__11 +#define __pyx_codeobj__13 __pyx_mstate_global->__pyx_codeobj__13 +#define __pyx_codeobj__15 __pyx_mstate_global->__pyx_codeobj__15 +#define __pyx_codeobj__17 __pyx_mstate_global->__pyx_codeobj__17 +#define __pyx_codeobj__19 __pyx_mstate_global->__pyx_codeobj__19 +#define __pyx_codeobj__21 __pyx_mstate_global->__pyx_codeobj__21 +#define __pyx_codeobj__23 __pyx_mstate_global->__pyx_codeobj__23 +/* #### Code section: module_code ### */ + +/* "cython_code/send_ads.pyx":14 + * cdef object cursor # Use 'object' since it's a generic Python object + * + * def __init__(self, str host, str user, str password, str database): # <<<<<<<<<<<<<< + * self.host = host + * self.user = user + */ + +/* Python wrapper */ +static int __pyx_pw_11cython_code_8send_ads_10MyDatabase_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds); /*proto*/ +static int __pyx_pw_11cython_code_8send_ads_10MyDatabase_1__init__(PyObject *__pyx_v_self, PyObject *__pyx_args, PyObject *__pyx_kwds) { + PyObject *__pyx_v_host = 0; + PyObject *__pyx_v_user = 0; + PyObject *__pyx_v_password = 0; + PyObject *__pyx_v_database = 0; + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[4] = {0,0,0,0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + int __pyx_r; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return -1; + #endif + __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_host,&__pyx_n_s_user,&__pyx_n_s_password,&__pyx_n_s_database,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 4: values[3] = __Pyx_Arg_VARARGS(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = __Pyx_Arg_VARARGS(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_VARARGS(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_host)) != 0)) { + (void)__Pyx_Arg_NewRef_VARARGS(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 14, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_user)) != 0)) { + (void)__Pyx_Arg_NewRef_VARARGS(values[1]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 14, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("__init__", 1, 4, 4, 1); __PYX_ERR(0, 14, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_password)) != 0)) { + (void)__Pyx_Arg_NewRef_VARARGS(values[2]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 14, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("__init__", 1, 4, 4, 2); __PYX_ERR(0, 14, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (likely((values[3] = __Pyx_GetKwValue_VARARGS(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_database)) != 0)) { + (void)__Pyx_Arg_NewRef_VARARGS(values[3]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 14, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("__init__", 1, 4, 4, 3); __PYX_ERR(0, 14, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 14, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 4)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_VARARGS(__pyx_args, 0); + values[1] = __Pyx_Arg_VARARGS(__pyx_args, 1); + values[2] = __Pyx_Arg_VARARGS(__pyx_args, 2); + values[3] = __Pyx_Arg_VARARGS(__pyx_args, 3); + } + __pyx_v_host = ((PyObject*)values[0]); + __pyx_v_user = ((PyObject*)values[1]); + __pyx_v_password = ((PyObject*)values[2]); + __pyx_v_database = ((PyObject*)values[3]); + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 1, 4, 4, __pyx_nargs); __PYX_ERR(0, 14, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.send_ads.MyDatabase.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return -1; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_host), (&PyUnicode_Type), 1, "host", 1))) __PYX_ERR(0, 14, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_user), (&PyUnicode_Type), 1, "user", 1))) __PYX_ERR(0, 14, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_password), (&PyUnicode_Type), 1, "password", 1))) __PYX_ERR(0, 14, __pyx_L1_error) + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_database), (&PyUnicode_Type), 1, "database", 1))) __PYX_ERR(0, 14, __pyx_L1_error) + __pyx_r = __pyx_pf_11cython_code_8send_ads_10MyDatabase___init__(((struct __pyx_obj_11cython_code_8send_ads_MyDatabase *)__pyx_v_self), __pyx_v_host, __pyx_v_user, __pyx_v_password, __pyx_v_database); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = -1; + __pyx_L0:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_VARARGS(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static int __pyx_pf_11cython_code_8send_ads_10MyDatabase___init__(struct __pyx_obj_11cython_code_8send_ads_MyDatabase *__pyx_v_self, PyObject *__pyx_v_host, PyObject *__pyx_v_user, PyObject *__pyx_v_password, PyObject *__pyx_v_database) { + int __pyx_r; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + unsigned int __pyx_t_4; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__init__", 1); + + /* "cython_code/send_ads.pyx":15 + * + * def __init__(self, str host, str user, str password, str database): + * self.host = host # <<<<<<<<<<<<<< + * self.user = user + * self.password = password + */ + __Pyx_INCREF(__pyx_v_host); + __Pyx_GIVEREF(__pyx_v_host); + __Pyx_GOTREF(__pyx_v_self->host); + __Pyx_DECREF(__pyx_v_self->host); + __pyx_v_self->host = __pyx_v_host; + + /* "cython_code/send_ads.pyx":16 + * def __init__(self, str host, str user, str password, str database): + * self.host = host + * self.user = user # <<<<<<<<<<<<<< + * self.password = password + * self.database = database + */ + __Pyx_INCREF(__pyx_v_user); + __Pyx_GIVEREF(__pyx_v_user); + __Pyx_GOTREF(__pyx_v_self->user); + __Pyx_DECREF(__pyx_v_self->user); + __pyx_v_self->user = __pyx_v_user; + + /* "cython_code/send_ads.pyx":17 + * self.host = host + * self.user = user + * self.password = password # <<<<<<<<<<<<<< + * self.database = database + * self.reconnect() + */ + __Pyx_INCREF(__pyx_v_password); + __Pyx_GIVEREF(__pyx_v_password); + __Pyx_GOTREF(__pyx_v_self->password); + __Pyx_DECREF(__pyx_v_self->password); + __pyx_v_self->password = __pyx_v_password; + + /* "cython_code/send_ads.pyx":18 + * self.user = user + * self.password = password + * self.database = database # <<<<<<<<<<<<<< + * self.reconnect() + * + */ + __Pyx_INCREF(__pyx_v_database); + __Pyx_GIVEREF(__pyx_v_database); + __Pyx_GOTREF(__pyx_v_self->database); + __Pyx_DECREF(__pyx_v_self->database); + __pyx_v_self->database = __pyx_v_database; + + /* "cython_code/send_ads.pyx":19 + * self.password = password + * self.database = database + * self.reconnect() # <<<<<<<<<<<<<< + * + * def reconnect(self): + */ + __pyx_t_2 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reconnect); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 19, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = NULL; + __pyx_t_4 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_2))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_2); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_2); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_2, function); + __pyx_t_4 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; + __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_2, __pyx_callargs+1-__pyx_t_4, 0+__pyx_t_4); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 19, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "cython_code/send_ads.pyx":14 + * cdef object cursor # Use 'object' since it's a generic Python object + * + * def __init__(self, str host, str user, str password, str database): # <<<<<<<<<<<<<< + * self.host = host + * self.user = user + */ + + /* function exit code */ + __pyx_r = 0; + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_AddTraceback("cython_code.send_ads.MyDatabase.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = -1; + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cython_code/send_ads.pyx":21 + * self.reconnect() + * + * def reconnect(self): # <<<<<<<<<<<<<< + * try: + * self.connection = mysql.connector.connect( + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_8send_ads_10MyDatabase_3reconnect(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_8send_ads_10MyDatabase_3reconnect = {"reconnect", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_8send_ads_10MyDatabase_3reconnect, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_8send_ads_10MyDatabase_3reconnect(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("reconnect (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + if (unlikely(__pyx_nargs > 0)) { + __Pyx_RaiseArgtupleInvalid("reconnect", 1, 0, 0, __pyx_nargs); return NULL;} + if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "reconnect", 0))) return NULL; + __pyx_r = __pyx_pf_11cython_code_8send_ads_10MyDatabase_2reconnect(((struct __pyx_obj_11cython_code_8send_ads_MyDatabase *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_8send_ads_10MyDatabase_2reconnect(struct __pyx_obj_11cython_code_8send_ads_MyDatabase *__pyx_v_self) { + PyObject *__pyx_v_err = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + unsigned int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + int __pyx_t_12; + char const *__pyx_t_13; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + PyObject *__pyx_t_18 = NULL; + PyObject *__pyx_t_19 = NULL; + char const *__pyx_t_20; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("reconnect", 1); + + /* "cython_code/send_ads.pyx":22 + * + * def reconnect(self): + * try: # <<<<<<<<<<<<<< + * self.connection = mysql.connector.connect( + * host=self.host, + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "cython_code/send_ads.pyx":23 + * def reconnect(self): + * try: + * self.connection = mysql.connector.connect( # <<<<<<<<<<<<<< + * host=self.host, + * user=self.user, + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_mysql); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 23, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_connector); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 23, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_connect); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 23, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":24 + * try: + * self.connection = mysql.connector.connect( + * host=self.host, # <<<<<<<<<<<<<< + * user=self.user, + * password=self.password, + */ + __pyx_t_5 = __Pyx_PyDict_NewPresized(5); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 24, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_host, __pyx_v_self->host) < 0) __PYX_ERR(0, 24, __pyx_L3_error) + + /* "cython_code/send_ads.pyx":25 + * self.connection = mysql.connector.connect( + * host=self.host, + * user=self.user, # <<<<<<<<<<<<<< + * password=self.password, + * database=self.database, + */ + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_user, __pyx_v_self->user) < 0) __PYX_ERR(0, 24, __pyx_L3_error) + + /* "cython_code/send_ads.pyx":26 + * host=self.host, + * user=self.user, + * password=self.password, # <<<<<<<<<<<<<< + * database=self.database, + * autocommit=True + */ + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_password, __pyx_v_self->password) < 0) __PYX_ERR(0, 24, __pyx_L3_error) + + /* "cython_code/send_ads.pyx":27 + * user=self.user, + * password=self.password, + * database=self.database, # <<<<<<<<<<<<<< + * autocommit=True + * ) + */ + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_database, __pyx_v_self->database) < 0) __PYX_ERR(0, 24, __pyx_L3_error) + + /* "cython_code/send_ads.pyx":28 + * password=self.password, + * database=self.database, + * autocommit=True # <<<<<<<<<<<<<< + * ) + * self.cursor = self.connection.cursor() + */ + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_autocommit, Py_True) < 0) __PYX_ERR(0, 24, __pyx_L3_error) + + /* "cython_code/send_ads.pyx":23 + * def reconnect(self): + * try: + * self.connection = mysql.connector.connect( # <<<<<<<<<<<<<< + * host=self.host, + * user=self.user, + */ + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_empty_tuple, __pyx_t_5); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 23, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_GIVEREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_v_self->connection); + __Pyx_DECREF(__pyx_v_self->connection); + __pyx_v_self->connection = __pyx_t_6; + __pyx_t_6 = 0; + + /* "cython_code/send_ads.pyx":30 + * autocommit=True + * ) + * self.cursor = self.connection.cursor() # <<<<<<<<<<<<<< + * except mysql.connector.Error as err: + * logging.error(err) + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->connection, __pyx_n_s_cursor); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 30, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL}; + __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 30, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_GIVEREF(__pyx_t_6); + __Pyx_GOTREF(__pyx_v_self->cursor); + __Pyx_DECREF(__pyx_v_self->cursor); + __pyx_v_self->cursor = __pyx_t_6; + __pyx_t_6 = 0; + + /* "cython_code/send_ads.pyx":22 + * + * def reconnect(self): + * try: # <<<<<<<<<<<<<< + * self.connection = mysql.connector.connect( + * host=self.host, + */ + } + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L8_try_end; + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "cython_code/send_ads.pyx":31 + * ) + * self.cursor = self.connection.cursor() + * except mysql.connector.Error as err: # <<<<<<<<<<<<<< + * logging.error(err) + * self.reconnect() + */ + __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4); + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_mysql); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 31, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_connector); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 31, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_Error); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 31, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_10 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_6, __pyx_t_8); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_ErrRestore(__pyx_t_6, __pyx_t_5, __pyx_t_4); + __pyx_t_6 = 0; __pyx_t_5 = 0; __pyx_t_4 = 0; + if (__pyx_t_10) { + __Pyx_AddTraceback("cython_code.send_ads.MyDatabase.reconnect", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6) < 0) __PYX_ERR(0, 31, __pyx_L5_except_error) + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __pyx_v_err = __pyx_t_5; + /*try:*/ { + + /* "cython_code/send_ads.pyx":32 + * self.cursor = self.connection.cursor() + * except mysql.connector.Error as err: + * logging.error(err) # <<<<<<<<<<<<<< + * self.reconnect() + * except Exception as err: + */ + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_logging); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 32, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_error); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 32, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_v_err}; + __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_11, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 32, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "cython_code/send_ads.pyx":33 + * except mysql.connector.Error as err: + * logging.error(err) + * self.reconnect() # <<<<<<<<<<<<<< + * except Exception as err: + * logging.error(err) + */ + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reconnect); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 33, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_9 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_9, NULL}; + __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_11, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 33, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + + /* "cython_code/send_ads.pyx":31 + * ) + * self.cursor = self.connection.cursor() + * except mysql.connector.Error as err: # <<<<<<<<<<<<<< + * logging.error(err) + * self.reconnect() + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + goto __pyx_L15; + } + __pyx_L14_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16) < 0)) __Pyx_ErrFetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_18); + __Pyx_XGOTREF(__pyx_t_19); + __pyx_t_10 = __pyx_lineno; __pyx_t_12 = __pyx_clineno; __pyx_t_13 = __pyx_filename; + { + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_ExceptionReset(__pyx_t_17, __pyx_t_18, __pyx_t_19); + } + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ErrRestore(__pyx_t_14, __pyx_t_15, __pyx_t_16); + __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; + __pyx_lineno = __pyx_t_10; __pyx_clineno = __pyx_t_12; __pyx_filename = __pyx_t_13; + goto __pyx_L5_except_error; + } + __pyx_L15:; + } + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L4_exception_handled; + } + + /* "cython_code/send_ads.pyx":34 + * logging.error(err) + * self.reconnect() + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + * + */ + __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); + if (__pyx_t_12) { + __Pyx_AddTraceback("cython_code.send_ads.MyDatabase.reconnect", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4) < 0) __PYX_ERR(0, 34, __pyx_L5_except_error) + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __pyx_v_err = __pyx_t_5; + /*try:*/ { + + /* "cython_code/send_ads.pyx":35 + * self.reconnect() + * except Exception as err: + * logging.error(err) # <<<<<<<<<<<<<< + * + * def select_users_by_id(self, int start_id, int end_id) -> list: + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_logging); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 35, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_error); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 35, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_11, __pyx_v_err}; + __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 35, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + + /* "cython_code/send_ads.pyx":34 + * logging.error(err) + * self.reconnect() + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + * + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + goto __pyx_L26; + } + __pyx_L25_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_19 = 0; __pyx_t_18 = 0; __pyx_t_17 = 0; __pyx_t_16 = 0; __pyx_t_15 = 0; __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_19, &__pyx_t_18, &__pyx_t_17) < 0)) __Pyx_ErrFetch(&__pyx_t_19, &__pyx_t_18, &__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_19); + __Pyx_XGOTREF(__pyx_t_18); + __Pyx_XGOTREF(__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_14); + __pyx_t_12 = __pyx_lineno; __pyx_t_10 = __pyx_clineno; __pyx_t_20 = __pyx_filename; + { + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_15, __pyx_t_14); + } + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_ErrRestore(__pyx_t_19, __pyx_t_18, __pyx_t_17); + __pyx_t_19 = 0; __pyx_t_18 = 0; __pyx_t_17 = 0; __pyx_t_16 = 0; __pyx_t_15 = 0; __pyx_t_14 = 0; + __pyx_lineno = __pyx_t_12; __pyx_clineno = __pyx_t_10; __pyx_filename = __pyx_t_20; + goto __pyx_L5_except_error; + } + __pyx_L26:; + } + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L4_exception_handled; + } + goto __pyx_L5_except_error; + + /* "cython_code/send_ads.pyx":22 + * + * def reconnect(self): + * try: # <<<<<<<<<<<<<< + * self.connection = mysql.connector.connect( + * host=self.host, + */ + __pyx_L5_except_error:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L4_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + __pyx_L8_try_end:; + } + + /* "cython_code/send_ads.pyx":21 + * self.reconnect() + * + * def reconnect(self): # <<<<<<<<<<<<<< + * try: + * self.connection = mysql.connector.connect( + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("cython_code.send_ads.MyDatabase.reconnect", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_err); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cython_code/send_ads.pyx":37 + * logging.error(err) + * + * def select_users_by_id(self, int start_id, int end_id) -> list: # <<<<<<<<<<<<<< + * try: + * sql_query = "SELECT * FROM `users` WHERE `id` >= %s AND `id` < %s;" + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_8send_ads_10MyDatabase_5select_users_by_id(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_8send_ads_10MyDatabase_5select_users_by_id = {"select_users_by_id", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_8send_ads_10MyDatabase_5select_users_by_id, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_8send_ads_10MyDatabase_5select_users_by_id(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + int __pyx_v_start_id; + int __pyx_v_end_id; + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[2] = {0,0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("select_users_by_id (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_start_id,&__pyx_n_s_end_id,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_start_id)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 37, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_end_id)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[1]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 37, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("select_users_by_id", 1, 2, 2, 1); __PYX_ERR(0, 37, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "select_users_by_id") < 0)) __PYX_ERR(0, 37, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 2)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + } + __pyx_v_start_id = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_start_id == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 37, __pyx_L3_error) + __pyx_v_end_id = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_end_id == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 37, __pyx_L3_error) + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("select_users_by_id", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 37, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.send_ads.MyDatabase.select_users_by_id", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_11cython_code_8send_ads_10MyDatabase_4select_users_by_id(((struct __pyx_obj_11cython_code_8send_ads_MyDatabase *)__pyx_v_self), __pyx_v_start_id, __pyx_v_end_id); + + /* function exit code */ + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_8send_ads_10MyDatabase_4select_users_by_id(struct __pyx_obj_11cython_code_8send_ads_MyDatabase *__pyx_v_self, int __pyx_v_start_id, int __pyx_v_end_id) { + PyObject *__pyx_v_sql_query = NULL; + PyObject *__pyx_v_query_values = NULL; + PyObject *__pyx_v_result = NULL; + PyObject *__pyx_v_err = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + unsigned int __pyx_t_7; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + int __pyx_t_10; + PyObject *__pyx_t_11 = NULL; + int __pyx_t_12; + char const *__pyx_t_13; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + PyObject *__pyx_t_17 = NULL; + PyObject *__pyx_t_18 = NULL; + PyObject *__pyx_t_19 = NULL; + char const *__pyx_t_20; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("select_users_by_id", 1); + + /* "cython_code/send_ads.pyx":38 + * + * def select_users_by_id(self, int start_id, int end_id) -> list: + * try: # <<<<<<<<<<<<<< + * sql_query = "SELECT * FROM `users` WHERE `id` >= %s AND `id` < %s;" + * query_values = (start_id, end_id) + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "cython_code/send_ads.pyx":39 + * def select_users_by_id(self, int start_id, int end_id) -> list: + * try: + * sql_query = "SELECT * FROM `users` WHERE `id` >= %s AND `id` < %s;" # <<<<<<<<<<<<<< + * query_values = (start_id, end_id) + * self.cursor.execute(sql_query, query_values) + */ + __Pyx_INCREF(__pyx_kp_u_SELECT_FROM_users_WHERE_id_s_AND); + __pyx_v_sql_query = __pyx_kp_u_SELECT_FROM_users_WHERE_id_s_AND; + + /* "cython_code/send_ads.pyx":40 + * try: + * sql_query = "SELECT * FROM `users` WHERE `id` >= %s AND `id` < %s;" + * query_values = (start_id, end_id) # <<<<<<<<<<<<<< + * self.cursor.execute(sql_query, query_values) + * result = self.cursor.fetchall() + */ + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_start_id); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 40, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_end_id); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 40, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = PyTuple_New(2); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 40, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_4); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_4)) __PYX_ERR(0, 40, __pyx_L3_error); + __Pyx_GIVEREF(__pyx_t_5); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 1, __pyx_t_5)) __PYX_ERR(0, 40, __pyx_L3_error); + __pyx_t_4 = 0; + __pyx_t_5 = 0; + __pyx_v_query_values = __pyx_t_6; + __pyx_t_6 = 0; + + /* "cython_code/send_ads.pyx":41 + * sql_query = "SELECT * FROM `users` WHERE `id` >= %s AND `id` < %s;" + * query_values = (start_id, end_id) + * self.cursor.execute(sql_query, query_values) # <<<<<<<<<<<<<< + * result = self.cursor.fetchall() + * return result + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->cursor, __pyx_n_s_execute); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 41, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[3] = {__pyx_t_4, __pyx_v_sql_query, __pyx_v_query_values}; + __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 2+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 41, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "cython_code/send_ads.pyx":42 + * query_values = (start_id, end_id) + * self.cursor.execute(sql_query, query_values) + * result = self.cursor.fetchall() # <<<<<<<<<<<<<< + * return result + * except mysql.connector.Error as err: + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_v_self->cursor, __pyx_n_s_fetchall); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 42, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL}; + __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 42, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __pyx_v_result = __pyx_t_6; + __pyx_t_6 = 0; + + /* "cython_code/send_ads.pyx":43 + * self.cursor.execute(sql_query, query_values) + * result = self.cursor.fetchall() + * return result # <<<<<<<<<<<<<< + * except mysql.connector.Error as err: + * logging.error(err) + */ + __Pyx_XDECREF(__pyx_r); + if (!(likely(PyList_CheckExact(__pyx_v_result))||((__pyx_v_result) == Py_None) || __Pyx_RaiseUnexpectedTypeError("list", __pyx_v_result))) __PYX_ERR(0, 43, __pyx_L3_error) + __Pyx_INCREF(__pyx_v_result); + __pyx_r = ((PyObject*)__pyx_v_result); + goto __pyx_L7_try_return; + + /* "cython_code/send_ads.pyx":38 + * + * def select_users_by_id(self, int start_id, int end_id) -> list: + * try: # <<<<<<<<<<<<<< + * sql_query = "SELECT * FROM `users` WHERE `id` >= %s AND `id` < %s;" + * query_values = (start_id, end_id) + */ + } + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "cython_code/send_ads.pyx":44 + * result = self.cursor.fetchall() + * return result + * except mysql.connector.Error as err: # <<<<<<<<<<<<<< + * logging.error(err) + * self.reconnect() + */ + __Pyx_ErrFetch(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4); + __Pyx_GetModuleGlobalName(__pyx_t_8, __pyx_n_s_mysql); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 44, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_8); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_8, __pyx_n_s_connector); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 44, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __pyx_t_8 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_Error); if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 44, __pyx_L5_except_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_10 = __Pyx_PyErr_GivenExceptionMatches(__pyx_t_6, __pyx_t_8); + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_ErrRestore(__pyx_t_6, __pyx_t_5, __pyx_t_4); + __pyx_t_6 = 0; __pyx_t_5 = 0; __pyx_t_4 = 0; + if (__pyx_t_10) { + __Pyx_AddTraceback("cython_code.send_ads.MyDatabase.select_users_by_id", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_5, &__pyx_t_6) < 0) __PYX_ERR(0, 44, __pyx_L5_except_error) + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __pyx_v_err = __pyx_t_5; + /*try:*/ { + + /* "cython_code/send_ads.pyx":45 + * return result + * except mysql.connector.Error as err: + * logging.error(err) # <<<<<<<<<<<<<< + * self.reconnect() + * except Exception as err: + */ + __Pyx_GetModuleGlobalName(__pyx_t_9, __pyx_n_s_logging); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 45, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_9); + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(__pyx_t_9, __pyx_n_s_error); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 45, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_11); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + __pyx_t_9 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_9, __pyx_v_err}; + __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_11, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 45, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + + /* "cython_code/send_ads.pyx":46 + * except mysql.connector.Error as err: + * logging.error(err) + * self.reconnect() # <<<<<<<<<<<<<< + * except Exception as err: + * logging.error(err) + */ + __pyx_t_11 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_self), __pyx_n_s_reconnect); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 46, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_9 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_11))) { + __pyx_t_9 = PyMethod_GET_SELF(__pyx_t_11); + if (likely(__pyx_t_9)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_11); + __Pyx_INCREF(__pyx_t_9); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_11, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_9, NULL}; + __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_11, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 46, __pyx_L14_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + + /* "cython_code/send_ads.pyx":44 + * result = self.cursor.fetchall() + * return result + * except mysql.connector.Error as err: # <<<<<<<<<<<<<< + * logging.error(err) + * self.reconnect() + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + goto __pyx_L15; + } + __pyx_L14_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_17, &__pyx_t_18, &__pyx_t_19); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16) < 0)) __Pyx_ErrFetch(&__pyx_t_14, &__pyx_t_15, &__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_18); + __Pyx_XGOTREF(__pyx_t_19); + __pyx_t_10 = __pyx_lineno; __pyx_t_12 = __pyx_clineno; __pyx_t_13 = __pyx_filename; + { + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_ExceptionReset(__pyx_t_17, __pyx_t_18, __pyx_t_19); + } + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_ErrRestore(__pyx_t_14, __pyx_t_15, __pyx_t_16); + __pyx_t_14 = 0; __pyx_t_15 = 0; __pyx_t_16 = 0; __pyx_t_17 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; + __pyx_lineno = __pyx_t_10; __pyx_clineno = __pyx_t_12; __pyx_filename = __pyx_t_13; + goto __pyx_L5_except_error; + } + __pyx_L15:; + } + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L4_exception_handled; + } + + /* "cython_code/send_ads.pyx":47 + * logging.error(err) + * self.reconnect() + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + * + */ + __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); + if (__pyx_t_12) { + __Pyx_AddTraceback("cython_code.send_ads.MyDatabase.select_users_by_id", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_5, &__pyx_t_4) < 0) __PYX_ERR(0, 47, __pyx_L5_except_error) + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __pyx_v_err = __pyx_t_5; + /*try:*/ { + + /* "cython_code/send_ads.pyx":48 + * self.reconnect() + * except Exception as err: + * logging.error(err) # <<<<<<<<<<<<<< + * + * cdef MyDatabase my_db = MyDatabase(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) + */ + __Pyx_GetModuleGlobalName(__pyx_t_11, __pyx_n_s_logging); if (unlikely(!__pyx_t_11)) __PYX_ERR(0, 48, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_11); + __pyx_t_9 = __Pyx_PyObject_GetAttrStr(__pyx_t_11, __pyx_n_s_error); if (unlikely(!__pyx_t_9)) __PYX_ERR(0, 48, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_9); + __Pyx_DECREF(__pyx_t_11); __pyx_t_11 = 0; + __pyx_t_11 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_9))) { + __pyx_t_11 = PyMethod_GET_SELF(__pyx_t_9); + if (likely(__pyx_t_11)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_9); + __Pyx_INCREF(__pyx_t_11); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_9, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_11, __pyx_v_err}; + __pyx_t_8 = __Pyx_PyObject_FastCall(__pyx_t_9, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + if (unlikely(!__pyx_t_8)) __PYX_ERR(0, 48, __pyx_L25_error) + __Pyx_GOTREF(__pyx_t_8); + __Pyx_DECREF(__pyx_t_9); __pyx_t_9 = 0; + } + __Pyx_DECREF(__pyx_t_8); __pyx_t_8 = 0; + } + + /* "cython_code/send_ads.pyx":47 + * logging.error(err) + * self.reconnect() + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + * + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + goto __pyx_L26; + } + __pyx_L25_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_19 = 0; __pyx_t_18 = 0; __pyx_t_17 = 0; __pyx_t_16 = 0; __pyx_t_15 = 0; __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_16, &__pyx_t_15, &__pyx_t_14); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_19, &__pyx_t_18, &__pyx_t_17) < 0)) __Pyx_ErrFetch(&__pyx_t_19, &__pyx_t_18, &__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_19); + __Pyx_XGOTREF(__pyx_t_18); + __Pyx_XGOTREF(__pyx_t_17); + __Pyx_XGOTREF(__pyx_t_16); + __Pyx_XGOTREF(__pyx_t_15); + __Pyx_XGOTREF(__pyx_t_14); + __pyx_t_12 = __pyx_lineno; __pyx_t_10 = __pyx_clineno; __pyx_t_20 = __pyx_filename; + { + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_16); + __Pyx_XGIVEREF(__pyx_t_15); + __Pyx_XGIVEREF(__pyx_t_14); + __Pyx_ExceptionReset(__pyx_t_16, __pyx_t_15, __pyx_t_14); + } + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_XGIVEREF(__pyx_t_17); + __Pyx_ErrRestore(__pyx_t_19, __pyx_t_18, __pyx_t_17); + __pyx_t_19 = 0; __pyx_t_18 = 0; __pyx_t_17 = 0; __pyx_t_16 = 0; __pyx_t_15 = 0; __pyx_t_14 = 0; + __pyx_lineno = __pyx_t_12; __pyx_clineno = __pyx_t_10; __pyx_filename = __pyx_t_20; + goto __pyx_L5_except_error; + } + __pyx_L26:; + } + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L4_exception_handled; + } + goto __pyx_L5_except_error; + + /* "cython_code/send_ads.pyx":38 + * + * def select_users_by_id(self, int start_id, int end_id) -> list: + * try: # <<<<<<<<<<<<<< + * sql_query = "SELECT * FROM `users` WHERE `id` >= %s AND `id` < %s;" + * query_values = (start_id, end_id) + */ + __pyx_L5_except_error:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L7_try_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; + __pyx_L4_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + } + + /* "cython_code/send_ads.pyx":37 + * logging.error(err) + * + * def select_users_by_id(self, int start_id, int end_id) -> list: # <<<<<<<<<<<<<< + * try: + * sql_query = "SELECT * FROM `users` WHERE `id` >= %s AND `id` < %s;" + */ + + /* function exit code */ + __pyx_r = ((PyObject*)Py_None); __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_8); + __Pyx_XDECREF(__pyx_t_9); + __Pyx_XDECREF(__pyx_t_11); + __Pyx_AddTraceback("cython_code.send_ads.MyDatabase.select_users_by_id", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_sql_query); + __Pyx_XDECREF(__pyx_v_query_values); + __Pyx_XDECREF(__pyx_v_result); + __Pyx_XDECREF(__pyx_v_err); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_8send_ads_10MyDatabase_7__reduce_cython__(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_8send_ads_10MyDatabase_7__reduce_cython__ = {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_8send_ads_10MyDatabase_7__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_8send_ads_10MyDatabase_7__reduce_cython__(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__reduce_cython__ (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + if (unlikely(__pyx_nargs > 0)) { + __Pyx_RaiseArgtupleInvalid("__reduce_cython__", 1, 0, 0, __pyx_nargs); return NULL;} + if (unlikely(__pyx_kwds) && __Pyx_NumKwargs_FASTCALL(__pyx_kwds) && unlikely(!__Pyx_CheckKeywordStrings(__pyx_kwds, "__reduce_cython__", 0))) return NULL; + __pyx_r = __pyx_pf_11cython_code_8send_ads_10MyDatabase_6__reduce_cython__(((struct __pyx_obj_11cython_code_8send_ads_MyDatabase *)__pyx_v_self)); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_8send_ads_10MyDatabase_6__reduce_cython__(struct __pyx_obj_11cython_code_8send_ads_MyDatabase *__pyx_v_self) { + PyObject *__pyx_v_state = 0; + PyObject *__pyx_v__dict = 0; + int __pyx_v_use_setstate; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__reduce_cython__", 1); + + /* "(tree fragment)":5 + * cdef object _dict + * cdef bint use_setstate + * state = (self.connection, self.cursor, self.database, self.host, self.password, self.user) # <<<<<<<<<<<<<< + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + */ + __pyx_t_1 = PyTuple_New(6); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v_self->connection); + __Pyx_GIVEREF(__pyx_v_self->connection); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v_self->connection)) __PYX_ERR(1, 5, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_self->cursor); + __Pyx_GIVEREF(__pyx_v_self->cursor); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_v_self->cursor)) __PYX_ERR(1, 5, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_self->database); + __Pyx_GIVEREF(__pyx_v_self->database); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_self->database)) __PYX_ERR(1, 5, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_self->host); + __Pyx_GIVEREF(__pyx_v_self->host); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 3, __pyx_v_self->host)) __PYX_ERR(1, 5, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_self->password); + __Pyx_GIVEREF(__pyx_v_self->password); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 4, __pyx_v_self->password)) __PYX_ERR(1, 5, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_self->user); + __Pyx_GIVEREF(__pyx_v_self->user); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 5, __pyx_v_self->user)) __PYX_ERR(1, 5, __pyx_L1_error); + __pyx_v_state = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "(tree fragment)":6 + * cdef bint use_setstate + * state = (self.connection, self.cursor, self.database, self.host, self.password, self.user) + * _dict = getattr(self, '__dict__', None) # <<<<<<<<<<<<<< + * if _dict is not None: + * state += (_dict,) + */ + __pyx_t_1 = __Pyx_GetAttr3(((PyObject *)__pyx_v_self), __pyx_n_s_dict, Py_None); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_v__dict = __pyx_t_1; + __pyx_t_1 = 0; + + /* "(tree fragment)":7 + * state = (self.connection, self.cursor, self.database, self.host, self.password, self.user) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + __pyx_t_2 = (__pyx_v__dict != Py_None); + if (__pyx_t_2) { + + /* "(tree fragment)":8 + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: + * state += (_dict,) # <<<<<<<<<<<<<< + * use_setstate = True + * else: + */ + __pyx_t_1 = PyTuple_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_v__dict); + __Pyx_GIVEREF(__pyx_v__dict); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_v__dict)) __PYX_ERR(1, 8, __pyx_L1_error); + __pyx_t_3 = PyNumber_InPlaceAdd(__pyx_v_state, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 8, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF_SET(__pyx_v_state, ((PyObject*)__pyx_t_3)); + __pyx_t_3 = 0; + + /* "(tree fragment)":9 + * if _dict is not None: + * state += (_dict,) + * use_setstate = True # <<<<<<<<<<<<<< + * else: + * use_setstate = self.connection is not None or self.cursor is not None or self.database is not None or self.host is not None or self.password is not None or self.user is not None + */ + __pyx_v_use_setstate = 1; + + /* "(tree fragment)":7 + * state = (self.connection, self.cursor, self.database, self.host, self.password, self.user) + * _dict = getattr(self, '__dict__', None) + * if _dict is not None: # <<<<<<<<<<<<<< + * state += (_dict,) + * use_setstate = True + */ + goto __pyx_L3; + } + + /* "(tree fragment)":11 + * use_setstate = True + * else: + * use_setstate = self.connection is not None or self.cursor is not None or self.database is not None or self.host is not None or self.password is not None or self.user is not None # <<<<<<<<<<<<<< + * if use_setstate: + * return __pyx_unpickle_MyDatabase, (type(self), 0xc59a5d0, None), state + */ + /*else*/ { + __pyx_t_4 = (__pyx_v_self->connection != Py_None); + if (!__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = (__pyx_v_self->cursor != Py_None); + if (!__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = (__pyx_v_self->database != ((PyObject*)Py_None)); + if (!__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = (__pyx_v_self->host != ((PyObject*)Py_None)); + if (!__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = (__pyx_v_self->password != ((PyObject*)Py_None)); + if (!__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = (__pyx_v_self->user != ((PyObject*)Py_None)); + __pyx_t_2 = __pyx_t_4; + __pyx_L4_bool_binop_done:; + __pyx_v_use_setstate = __pyx_t_2; + } + __pyx_L3:; + + /* "(tree fragment)":12 + * else: + * use_setstate = self.connection is not None or self.cursor is not None or self.database is not None or self.host is not None or self.password is not None or self.user is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_MyDatabase, (type(self), 0xc59a5d0, None), state + * else: + */ + if (__pyx_v_use_setstate) { + + /* "(tree fragment)":13 + * use_setstate = self.connection is not None or self.cursor is not None or self.database is not None or self.host is not None or self.password is not None or self.user is not None + * if use_setstate: + * return __pyx_unpickle_MyDatabase, (type(self), 0xc59a5d0, None), state # <<<<<<<<<<<<<< + * else: + * return __pyx_unpickle_MyDatabase, (type(self), 0xc59a5d0, state) + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_pyx_unpickle_MyDatabase); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))))) __PYX_ERR(1, 13, __pyx_L1_error); + __Pyx_INCREF(__pyx_int_207201744); + __Pyx_GIVEREF(__pyx_int_207201744); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_207201744)) __PYX_ERR(1, 13, __pyx_L1_error); + __Pyx_INCREF(Py_None); + __Pyx_GIVEREF(Py_None); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 2, Py_None)) __PYX_ERR(1, 13, __pyx_L1_error); + __pyx_t_5 = PyTuple_New(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 13, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_3); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_t_3)) __PYX_ERR(1, 13, __pyx_L1_error); + __Pyx_GIVEREF(__pyx_t_1); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_1)) __PYX_ERR(1, 13, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_v_state)) __PYX_ERR(1, 13, __pyx_L1_error); + __pyx_t_3 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_5; + __pyx_t_5 = 0; + goto __pyx_L0; + + /* "(tree fragment)":12 + * else: + * use_setstate = self.connection is not None or self.cursor is not None or self.database is not None or self.host is not None or self.password is not None or self.user is not None + * if use_setstate: # <<<<<<<<<<<<<< + * return __pyx_unpickle_MyDatabase, (type(self), 0xc59a5d0, None), state + * else: + */ + } + + /* "(tree fragment)":15 + * return __pyx_unpickle_MyDatabase, (type(self), 0xc59a5d0, None), state + * else: + * return __pyx_unpickle_MyDatabase, (type(self), 0xc59a5d0, state) # <<<<<<<<<<<<<< + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_MyDatabase__set_state(self, __pyx_state) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_pyx_unpickle_MyDatabase); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + __Pyx_GIVEREF(((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self)))); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 0, ((PyObject *)Py_TYPE(((PyObject *)__pyx_v_self))))) __PYX_ERR(1, 15, __pyx_L1_error); + __Pyx_INCREF(__pyx_int_207201744); + __Pyx_GIVEREF(__pyx_int_207201744); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_int_207201744)) __PYX_ERR(1, 15, __pyx_L1_error); + __Pyx_INCREF(__pyx_v_state); + __Pyx_GIVEREF(__pyx_v_state); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_v_state)) __PYX_ERR(1, 15, __pyx_L1_error); + __pyx_t_3 = PyTuple_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 15, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_5); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 0, __pyx_t_5)) __PYX_ERR(1, 15, __pyx_L1_error); + __Pyx_GIVEREF(__pyx_t_1); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_3, 1, __pyx_t_1)) __PYX_ERR(1, 15, __pyx_L1_error); + __pyx_t_5 = 0; + __pyx_t_1 = 0; + __pyx_r = __pyx_t_3; + __pyx_t_3 = 0; + goto __pyx_L0; + } + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_AddTraceback("cython_code.send_ads.MyDatabase.__reduce_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_state); + __Pyx_XDECREF(__pyx_v__dict); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":16 + * else: + * return __pyx_unpickle_MyDatabase, (type(self), 0xc59a5d0, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_MyDatabase__set_state(self, __pyx_state) + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_8send_ads_10MyDatabase_9__setstate_cython__(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_8send_ads_10MyDatabase_9__setstate_cython__ = {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_8send_ads_10MyDatabase_9__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_8send_ads_10MyDatabase_9__setstate_cython__(PyObject *__pyx_v_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + PyObject *__pyx_v___pyx_state = 0; + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[1] = {0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__setstate_cython__ (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_state,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 16, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__setstate_cython__") < 0)) __PYX_ERR(1, 16, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 1)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + } + __pyx_v___pyx_state = values[0]; + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__setstate_cython__", 1, 1, 1, __pyx_nargs); __PYX_ERR(1, 16, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.send_ads.MyDatabase.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_11cython_code_8send_ads_10MyDatabase_8__setstate_cython__(((struct __pyx_obj_11cython_code_8send_ads_MyDatabase *)__pyx_v_self), __pyx_v___pyx_state); + + /* function exit code */ + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_8send_ads_10MyDatabase_8__setstate_cython__(struct __pyx_obj_11cython_code_8send_ads_MyDatabase *__pyx_v_self, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__setstate_cython__", 1); + + /* "(tree fragment)":17 + * return __pyx_unpickle_MyDatabase, (type(self), 0xc59a5d0, state) + * def __setstate_cython__(self, __pyx_state): + * __pyx_unpickle_MyDatabase__set_state(self, __pyx_state) # <<<<<<<<<<<<<< + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None) || __Pyx_RaiseUnexpectedTypeError("tuple", __pyx_v___pyx_state))) __PYX_ERR(1, 17, __pyx_L1_error) + __pyx_t_1 = __pyx_f_11cython_code_8send_ads___pyx_unpickle_MyDatabase__set_state(__pyx_v_self, ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":16 + * else: + * return __pyx_unpickle_MyDatabase, (type(self), 0xc59a5d0, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_MyDatabase__set_state(self, __pyx_state) + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("cython_code.send_ads.MyDatabase.__setstate_cython__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cython_code/send_ads.pyx":52 + * cdef MyDatabase my_db = MyDatabase(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) + * + * def copy_message_sync(int chat_id, int from_chat_id, int message_id, **kwargs): # <<<<<<<<<<<<<< + * url = f"https://api.telegram.org/bot{BOT_TOKEN}/copyMessage" + * data = { + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_8send_ads_1copy_message_sync(PyObject *__pyx_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_8send_ads_1copy_message_sync = {"copy_message_sync", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_8send_ads_1copy_message_sync, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_8send_ads_1copy_message_sync(PyObject *__pyx_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + int __pyx_v_chat_id; + int __pyx_v_from_chat_id; + int __pyx_v_message_id; + PyObject *__pyx_v_kwargs = 0; + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[3] = {0,0,0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("copy_message_sync (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL; + __Pyx_GOTREF(__pyx_v_kwargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_chat_id,&__pyx_n_s_from_chat_id,&__pyx_n_s_message_id,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_chat_id)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 52, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_from_chat_id)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[1]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 52, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("copy_message_sync", 1, 3, 3, 1); __PYX_ERR(0, 52, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_message_id)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[2]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 52, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("copy_message_sync", 1, 3, 3, 2); __PYX_ERR(0, 52, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, __pyx_v_kwargs, values + 0, kwd_pos_args, "copy_message_sync") < 0)) __PYX_ERR(0, 52, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 3)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); + } + __pyx_v_chat_id = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_chat_id == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 52, __pyx_L3_error) + __pyx_v_from_chat_id = __Pyx_PyInt_As_int(values[1]); if (unlikely((__pyx_v_from_chat_id == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 52, __pyx_L3_error) + __pyx_v_message_id = __Pyx_PyInt_As_int(values[2]); if (unlikely((__pyx_v_message_id == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 52, __pyx_L3_error) + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("copy_message_sync", 1, 3, 3, __pyx_nargs); __PYX_ERR(0, 52, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; + __Pyx_AddTraceback("cython_code.send_ads.copy_message_sync", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_11cython_code_8send_ads_copy_message_sync(__pyx_self, __pyx_v_chat_id, __pyx_v_from_chat_id, __pyx_v_message_id, __pyx_v_kwargs); + + /* function exit code */ + __Pyx_DECREF(__pyx_v_kwargs); + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_8send_ads_copy_message_sync(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_chat_id, int __pyx_v_from_chat_id, int __pyx_v_message_id, PyObject *__pyx_v_kwargs) { + PyObject *__pyx_v_url = NULL; + PyObject *__pyx_v_data = NULL; + PyObject *__pyx_v_response = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + Py_UCS4 __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + unsigned int __pyx_t_7; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("copy_message_sync", 1); + + /* "cython_code/send_ads.pyx":53 + * + * def copy_message_sync(int chat_id, int from_chat_id, int message_id, **kwargs): + * url = f"https://api.telegram.org/bot{BOT_TOKEN}/copyMessage" # <<<<<<<<<<<<<< + * data = { + * "chat_id": chat_id, + */ + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = 0; + __pyx_t_3 = 127; + __Pyx_INCREF(__pyx_kp_u_https_api_telegram_org_bot); + __pyx_t_2 += 28; + __Pyx_GIVEREF(__pyx_kp_u_https_api_telegram_org_bot); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_https_api_telegram_org_bot); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_BOT_TOKEN); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_t_4, __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_3; + __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5); + __pyx_t_5 = 0; + __Pyx_INCREF(__pyx_kp_u_copyMessage); + __pyx_t_2 += 12; + __Pyx_GIVEREF(__pyx_kp_u_copyMessage); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_copyMessage); + __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_1, 3, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_url = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":55 + * url = f"https://api.telegram.org/bot{BOT_TOKEN}/copyMessage" + * data = { + * "chat_id": chat_id, # <<<<<<<<<<<<<< + * "from_chat_id": from_chat_id, + * "message_id": message_id + */ + __pyx_t_5 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 55, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_chat_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 55, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_5, __pyx_n_u_chat_id, __pyx_t_1) < 0) __PYX_ERR(0, 55, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "cython_code/send_ads.pyx":56 + * data = { + * "chat_id": chat_id, + * "from_chat_id": from_chat_id, # <<<<<<<<<<<<<< + * "message_id": message_id + * } + */ + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_from_chat_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 56, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_5, __pyx_n_u_from_chat_id, __pyx_t_1) < 0) __PYX_ERR(0, 55, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "cython_code/send_ads.pyx":57 + * "chat_id": chat_id, + * "from_chat_id": from_chat_id, + * "message_id": message_id # <<<<<<<<<<<<<< + * } + * data.update(kwargs) + */ + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_message_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 57, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_5, __pyx_n_u_message_id, __pyx_t_1) < 0) __PYX_ERR(0, 55, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_data = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":59 + * "message_id": message_id + * } + * data.update(kwargs) # <<<<<<<<<<<<<< + * response = requests.post(url, data=data) + * return response.json() + */ + __pyx_t_5 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyDict_Type_update, __pyx_v_data, __pyx_v_kwargs); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 59, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":60 + * } + * data.update(kwargs) + * response = requests.post(url, data=data) # <<<<<<<<<<<<<< + * return response.json() + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_requests); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_post); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_url); + __Pyx_GIVEREF(__pyx_v_url); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_url)) __PYX_ERR(0, 60, __pyx_L1_error); + __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_data, __pyx_v_data) < 0) __PYX_ERR(0, 60, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_response = __pyx_t_6; + __pyx_t_6 = 0; + + /* "cython_code/send_ads.pyx":61 + * data.update(kwargs) + * response = requests.post(url, data=data) + * return response.json() # <<<<<<<<<<<<<< + * + * def send_message_sync(int chat_id, str text, **kwargs): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_response, __pyx_n_s_json); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 61, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL}; + __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 61, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + goto __pyx_L0; + + /* "cython_code/send_ads.pyx":52 + * cdef MyDatabase my_db = MyDatabase(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) + * + * def copy_message_sync(int chat_id, int from_chat_id, int message_id, **kwargs): # <<<<<<<<<<<<<< + * url = f"https://api.telegram.org/bot{BOT_TOKEN}/copyMessage" + * data = { + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("cython_code.send_ads.copy_message_sync", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_url); + __Pyx_XDECREF(__pyx_v_data); + __Pyx_XDECREF(__pyx_v_response); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cython_code/send_ads.pyx":63 + * return response.json() + * + * def send_message_sync(int chat_id, str text, **kwargs): # <<<<<<<<<<<<<< + * url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage" + * data = { + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_8send_ads_3send_message_sync(PyObject *__pyx_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_8send_ads_3send_message_sync = {"send_message_sync", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_8send_ads_3send_message_sync, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_8send_ads_3send_message_sync(PyObject *__pyx_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + int __pyx_v_chat_id; + PyObject *__pyx_v_text = 0; + PyObject *__pyx_v_kwargs = 0; + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[2] = {0,0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("send_message_sync (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + __pyx_v_kwargs = PyDict_New(); if (unlikely(!__pyx_v_kwargs)) return NULL; + __Pyx_GOTREF(__pyx_v_kwargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_chat_id,&__pyx_n_s_text,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_chat_id)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 63, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_text)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[1]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 63, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("send_message_sync", 1, 2, 2, 1); __PYX_ERR(0, 63, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, __pyx_v_kwargs, values + 0, kwd_pos_args, "send_message_sync") < 0)) __PYX_ERR(0, 63, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 2)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + } + __pyx_v_chat_id = __Pyx_PyInt_As_int(values[0]); if (unlikely((__pyx_v_chat_id == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 63, __pyx_L3_error) + __pyx_v_text = ((PyObject*)values[1]); + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("send_message_sync", 1, 2, 2, __pyx_nargs); __PYX_ERR(0, 63, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_DECREF(__pyx_v_kwargs); __pyx_v_kwargs = 0; + __Pyx_AddTraceback("cython_code.send_ads.send_message_sync", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + if (unlikely(!__Pyx_ArgTypeTest(((PyObject *)__pyx_v_text), (&PyUnicode_Type), 1, "text", 1))) __PYX_ERR(0, 63, __pyx_L1_error) + __pyx_r = __pyx_pf_11cython_code_8send_ads_2send_message_sync(__pyx_self, __pyx_v_chat_id, __pyx_v_text, __pyx_v_kwargs); + + /* function exit code */ + goto __pyx_L0; + __pyx_L1_error:; + __pyx_r = NULL; + __pyx_L0:; + __Pyx_DECREF(__pyx_v_kwargs); + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_8send_ads_2send_message_sync(CYTHON_UNUSED PyObject *__pyx_self, int __pyx_v_chat_id, PyObject *__pyx_v_text, PyObject *__pyx_v_kwargs) { + PyObject *__pyx_v_url = NULL; + PyObject *__pyx_v_data = NULL; + PyObject *__pyx_v_response = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + Py_ssize_t __pyx_t_2; + Py_UCS4 __pyx_t_3; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + unsigned int __pyx_t_7; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("send_message_sync", 1); + + /* "cython_code/send_ads.pyx":64 + * + * def send_message_sync(int chat_id, str text, **kwargs): + * url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage" # <<<<<<<<<<<<<< + * data = { + * "chat_id": chat_id, + */ + __pyx_t_1 = PyTuple_New(3); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 64, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = 0; + __pyx_t_3 = 127; + __Pyx_INCREF(__pyx_kp_u_https_api_telegram_org_bot); + __pyx_t_2 += 28; + __Pyx_GIVEREF(__pyx_kp_u_https_api_telegram_org_bot); + PyTuple_SET_ITEM(__pyx_t_1, 0, __pyx_kp_u_https_api_telegram_org_bot); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_BOT_TOKEN); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 64, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_PyObject_FormatSimple(__pyx_t_4, __pyx_empty_unicode); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 64, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_3 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) > __pyx_t_3) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_5) : __pyx_t_3; + __pyx_t_2 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + PyTuple_SET_ITEM(__pyx_t_1, 1, __pyx_t_5); + __pyx_t_5 = 0; + __Pyx_INCREF(__pyx_kp_u_sendMessage); + __pyx_t_2 += 12; + __Pyx_GIVEREF(__pyx_kp_u_sendMessage); + PyTuple_SET_ITEM(__pyx_t_1, 2, __pyx_kp_u_sendMessage); + __pyx_t_5 = __Pyx_PyUnicode_Join(__pyx_t_1, 3, __pyx_t_2, __pyx_t_3); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 64, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_v_url = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":66 + * url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage" + * data = { + * "chat_id": chat_id, # <<<<<<<<<<<<<< + * "text": text + * } + */ + __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 66, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_PyInt_From_int(__pyx_v_chat_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 66, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (PyDict_SetItem(__pyx_t_5, __pyx_n_u_chat_id, __pyx_t_1) < 0) __PYX_ERR(0, 66, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "cython_code/send_ads.pyx":67 + * data = { + * "chat_id": chat_id, + * "text": text # <<<<<<<<<<<<<< + * } + * data.update(kwargs) + */ + if (PyDict_SetItem(__pyx_t_5, __pyx_n_u_text, __pyx_v_text) < 0) __PYX_ERR(0, 66, __pyx_L1_error) + __pyx_v_data = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":69 + * "text": text + * } + * data.update(kwargs) # <<<<<<<<<<<<<< + * response = requests.post(url, data=data) + * return response.json() + */ + __pyx_t_5 = __Pyx_CallUnboundCMethod1(&__pyx_umethod_PyDict_Type_update, __pyx_v_data, __pyx_v_kwargs); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 69, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":70 + * } + * data.update(kwargs) + * response = requests.post(url, data=data) # <<<<<<<<<<<<<< + * return response.json() + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_requests); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 70, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_post); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 70, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 70, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_url); + __Pyx_GIVEREF(__pyx_v_url); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_url)) __PYX_ERR(0, 70, __pyx_L1_error); + __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 70, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_data, __pyx_v_data) < 0) __PYX_ERR(0, 70, __pyx_L1_error) + __pyx_t_6 = __Pyx_PyObject_Call(__pyx_t_1, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 70, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_response = __pyx_t_6; + __pyx_t_6 = 0; + + /* "cython_code/send_ads.pyx":71 + * data.update(kwargs) + * response = requests.post(url, data=data) + * return response.json() # <<<<<<<<<<<<<< + * + * def send_ads(): + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_v_response, __pyx_n_s_json); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 71, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL}; + __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 71, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __pyx_r = __pyx_t_6; + __pyx_t_6 = 0; + goto __pyx_L0; + + /* "cython_code/send_ads.pyx":63 + * return response.json() + * + * def send_message_sync(int chat_id, str text, **kwargs): # <<<<<<<<<<<<<< + * url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage" + * data = { + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_AddTraceback("cython_code.send_ads.send_message_sync", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_url); + __Pyx_XDECREF(__pyx_v_data); + __Pyx_XDECREF(__pyx_v_response); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "cython_code/send_ads.pyx":73 + * return response.json() + * + * def send_ads(): # <<<<<<<<<<<<<< + * cdef float start_time, end_time, total_time, per_time + * cdef int start_index, end_index, total_users, chat_id, from_chat_id, message_id + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_8send_ads_5send_ads(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_8send_ads_5send_ads = {"send_ads", (PyCFunction)__pyx_pw_11cython_code_8send_ads_5send_ads, METH_NOARGS, 0}; +static PyObject *__pyx_pw_11cython_code_8send_ads_5send_ads(PyObject *__pyx_self, CYTHON_UNUSED PyObject *unused) { + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("send_ads (wrapper)", 0); + __pyx_kwvalues = __Pyx_KwValues_VARARGS(__pyx_args, __pyx_nargs); + __pyx_r = __pyx_pf_11cython_code_8send_ads_4send_ads(__pyx_self); + + /* function exit code */ + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_8send_ads_4send_ads(CYTHON_UNUSED PyObject *__pyx_self) { + float __pyx_v_start_time; + float __pyx_v_end_time; + float __pyx_v_total_time; + float __pyx_v_per_time; + int __pyx_v_start_index; + int __pyx_v_end_index; + int __pyx_v_total_users; + int __pyx_v_chat_id; + int __pyx_v_from_chat_id; + int __pyx_v_message_id; + PyObject *__pyx_v_caption = 0; + PyObject *__pyx_v_users_batch = NULL; + PyObject *__pyx_v_reply_markup = NULL; + PyObject *__pyx_v_ads_data = NULL; + PyObject *__pyx_v_user = NULL; + PyObject *__pyx_v_err = NULL; + PyObject *__pyx_v_summary_message = NULL; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + unsigned int __pyx_t_7; + float __pyx_t_8; + int __pyx_t_9; + int __pyx_t_10; + long __pyx_t_11; + long __pyx_t_12; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + Py_ssize_t __pyx_t_15; + Py_UCS4 __pyx_t_16; + Py_ssize_t __pyx_t_17; + PyObject *(*__pyx_t_18)(PyObject *); + PyObject *__pyx_t_19 = NULL; + PyObject *__pyx_t_20 = NULL; + PyObject *__pyx_t_21 = NULL; + PyObject *__pyx_t_22 = NULL; + PyObject *__pyx_t_23 = NULL; + PyObject *__pyx_t_24 = NULL; + int __pyx_t_25; + char const *__pyx_t_26; + PyObject *__pyx_t_27 = NULL; + PyObject *__pyx_t_28 = NULL; + PyObject *__pyx_t_29 = NULL; + PyObject *__pyx_t_30 = NULL; + PyObject *__pyx_t_31 = NULL; + PyObject *__pyx_t_32 = NULL; + PyObject *__pyx_t_33 = NULL; + char const *__pyx_t_34; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("send_ads", 1); + + /* "cython_code/send_ads.pyx":77 + * cdef int start_index, end_index, total_users, chat_id, from_chat_id, message_id + * cdef str caption + * users_batch = None # <<<<<<<<<<<<<< + * reply_markup = None + * + */ + __Pyx_INCREF(Py_None); + __pyx_v_users_batch = Py_None; + + /* "cython_code/send_ads.pyx":78 + * cdef str caption + * users_batch = None + * reply_markup = None # <<<<<<<<<<<<<< + * + * try: + */ + __Pyx_INCREF(Py_None); + __pyx_v_reply_markup = Py_None; + + /* "cython_code/send_ads.pyx":80 + * reply_markup = None + * + * try: # <<<<<<<<<<<<<< + * start_time = time.time() + * ads_data = file_db.reading_db()['ads'] + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "cython_code/send_ads.pyx":81 + * + * try: + * start_time = time.time() # <<<<<<<<<<<<<< + * ads_data = file_db.reading_db()['ads'] + * if ads_data: + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 81, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 81, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 81, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __pyx_t_8 = __pyx_PyFloat_AsFloat(__pyx_t_4); if (unlikely((__pyx_t_8 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 81, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_start_time = __pyx_t_8; + + /* "cython_code/send_ads.pyx":82 + * try: + * start_time = time.time() + * ads_data = file_db.reading_db()['ads'] # <<<<<<<<<<<<<< + * if ads_data: + * start_index = ads_data['start'] + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_file_db); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 82, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_reading_db); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 82, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_6, NULL}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 82, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_t_4, __pyx_n_u_ads); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 82, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_v_ads_data = __pyx_t_5; + __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":83 + * start_time = time.time() + * ads_data = file_db.reading_db()['ads'] + * if ads_data: # <<<<<<<<<<<<<< + * start_index = ads_data['start'] + * from_chat_id = ads_data['from_chat_id'] + */ + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_ads_data); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 83, __pyx_L3_error) + if (__pyx_t_9) { + + /* "cython_code/send_ads.pyx":84 + * ads_data = file_db.reading_db()['ads'] + * if ads_data: + * start_index = ads_data['start'] # <<<<<<<<<<<<<< + * from_chat_id = ads_data['from_chat_id'] + * message_id = ads_data['message_id'] + */ + __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ads_data, __pyx_n_u_start); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 84, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 84, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_start_index = __pyx_t_10; + + /* "cython_code/send_ads.pyx":85 + * if ads_data: + * start_index = ads_data['start'] + * from_chat_id = ads_data['from_chat_id'] # <<<<<<<<<<<<<< + * message_id = ads_data['message_id'] + * caption = ads_data['caption'] + */ + __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ads_data, __pyx_n_u_from_chat_id); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 85, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 85, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_from_chat_id = __pyx_t_10; + + /* "cython_code/send_ads.pyx":86 + * start_index = ads_data['start'] + * from_chat_id = ads_data['from_chat_id'] + * message_id = ads_data['message_id'] # <<<<<<<<<<<<<< + * caption = ads_data['caption'] + * reply_markup = ads_data['reply_markup'] + */ + __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ads_data, __pyx_n_u_message_id); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 86, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 86, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_message_id = __pyx_t_10; + + /* "cython_code/send_ads.pyx":87 + * from_chat_id = ads_data['from_chat_id'] + * message_id = ads_data['message_id'] + * caption = ads_data['caption'] # <<<<<<<<<<<<<< + * reply_markup = ads_data['reply_markup'] + * total_users = ads_data['total_users'] + */ + __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ads_data, __pyx_n_u_caption); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 87, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + if (!(likely(PyUnicode_CheckExact(__pyx_t_5))||((__pyx_t_5) == Py_None) || __Pyx_RaiseUnexpectedTypeError("unicode", __pyx_t_5))) __PYX_ERR(0, 87, __pyx_L3_error) + __pyx_v_caption = ((PyObject*)__pyx_t_5); + __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":88 + * message_id = ads_data['message_id'] + * caption = ads_data['caption'] + * reply_markup = ads_data['reply_markup'] # <<<<<<<<<<<<<< + * total_users = ads_data['total_users'] + * end_index = min(start_index + 100, total_users) + */ + __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ads_data, __pyx_n_u_reply_markup); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 88, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF_SET(__pyx_v_reply_markup, __pyx_t_5); + __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":89 + * caption = ads_data['caption'] + * reply_markup = ads_data['reply_markup'] + * total_users = ads_data['total_users'] # <<<<<<<<<<<<<< + * end_index = min(start_index + 100, total_users) + * + */ + __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ads_data, __pyx_n_u_total_users); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 89, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_5); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 89, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_total_users = __pyx_t_10; + + /* "cython_code/send_ads.pyx":90 + * reply_markup = ads_data['reply_markup'] + * total_users = ads_data['total_users'] + * end_index = min(start_index + 100, total_users) # <<<<<<<<<<<<<< + * + * users_batch = my_db.select_users_by_id(start_index, end_index) + */ + __pyx_t_10 = __pyx_v_total_users; + __pyx_t_11 = (__pyx_v_start_index + 0x64); + __pyx_t_9 = (__pyx_t_10 < __pyx_t_11); + if (__pyx_t_9) { + __pyx_t_12 = __pyx_t_10; + } else { + __pyx_t_12 = __pyx_t_11; + } + __pyx_v_end_index = __pyx_t_12; + + /* "cython_code/send_ads.pyx":92 + * end_index = min(start_index + 100, total_users) + * + * users_batch = my_db.select_users_by_id(start_index, end_index) # <<<<<<<<<<<<<< + * if users_batch: + * logging.info(f'Sending ads to users {start_index} - {end_index} (Total: {len(users_batch)})') + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v_11cython_code_8send_ads_my_db), __pyx_n_s_select_users_by_id); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 92, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_start_index); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 92, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_13 = __Pyx_PyInt_From_int(__pyx_v_end_index); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 92, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[3] = {__pyx_t_14, __pyx_t_6, __pyx_t_13}; + __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_7, 2+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 92, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF_SET(__pyx_v_users_batch, __pyx_t_5); + __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":93 + * + * users_batch = my_db.select_users_by_id(start_index, end_index) + * if users_batch: # <<<<<<<<<<<<<< + * logging.info(f'Sending ads to users {start_index} - {end_index} (Total: {len(users_batch)})') + * for user in users_batch: + */ + __pyx_t_9 = __Pyx_PyObject_IsTrue(__pyx_v_users_batch); if (unlikely((__pyx_t_9 < 0))) __PYX_ERR(0, 93, __pyx_L3_error) + if (__pyx_t_9) { + + /* "cython_code/send_ads.pyx":94 + * users_batch = my_db.select_users_by_id(start_index, end_index) + * if users_batch: + * logging.info(f'Sending ads to users {start_index} - {end_index} (Total: {len(users_batch)})') # <<<<<<<<<<<<<< + * for user in users_batch: + * try: + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_logging); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 94, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_info); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 94, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = PyTuple_New(7); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 94, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_15 = 0; + __pyx_t_16 = 127; + __Pyx_INCREF(__pyx_kp_u_Sending_ads_to_users); + __pyx_t_15 += 21; + __Pyx_GIVEREF(__pyx_kp_u_Sending_ads_to_users); + PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_kp_u_Sending_ads_to_users); + __pyx_t_6 = __Pyx_PyUnicode_From_int(__pyx_v_start_index, 0, ' ', 'd'); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 94, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_INCREF(__pyx_kp_u_); + __pyx_t_15 += 3; + __Pyx_GIVEREF(__pyx_kp_u_); + PyTuple_SET_ITEM(__pyx_t_4, 2, __pyx_kp_u_); + __pyx_t_6 = __Pyx_PyUnicode_From_int(__pyx_v_end_index, 0, ' ', 'd'); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 94, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_4, 3, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_INCREF(__pyx_kp_u_Total); + __pyx_t_15 += 9; + __Pyx_GIVEREF(__pyx_kp_u_Total); + PyTuple_SET_ITEM(__pyx_t_4, 4, __pyx_kp_u_Total); + __pyx_t_17 = PyObject_Length(__pyx_v_users_batch); if (unlikely(__pyx_t_17 == ((Py_ssize_t)-1))) __PYX_ERR(0, 94, __pyx_L3_error) + __pyx_t_6 = __Pyx_PyUnicode_From_Py_ssize_t(__pyx_t_17, 0, ' ', 'd'); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 94, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + PyTuple_SET_ITEM(__pyx_t_4, 5, __pyx_t_6); + __pyx_t_6 = 0; + __Pyx_INCREF(__pyx_kp_u__2); + __pyx_t_15 += 1; + __Pyx_GIVEREF(__pyx_kp_u__2); + PyTuple_SET_ITEM(__pyx_t_4, 6, __pyx_kp_u__2); + __pyx_t_6 = __Pyx_PyUnicode_Join(__pyx_t_4, 7, __pyx_t_15, __pyx_t_16); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 94, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_t_6}; + __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_13, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 94, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":95 + * if users_batch: + * logging.info(f'Sending ads to users {start_index} - {end_index} (Total: {len(users_batch)})') + * for user in users_batch: # <<<<<<<<<<<<<< + * try: + * chat_id = user[1] + */ + if (likely(PyList_CheckExact(__pyx_v_users_batch)) || PyTuple_CheckExact(__pyx_v_users_batch)) { + __pyx_t_5 = __pyx_v_users_batch; __Pyx_INCREF(__pyx_t_5); + __pyx_t_15 = 0; + __pyx_t_18 = NULL; + } else { + __pyx_t_15 = -1; __pyx_t_5 = PyObject_GetIter(__pyx_v_users_batch); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 95, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_18 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_5); if (unlikely(!__pyx_t_18)) __PYX_ERR(0, 95, __pyx_L3_error) + } + for (;;) { + if (likely(!__pyx_t_18)) { + if (likely(PyList_CheckExact(__pyx_t_5))) { + { + Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_5); + #if !CYTHON_ASSUME_SAFE_MACROS + if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 95, __pyx_L3_error) + #endif + if (__pyx_t_15 >= __pyx_temp) break; + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_13 = PyList_GET_ITEM(__pyx_t_5, __pyx_t_15); __Pyx_INCREF(__pyx_t_13); __pyx_t_15++; if (unlikely((0 < 0))) __PYX_ERR(0, 95, __pyx_L3_error) + #else + __pyx_t_13 = __Pyx_PySequence_ITEM(__pyx_t_5, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 95, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_13); + #endif + } else { + { + Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_5); + #if !CYTHON_ASSUME_SAFE_MACROS + if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 95, __pyx_L3_error) + #endif + if (__pyx_t_15 >= __pyx_temp) break; + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_13 = PyTuple_GET_ITEM(__pyx_t_5, __pyx_t_15); __Pyx_INCREF(__pyx_t_13); __pyx_t_15++; if (unlikely((0 < 0))) __PYX_ERR(0, 95, __pyx_L3_error) + #else + __pyx_t_13 = __Pyx_PySequence_ITEM(__pyx_t_5, __pyx_t_15); __pyx_t_15++; if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 95, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_13); + #endif + } + } else { + __pyx_t_13 = __pyx_t_18(__pyx_t_5); + if (unlikely(!__pyx_t_13)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 95, __pyx_L3_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_13); + } + __Pyx_XDECREF_SET(__pyx_v_user, __pyx_t_13); + __pyx_t_13 = 0; + + /* "cython_code/send_ads.pyx":96 + * logging.info(f'Sending ads to users {start_index} - {end_index} (Total: {len(users_batch)})') + * for user in users_batch: + * try: # <<<<<<<<<<<<<< + * chat_id = user[1] + * copy_message_sync(chat_id, + */ + { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ExceptionSave(&__pyx_t_19, &__pyx_t_20, &__pyx_t_21); + __Pyx_XGOTREF(__pyx_t_19); + __Pyx_XGOTREF(__pyx_t_20); + __Pyx_XGOTREF(__pyx_t_21); + /*try:*/ { + + /* "cython_code/send_ads.pyx":97 + * for user in users_batch: + * try: + * chat_id = user[1] # <<<<<<<<<<<<<< + * copy_message_sync(chat_id, + * from_chat_id, + */ + __pyx_t_13 = __Pyx_GetItemInt(__pyx_v_user, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 97, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_10 = __Pyx_PyInt_As_int(__pyx_t_13); if (unlikely((__pyx_t_10 == (int)-1) && PyErr_Occurred())) __PYX_ERR(0, 97, __pyx_L13_error) + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_v_chat_id = __pyx_t_10; + + /* "cython_code/send_ads.pyx":98 + * try: + * chat_id = user[1] + * copy_message_sync(chat_id, # <<<<<<<<<<<<<< + * from_chat_id, + * message_id, + */ + __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_copy_message_sync); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 98, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_6 = __Pyx_PyInt_From_int(__pyx_v_chat_id); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 98, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_6); + + /* "cython_code/send_ads.pyx":99 + * chat_id = user[1] + * copy_message_sync(chat_id, + * from_chat_id, # <<<<<<<<<<<<<< + * message_id, + * caption=caption, + */ + __pyx_t_4 = __Pyx_PyInt_From_int(__pyx_v_from_chat_id); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 99, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_4); + + /* "cython_code/send_ads.pyx":100 + * copy_message_sync(chat_id, + * from_chat_id, + * message_id, # <<<<<<<<<<<<<< + * caption=caption, + * reply_markup=reply_markup) + */ + __pyx_t_14 = __Pyx_PyInt_From_int(__pyx_v_message_id); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 100, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_14); + + /* "cython_code/send_ads.pyx":98 + * try: + * chat_id = user[1] + * copy_message_sync(chat_id, # <<<<<<<<<<<<<< + * from_chat_id, + * message_id, + */ + __pyx_t_22 = PyTuple_New(3); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 98, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_GIVEREF(__pyx_t_6); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_22, 0, __pyx_t_6)) __PYX_ERR(0, 98, __pyx_L13_error); + __Pyx_GIVEREF(__pyx_t_4); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_22, 1, __pyx_t_4)) __PYX_ERR(0, 98, __pyx_L13_error); + __Pyx_GIVEREF(__pyx_t_14); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_22, 2, __pyx_t_14)) __PYX_ERR(0, 98, __pyx_L13_error); + __pyx_t_6 = 0; + __pyx_t_4 = 0; + __pyx_t_14 = 0; + + /* "cython_code/send_ads.pyx":101 + * from_chat_id, + * message_id, + * caption=caption, # <<<<<<<<<<<<<< + * reply_markup=reply_markup) + * ads_data["done_count"] += 1 + */ + __pyx_t_14 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 101, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_14); + if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_caption, __pyx_v_caption) < 0) __PYX_ERR(0, 101, __pyx_L13_error) + + /* "cython_code/send_ads.pyx":102 + * message_id, + * caption=caption, + * reply_markup=reply_markup) # <<<<<<<<<<<<<< + * ads_data["done_count"] += 1 + * except Exception as err: + */ + if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_reply_markup, __pyx_v_reply_markup) < 0) __PYX_ERR(0, 101, __pyx_L13_error) + + /* "cython_code/send_ads.pyx":98 + * try: + * chat_id = user[1] + * copy_message_sync(chat_id, # <<<<<<<<<<<<<< + * from_chat_id, + * message_id, + */ + __pyx_t_4 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_t_22, __pyx_t_14); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 98, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "cython_code/send_ads.pyx":103 + * caption=caption, + * reply_markup=reply_markup) + * ads_data["done_count"] += 1 # <<<<<<<<<<<<<< + * except Exception as err: + * logging.error(err) + */ + __Pyx_INCREF(__pyx_n_u_done_count); + __pyx_t_23 = __pyx_n_u_done_count; + __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ads_data, __pyx_t_23); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 103, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_14 = __Pyx_PyInt_AddObjC(__pyx_t_4, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 103, __pyx_L13_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely((PyObject_SetItem(__pyx_v_ads_data, __pyx_t_23, __pyx_t_14) < 0))) __PYX_ERR(0, 103, __pyx_L13_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; + + /* "cython_code/send_ads.pyx":96 + * logging.info(f'Sending ads to users {start_index} - {end_index} (Total: {len(users_batch)})') + * for user in users_batch: + * try: # <<<<<<<<<<<<<< + * chat_id = user[1] + * copy_message_sync(chat_id, + */ + } + __Pyx_XDECREF(__pyx_t_19); __pyx_t_19 = 0; + __Pyx_XDECREF(__pyx_t_20); __pyx_t_20 = 0; + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + goto __pyx_L20_try_end; + __pyx_L13_error:; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_XDECREF(__pyx_t_23); __pyx_t_23 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "cython_code/send_ads.pyx":104 + * reply_markup=reply_markup) + * ads_data["done_count"] += 1 + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + * ads_data["fail_count"] += 1 + */ + __pyx_t_10 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); + if (__pyx_t_10) { + __Pyx_AddTraceback("cython_code.send_ads.send_ads", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_14, &__pyx_t_4, &__pyx_t_22) < 0) __PYX_ERR(0, 104, __pyx_L15_except_error) + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_22); + __Pyx_INCREF(__pyx_t_4); + __pyx_v_err = __pyx_t_4; + /*try:*/ { + + /* "cython_code/send_ads.pyx":105 + * ads_data["done_count"] += 1 + * except Exception as err: + * logging.error(err) # <<<<<<<<<<<<<< + * ads_data["fail_count"] += 1 + * + */ + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_logging); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 105, __pyx_L26_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_24 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_error); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 105, __pyx_L26_error) + __Pyx_GOTREF(__pyx_t_24); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_24))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_24); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_24); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_24, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_v_err}; + __pyx_t_13 = __Pyx_PyObject_FastCall(__pyx_t_24, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 105, __pyx_L26_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; + } + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + + /* "cython_code/send_ads.pyx":106 + * except Exception as err: + * logging.error(err) + * ads_data["fail_count"] += 1 # <<<<<<<<<<<<<< + * + * if end_index < total_users: + */ + __Pyx_INCREF(__pyx_n_u_fail_count); + __pyx_t_23 = __pyx_n_u_fail_count; + __pyx_t_13 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ads_data, __pyx_t_23); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 106, __pyx_L26_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_24 = __Pyx_PyInt_AddObjC(__pyx_t_13, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 106, __pyx_L26_error) + __Pyx_GOTREF(__pyx_t_24); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely((PyObject_SetItem(__pyx_v_ads_data, __pyx_t_23, __pyx_t_24) < 0))) __PYX_ERR(0, 106, __pyx_L26_error) + __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; + __Pyx_DECREF(__pyx_t_23); __pyx_t_23 = 0; + } + + /* "cython_code/send_ads.pyx":104 + * reply_markup=reply_markup) + * ads_data["done_count"] += 1 + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + * ads_data["fail_count"] += 1 + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + goto __pyx_L27; + } + __pyx_L26_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_27 = 0; __pyx_t_28 = 0; __pyx_t_29 = 0; __pyx_t_30 = 0; __pyx_t_31 = 0; __pyx_t_32 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_23); __pyx_t_23 = 0; + __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_30, &__pyx_t_31, &__pyx_t_32); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_27, &__pyx_t_28, &__pyx_t_29) < 0)) __Pyx_ErrFetch(&__pyx_t_27, &__pyx_t_28, &__pyx_t_29); + __Pyx_XGOTREF(__pyx_t_27); + __Pyx_XGOTREF(__pyx_t_28); + __Pyx_XGOTREF(__pyx_t_29); + __Pyx_XGOTREF(__pyx_t_30); + __Pyx_XGOTREF(__pyx_t_31); + __Pyx_XGOTREF(__pyx_t_32); + __pyx_t_10 = __pyx_lineno; __pyx_t_25 = __pyx_clineno; __pyx_t_26 = __pyx_filename; + { + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_30); + __Pyx_XGIVEREF(__pyx_t_31); + __Pyx_XGIVEREF(__pyx_t_32); + __Pyx_ExceptionReset(__pyx_t_30, __pyx_t_31, __pyx_t_32); + } + __Pyx_XGIVEREF(__pyx_t_27); + __Pyx_XGIVEREF(__pyx_t_28); + __Pyx_XGIVEREF(__pyx_t_29); + __Pyx_ErrRestore(__pyx_t_27, __pyx_t_28, __pyx_t_29); + __pyx_t_27 = 0; __pyx_t_28 = 0; __pyx_t_29 = 0; __pyx_t_30 = 0; __pyx_t_31 = 0; __pyx_t_32 = 0; + __pyx_lineno = __pyx_t_10; __pyx_clineno = __pyx_t_25; __pyx_filename = __pyx_t_26; + goto __pyx_L15_except_error; + } + __pyx_L27:; + } + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + goto __pyx_L14_exception_handled; + } + goto __pyx_L15_except_error; + + /* "cython_code/send_ads.pyx":96 + * logging.info(f'Sending ads to users {start_index} - {end_index} (Total: {len(users_batch)})') + * for user in users_batch: + * try: # <<<<<<<<<<<<<< + * chat_id = user[1] + * copy_message_sync(chat_id, + */ + __pyx_L15_except_error:; + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_XGIVEREF(__pyx_t_20); + __Pyx_XGIVEREF(__pyx_t_21); + __Pyx_ExceptionReset(__pyx_t_19, __pyx_t_20, __pyx_t_21); + goto __pyx_L3_error; + __pyx_L14_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_XGIVEREF(__pyx_t_20); + __Pyx_XGIVEREF(__pyx_t_21); + __Pyx_ExceptionReset(__pyx_t_19, __pyx_t_20, __pyx_t_21); + __pyx_L20_try_end:; + } + + /* "cython_code/send_ads.pyx":95 + * if users_batch: + * logging.info(f'Sending ads to users {start_index} - {end_index} (Total: {len(users_batch)})') + * for user in users_batch: # <<<<<<<<<<<<<< + * try: + * chat_id = user[1] + */ + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":108 + * ads_data["fail_count"] += 1 + * + * if end_index < total_users: # <<<<<<<<<<<<<< + * time.sleep(1) + * end_time = time.time() + */ + __pyx_t_9 = (__pyx_v_end_index < __pyx_v_total_users); + if (__pyx_t_9) { + + /* "cython_code/send_ads.pyx":109 + * + * if end_index < total_users: + * time.sleep(1) # <<<<<<<<<<<<<< + * end_time = time.time() + * total_time = end_time - start_time + */ + __Pyx_GetModuleGlobalName(__pyx_t_22, __pyx_n_s_time); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 109, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_22); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_22, __pyx_n_s_sleep); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 109, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + __pyx_t_22 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_22)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_22); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_22, __pyx_int_1}; + __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 109, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":110 + * if end_index < total_users: + * time.sleep(1) + * end_time = time.time() # <<<<<<<<<<<<<< + * total_time = end_time - start_time + * per_time = ads_data["per_time"] + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 110, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_22 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 110, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_22))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_22); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_22); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_22, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_4, NULL}; + __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_22, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 110, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + } + __pyx_t_8 = __pyx_PyFloat_AsFloat(__pyx_t_5); if (unlikely((__pyx_t_8 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 110, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_end_time = __pyx_t_8; + + /* "cython_code/send_ads.pyx":111 + * time.sleep(1) + * end_time = time.time() + * total_time = end_time - start_time # <<<<<<<<<<<<<< + * per_time = ads_data["per_time"] + * if per_time < total_time: + */ + __pyx_v_total_time = (__pyx_v_end_time - __pyx_v_start_time); + + /* "cython_code/send_ads.pyx":112 + * end_time = time.time() + * total_time = end_time - start_time + * per_time = ads_data["per_time"] # <<<<<<<<<<<<<< + * if per_time < total_time: + * ads_data["per_time"] = per_time + */ + __pyx_t_5 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ads_data, __pyx_n_u_per_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 112, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_8 = __pyx_PyFloat_AsFloat(__pyx_t_5); if (unlikely((__pyx_t_8 == (float)-1) && PyErr_Occurred())) __PYX_ERR(0, 112, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_per_time = __pyx_t_8; + + /* "cython_code/send_ads.pyx":113 + * total_time = end_time - start_time + * per_time = ads_data["per_time"] + * if per_time < total_time: # <<<<<<<<<<<<<< + * ads_data["per_time"] = per_time + * ads_data['start'] = end_index + */ + __pyx_t_9 = (__pyx_v_per_time < __pyx_v_total_time); + if (__pyx_t_9) { + + /* "cython_code/send_ads.pyx":114 + * per_time = ads_data["per_time"] + * if per_time < total_time: + * ads_data["per_time"] = per_time # <<<<<<<<<<<<<< + * ads_data['start'] = end_index + * file_db.add_data(ads_data, key='ads') + */ + __pyx_t_5 = PyFloat_FromDouble(__pyx_v_per_time); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 114, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + if (unlikely((PyObject_SetItem(__pyx_v_ads_data, __pyx_n_u_per_time, __pyx_t_5) < 0))) __PYX_ERR(0, 114, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":113 + * total_time = end_time - start_time + * per_time = ads_data["per_time"] + * if per_time < total_time: # <<<<<<<<<<<<<< + * ads_data["per_time"] = per_time + * ads_data['start'] = end_index + */ + } + + /* "cython_code/send_ads.pyx":115 + * if per_time < total_time: + * ads_data["per_time"] = per_time + * ads_data['start'] = end_index # <<<<<<<<<<<<<< + * file_db.add_data(ads_data, key='ads') + * return send_ads() + */ + __pyx_t_5 = __Pyx_PyInt_From_int(__pyx_v_end_index); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 115, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + if (unlikely((PyObject_SetItem(__pyx_v_ads_data, __pyx_n_u_start, __pyx_t_5) < 0))) __PYX_ERR(0, 115, __pyx_L3_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":116 + * ads_data["per_time"] = per_time + * ads_data['start'] = end_index + * file_db.add_data(ads_data, key='ads') # <<<<<<<<<<<<<< + * return send_ads() + * else: + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_file_db); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 116, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_22 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_add_data); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 116, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = PyTuple_New(1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 116, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_v_ads_data); + __Pyx_GIVEREF(__pyx_v_ads_data); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_v_ads_data)) __PYX_ERR(0, 116, __pyx_L3_error); + __pyx_t_4 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 116, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_key, __pyx_n_u_ads) < 0) __PYX_ERR(0, 116, __pyx_L3_error) + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_22, __pyx_t_5, __pyx_t_4); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 116, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "cython_code/send_ads.pyx":117 + * ads_data['start'] = end_index + * file_db.add_data(ads_data, key='ads') + * return send_ads() # <<<<<<<<<<<<<< + * else: + * file_db.add_data(False, key='ads') + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_send_ads); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 117, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL}; + __pyx_t_14 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 117, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __pyx_r = __pyx_t_14; + __pyx_t_14 = 0; + goto __pyx_L7_try_return; + + /* "cython_code/send_ads.pyx":108 + * ads_data["fail_count"] += 1 + * + * if end_index < total_users: # <<<<<<<<<<<<<< + * time.sleep(1) + * end_time = time.time() + */ + } + + /* "cython_code/send_ads.pyx":119 + * return send_ads() + * else: + * file_db.add_data(False, key='ads') # <<<<<<<<<<<<<< + * summary_message = ( + * f" Advertisement Sending Completed\n\n" + */ + /*else*/ { + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_file_db); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 119, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_add_data); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 119, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 119, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_14); + if (PyDict_SetItem(__pyx_t_14, __pyx_n_s_key, __pyx_n_u_ads) < 0) __PYX_ERR(0, 119, __pyx_L3_error) + __pyx_t_5 = __Pyx_PyObject_Call(__pyx_t_4, __pyx_tuple__3, __pyx_t_14); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 119, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + + /* "cython_code/send_ads.pyx":121 + * file_db.add_data(False, key='ads') + * summary_message = ( + * f" Advertisement Sending Completed\n\n" # <<<<<<<<<<<<<< + * f" Total Users: {total_users}\n" + * f" Sent: {ads_data['done_count']}\n" + */ + __pyx_t_5 = PyTuple_New(10); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 121, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_15 = 0; + __pyx_t_16 = 127; + __Pyx_INCREF(__pyx_kp_u_Advertisement_Sending_Completed); + __pyx_t_16 = (1114111 > __pyx_t_16) ? 1114111 : __pyx_t_16; + __pyx_t_15 += 50; + __Pyx_GIVEREF(__pyx_kp_u_Advertisement_Sending_Completed); + PyTuple_SET_ITEM(__pyx_t_5, 0, __pyx_kp_u_Advertisement_Sending_Completed); + + /* "cython_code/send_ads.pyx":122 + * summary_message = ( + * f" Advertisement Sending Completed\n\n" + * f" Total Users: {total_users}\n" # <<<<<<<<<<<<<< + * f" Sent: {ads_data['done_count']}\n" + * f" Failed: {ads_data['fail_count']}\n" + */ + __pyx_t_14 = __Pyx_PyUnicode_From_int(__pyx_v_total_users, 0, ' ', 'd'); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 122, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_5, 1, __pyx_t_14); + __pyx_t_14 = 0; + __Pyx_INCREF(__pyx_kp_u_Sent); + __pyx_t_16 = (65535 > __pyx_t_16) ? 65535 : __pyx_t_16; + __pyx_t_15 += 10; + __Pyx_GIVEREF(__pyx_kp_u_Sent); + PyTuple_SET_ITEM(__pyx_t_5, 2, __pyx_kp_u_Sent); + + /* "cython_code/send_ads.pyx":123 + * f" Advertisement Sending Completed\n\n" + * f" Total Users: {total_users}\n" + * f" Sent: {ads_data['done_count']}\n" # <<<<<<<<<<<<<< + * f" Failed: {ads_data['fail_count']}\n" + * f" Start Time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(ads_data['start-time']))}\n" + */ + __pyx_t_14 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ads_data, __pyx_n_u_done_count); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 123, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_t_14, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 123, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_16 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_16) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_16; + __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 3, __pyx_t_4); + __pyx_t_4 = 0; + __Pyx_INCREF(__pyx_kp_u_Failed); + __pyx_t_16 = (65535 > __pyx_t_16) ? 65535 : __pyx_t_16; + __pyx_t_15 += 12; + __Pyx_GIVEREF(__pyx_kp_u_Failed); + PyTuple_SET_ITEM(__pyx_t_5, 4, __pyx_kp_u_Failed); + + /* "cython_code/send_ads.pyx":124 + * f" Total Users: {total_users}\n" + * f" Sent: {ads_data['done_count']}\n" + * f" Failed: {ads_data['fail_count']}\n" # <<<<<<<<<<<<<< + * f" Start Time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(ads_data['start-time']))}\n" + * f" End Time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))}" + */ + __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ads_data, __pyx_n_u_fail_count); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 124, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_14 = __Pyx_PyObject_FormatSimple(__pyx_t_4, __pyx_empty_unicode); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 124, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_16 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_14) > __pyx_t_16) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_14) : __pyx_t_16; + __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + PyTuple_SET_ITEM(__pyx_t_5, 5, __pyx_t_14); + __pyx_t_14 = 0; + __Pyx_INCREF(__pyx_kp_u_Start_Time); + __pyx_t_16 = (65535 > __pyx_t_16) ? 65535 : __pyx_t_16; + __pyx_t_15 += 15; + __Pyx_GIVEREF(__pyx_kp_u_Start_Time); + PyTuple_SET_ITEM(__pyx_t_5, 6, __pyx_kp_u_Start_Time); + + /* "cython_code/send_ads.pyx":125 + * f" Sent: {ads_data['done_count']}\n" + * f" Failed: {ads_data['fail_count']}\n" + * f" Start Time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(ads_data['start-time']))}\n" # <<<<<<<<<<<<<< + * f" End Time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))}" + * ) + */ + __Pyx_GetModuleGlobalName(__pyx_t_4, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 125, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_22 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_strftime); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 125, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_24, __pyx_n_s_time); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 125, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_24); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_24, __pyx_n_s_localtime); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 125, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; + __pyx_t_24 = __Pyx_PyObject_Dict_GetItem(__pyx_v_ads_data, __pyx_kp_u_start_time); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 125, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_24); + __pyx_t_6 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_6, __pyx_t_24}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_13, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 125, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } + __pyx_t_13 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_22))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_22); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_22); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_22, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[3] = {__pyx_t_13, __pyx_kp_u_Y_m_d_H_M_S, __pyx_t_4}; + __pyx_t_14 = __Pyx_PyObject_FastCall(__pyx_t_22, __pyx_callargs+1-__pyx_t_7, 2+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 125, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + } + __pyx_t_22 = __Pyx_PyObject_FormatSimple(__pyx_t_14, __pyx_empty_unicode); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 125, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_16 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_22) > __pyx_t_16) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_22) : __pyx_t_16; + __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_22); + __Pyx_GIVEREF(__pyx_t_22); + PyTuple_SET_ITEM(__pyx_t_5, 7, __pyx_t_22); + __pyx_t_22 = 0; + __Pyx_INCREF(__pyx_kp_u_End_Time); + __pyx_t_16 = (1114111 > __pyx_t_16) ? 1114111 : __pyx_t_16; + __pyx_t_15 += 13; + __Pyx_GIVEREF(__pyx_kp_u_End_Time); + PyTuple_SET_ITEM(__pyx_t_5, 8, __pyx_kp_u_End_Time); + + /* "cython_code/send_ads.pyx":126 + * f" Failed: {ads_data['fail_count']}\n" + * f" Start Time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(ads_data['start-time']))}\n" + * f" End Time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))}" # <<<<<<<<<<<<<< + * ) + * send_message_sync(from_chat_id, summary_message) + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_time); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 126, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_strftime); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 126, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_time); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 126, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_24 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_localtime); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 126, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_24); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 126, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_33 = __Pyx_PyObject_GetAttrStr(__pyx_t_6, __pyx_n_s_time); if (unlikely(!__pyx_t_33)) __PYX_ERR(0, 126, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_33); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_6 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_33))) { + __pyx_t_6 = PyMethod_GET_SELF(__pyx_t_33); + if (likely(__pyx_t_6)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_33); + __Pyx_INCREF(__pyx_t_6); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_33, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_6, NULL}; + __pyx_t_13 = __Pyx_PyObject_FastCall(__pyx_t_33, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 126, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_33); __pyx_t_33 = 0; + } + __pyx_t_33 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_24))) { + __pyx_t_33 = PyMethod_GET_SELF(__pyx_t_24); + if (likely(__pyx_t_33)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_24); + __Pyx_INCREF(__pyx_t_33); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_24, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_33, __pyx_t_13}; + __pyx_t_14 = __Pyx_PyObject_FastCall(__pyx_t_24, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_33); __pyx_t_33 = 0; + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 126, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; + } + __pyx_t_24 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_24 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_24)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_24); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[3] = {__pyx_t_24, __pyx_kp_u_Y_m_d_H_M_S, __pyx_t_14}; + __pyx_t_22 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_7, 2+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 126, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __pyx_t_4 = __Pyx_PyObject_FormatSimple(__pyx_t_22, __pyx_empty_unicode); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 126, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + __pyx_t_16 = (__Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) > __pyx_t_16) ? __Pyx_PyUnicode_MAX_CHAR_VALUE(__pyx_t_4) : __pyx_t_16; + __pyx_t_15 += __Pyx_PyUnicode_GET_LENGTH(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + PyTuple_SET_ITEM(__pyx_t_5, 9, __pyx_t_4); + __pyx_t_4 = 0; + + /* "cython_code/send_ads.pyx":121 + * file_db.add_data(False, key='ads') + * summary_message = ( + * f" Advertisement Sending Completed\n\n" # <<<<<<<<<<<<<< + * f" Total Users: {total_users}\n" + * f" Sent: {ads_data['done_count']}\n" + */ + __pyx_t_4 = __Pyx_PyUnicode_Join(__pyx_t_5, 10, __pyx_t_15, __pyx_t_16); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 121, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_v_summary_message = ((PyObject*)__pyx_t_4); + __pyx_t_4 = 0; + + /* "cython_code/send_ads.pyx":128 + * f" End Time: {time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))}" + * ) + * send_message_sync(from_chat_id, summary_message) # <<<<<<<<<<<<<< + * elif users_batch is None: + * db.reconnect() + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_send_message_sync); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 128, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_22 = __Pyx_PyInt_From_int(__pyx_v_from_chat_id); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 128, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_22); + __pyx_t_14 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[3] = {__pyx_t_14, __pyx_t_22, __pyx_v_summary_message}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 2+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 128, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + + /* "cython_code/send_ads.pyx":93 + * + * users_batch = my_db.select_users_by_id(start_index, end_index) + * if users_batch: # <<<<<<<<<<<<<< + * logging.info(f'Sending ads to users {start_index} - {end_index} (Total: {len(users_batch)})') + * for user in users_batch: + */ + goto __pyx_L10; + } + + /* "cython_code/send_ads.pyx":129 + * ) + * send_message_sync(from_chat_id, summary_message) + * elif users_batch is None: # <<<<<<<<<<<<<< + * db.reconnect() + * time.sleep(2) + */ + __pyx_t_9 = (__pyx_v_users_batch == Py_None); + if (__pyx_t_9) { + + /* "cython_code/send_ads.pyx":130 + * send_message_sync(from_chat_id, summary_message) + * elif users_batch is None: + * db.reconnect() # <<<<<<<<<<<<<< + * time.sleep(2) + * else: + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_db); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 130, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_22 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_reconnect); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 130, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_22); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_22))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_22); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_22); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_22, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_22, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 130, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "cython_code/send_ads.pyx":131 + * elif users_batch is None: + * db.reconnect() + * time.sleep(2) # <<<<<<<<<<<<<< + * else: + * return + */ + __Pyx_GetModuleGlobalName(__pyx_t_22, __pyx_n_s_time); if (unlikely(!__pyx_t_22)) __PYX_ERR(0, 131, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_22); + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_t_22, __pyx_n_s_sleep); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 131, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_22); __pyx_t_22 = 0; + __pyx_t_22 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_5))) { + __pyx_t_22 = PyMethod_GET_SELF(__pyx_t_5); + if (likely(__pyx_t_22)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_5); + __Pyx_INCREF(__pyx_t_22); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_5, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_22, __pyx_int_2}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_5, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 131, __pyx_L3_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "cython_code/send_ads.pyx":129 + * ) + * send_message_sync(from_chat_id, summary_message) + * elif users_batch is None: # <<<<<<<<<<<<<< + * db.reconnect() + * time.sleep(2) + */ + goto __pyx_L10; + } + + /* "cython_code/send_ads.pyx":133 + * time.sleep(2) + * else: + * return # <<<<<<<<<<<<<< + * else: + * return + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L7_try_return; + } + __pyx_L10:; + + /* "cython_code/send_ads.pyx":83 + * start_time = time.time() + * ads_data = file_db.reading_db()['ads'] + * if ads_data: # <<<<<<<<<<<<<< + * start_index = ads_data['start'] + * from_chat_id = ads_data['from_chat_id'] + */ + goto __pyx_L9; + } + + /* "cython_code/send_ads.pyx":135 + * return + * else: + * return # <<<<<<<<<<<<<< + * except Exception as err: + * logging.error(err) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L7_try_return; + } + __pyx_L9:; + + /* "cython_code/send_ads.pyx":80 + * reply_markup = None + * + * try: # <<<<<<<<<<<<<< + * start_time = time.time() + * ads_data = file_db.reading_db()['ads'] + */ + } + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L8_try_end; + __pyx_L3_error:; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_XDECREF(__pyx_t_23); __pyx_t_23 = 0; + __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; + __Pyx_XDECREF(__pyx_t_33); __pyx_t_33 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "cython_code/send_ads.pyx":136 + * else: + * return + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + */ + __pyx_t_25 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); + if (__pyx_t_25) { + __Pyx_AddTraceback("cython_code.send_ads.send_ads", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_5, &__pyx_t_22) < 0) __PYX_ERR(0, 136, __pyx_L5_except_error) + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_22); + __Pyx_INCREF(__pyx_t_5); + __Pyx_XDECREF_SET(__pyx_v_err, __pyx_t_5); + /*try:*/ { + + /* "cython_code/send_ads.pyx":137 + * return + * except Exception as err: + * logging.error(err) # <<<<<<<<<<<<<< + */ + __Pyx_GetModuleGlobalName(__pyx_t_24, __pyx_n_s_logging); if (unlikely(!__pyx_t_24)) __PYX_ERR(0, 137, __pyx_L40_error) + __Pyx_GOTREF(__pyx_t_24); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_24, __pyx_n_s_error); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 137, __pyx_L40_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_24); __pyx_t_24 = 0; + __pyx_t_24 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_24 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_24)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_24); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_24, __pyx_v_err}; + __pyx_t_14 = __Pyx_PyObject_FastCall(__pyx_t_13, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; + if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 137, __pyx_L40_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } + + /* "cython_code/send_ads.pyx":136 + * else: + * return + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + goto __pyx_L41; + } + __pyx_L40_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __pyx_t_21 = 0; __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_32 = 0; __pyx_t_31 = 0; __pyx_t_30 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_23); __pyx_t_23 = 0; + __Pyx_XDECREF(__pyx_t_24); __pyx_t_24 = 0; + __Pyx_XDECREF(__pyx_t_33); __pyx_t_33 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_32, &__pyx_t_31, &__pyx_t_30); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_21, &__pyx_t_20, &__pyx_t_19) < 0)) __Pyx_ErrFetch(&__pyx_t_21, &__pyx_t_20, &__pyx_t_19); + __Pyx_XGOTREF(__pyx_t_21); + __Pyx_XGOTREF(__pyx_t_20); + __Pyx_XGOTREF(__pyx_t_19); + __Pyx_XGOTREF(__pyx_t_32); + __Pyx_XGOTREF(__pyx_t_31); + __Pyx_XGOTREF(__pyx_t_30); + __pyx_t_25 = __pyx_lineno; __pyx_t_10 = __pyx_clineno; __pyx_t_34 = __pyx_filename; + { + __Pyx_DECREF(__pyx_v_err); __pyx_v_err = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_32); + __Pyx_XGIVEREF(__pyx_t_31); + __Pyx_XGIVEREF(__pyx_t_30); + __Pyx_ExceptionReset(__pyx_t_32, __pyx_t_31, __pyx_t_30); + } + __Pyx_XGIVEREF(__pyx_t_21); + __Pyx_XGIVEREF(__pyx_t_20); + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_ErrRestore(__pyx_t_21, __pyx_t_20, __pyx_t_19); + __pyx_t_21 = 0; __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_32 = 0; __pyx_t_31 = 0; __pyx_t_30 = 0; + __pyx_lineno = __pyx_t_25; __pyx_clineno = __pyx_t_10; __pyx_filename = __pyx_t_34; + goto __pyx_L5_except_error; + } + __pyx_L41:; + } + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + goto __pyx_L4_exception_handled; + } + goto __pyx_L5_except_error; + + /* "cython_code/send_ads.pyx":80 + * reply_markup = None + * + * try: # <<<<<<<<<<<<<< + * start_time = time.time() + * ads_data = file_db.reading_db()['ads'] + */ + __pyx_L5_except_error:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L7_try_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; + __pyx_L4_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + __pyx_L8_try_end:; + } + + /* "cython_code/send_ads.pyx":73 + * return response.json() + * + * def send_ads(): # <<<<<<<<<<<<<< + * cdef float start_time, end_time, total_time, per_time + * cdef int start_index, end_index, total_users, chat_id, from_chat_id, message_id + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_22); + __Pyx_XDECREF(__pyx_t_23); + __Pyx_XDECREF(__pyx_t_24); + __Pyx_XDECREF(__pyx_t_33); + __Pyx_AddTraceback("cython_code.send_ads.send_ads", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v_caption); + __Pyx_XDECREF(__pyx_v_users_batch); + __Pyx_XDECREF(__pyx_v_reply_markup); + __Pyx_XDECREF(__pyx_v_ads_data); + __Pyx_XDECREF(__pyx_v_user); + __Pyx_XDECREF(__pyx_v_err); + __Pyx_XDECREF(__pyx_v_summary_message); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":1 + * def __pyx_unpickle_MyDatabase(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_8send_ads_7__pyx_unpickle_MyDatabase(PyObject *__pyx_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +static PyMethodDef __pyx_mdef_11cython_code_8send_ads_7__pyx_unpickle_MyDatabase = {"__pyx_unpickle_MyDatabase", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_8send_ads_7__pyx_unpickle_MyDatabase, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}; +static PyObject *__pyx_pw_11cython_code_8send_ads_7__pyx_unpickle_MyDatabase(PyObject *__pyx_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + PyObject *__pyx_v___pyx_type = 0; + long __pyx_v___pyx_checksum; + PyObject *__pyx_v___pyx_state = 0; + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[3] = {0,0,0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__pyx_unpickle_MyDatabase (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_pyx_type,&__pyx_n_s_pyx_checksum,&__pyx_n_s_pyx_state,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_type)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_checksum)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[1]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_MyDatabase", 1, 3, 3, 1); __PYX_ERR(1, 1, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_pyx_state)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[2]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_MyDatabase", 1, 3, 3, 2); __PYX_ERR(1, 1, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__pyx_unpickle_MyDatabase") < 0)) __PYX_ERR(1, 1, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 3)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); + } + __pyx_v___pyx_type = values[0]; + __pyx_v___pyx_checksum = __Pyx_PyInt_As_long(values[1]); if (unlikely((__pyx_v___pyx_checksum == (long)-1) && PyErr_Occurred())) __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_v___pyx_state = values[2]; + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__pyx_unpickle_MyDatabase", 1, 3, 3, __pyx_nargs); __PYX_ERR(1, 1, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.send_ads.__pyx_unpickle_MyDatabase", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_11cython_code_8send_ads_6__pyx_unpickle_MyDatabase(__pyx_self, __pyx_v___pyx_type, __pyx_v___pyx_checksum, __pyx_v___pyx_state); + + /* function exit code */ + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_8send_ads_6__pyx_unpickle_MyDatabase(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v___pyx_type, long __pyx_v___pyx_checksum, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_v___pyx_PickleError = 0; + PyObject *__pyx_v___pyx_result = 0; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + unsigned int __pyx_t_5; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__pyx_unpickle_MyDatabase", 1); + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum not in (0xc59a5d0, 0xee418c5, 0x43b1ea3): # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xc59a5d0, 0xee418c5, 0x43b1ea3) = (connection, cursor, database, host, password, user))" % __pyx_checksum + */ + __pyx_t_1 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = (__Pyx_PySequence_ContainsTF(__pyx_t_1, __pyx_tuple__4, Py_NE)); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "(tree fragment)":5 + * cdef object __pyx_result + * if __pyx_checksum not in (0xc59a5d0, 0xee418c5, 0x43b1ea3): + * from pickle import PickleError as __pyx_PickleError # <<<<<<<<<<<<<< + * raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xc59a5d0, 0xee418c5, 0x43b1ea3) = (connection, cursor, database, host, password, user))" % __pyx_checksum + * __pyx_result = MyDatabase.__new__(__pyx_type) + */ + __pyx_t_1 = PyList_New(1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_n_s_PickleError); + __Pyx_GIVEREF(__pyx_n_s_PickleError); + if (__Pyx_PyList_SET_ITEM(__pyx_t_1, 0, __pyx_n_s_PickleError)) __PYX_ERR(1, 5, __pyx_L1_error); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_pickle, __pyx_t_1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_PickleError); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_1); + __pyx_v___pyx_PickleError = __pyx_t_1; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "(tree fragment)":6 + * if __pyx_checksum not in (0xc59a5d0, 0xee418c5, 0x43b1ea3): + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xc59a5d0, 0xee418c5, 0x43b1ea3) = (connection, cursor, database, host, password, user))" % __pyx_checksum # <<<<<<<<<<<<<< + * __pyx_result = MyDatabase.__new__(__pyx_type) + * if __pyx_state is not None: + */ + __pyx_t_3 = __Pyx_PyInt_From_long(__pyx_v___pyx_checksum); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_1 = __Pyx_PyString_Format(__pyx_kp_s_Incompatible_checksums_0x_x_vs_0, __pyx_t_3); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_Raise(__pyx_v___pyx_PickleError, __pyx_t_1, 0, 0); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __PYX_ERR(1, 6, __pyx_L1_error) + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum not in (0xc59a5d0, 0xee418c5, 0x43b1ea3): # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xc59a5d0, 0xee418c5, 0x43b1ea3) = (connection, cursor, database, host, password, user))" % __pyx_checksum + */ + } + + /* "(tree fragment)":7 + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xc59a5d0, 0xee418c5, 0x43b1ea3) = (connection, cursor, database, host, password, user))" % __pyx_checksum + * __pyx_result = MyDatabase.__new__(__pyx_type) # <<<<<<<<<<<<<< + * if __pyx_state is not None: + * __pyx_unpickle_MyDatabase__set_state( __pyx_result, __pyx_state) + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_ptype_11cython_code_8send_ads_MyDatabase), __pyx_n_s_new); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = NULL; + __pyx_t_5 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_5 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_v___pyx_type}; + __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_v___pyx_result = __pyx_t_1; + __pyx_t_1 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xc59a5d0, 0xee418c5, 0x43b1ea3) = (connection, cursor, database, host, password, user))" % __pyx_checksum + * __pyx_result = MyDatabase.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_MyDatabase__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + __pyx_t_2 = (__pyx_v___pyx_state != Py_None); + if (__pyx_t_2) { + + /* "(tree fragment)":9 + * __pyx_result = MyDatabase.__new__(__pyx_type) + * if __pyx_state is not None: + * __pyx_unpickle_MyDatabase__set_state( __pyx_result, __pyx_state) # <<<<<<<<<<<<<< + * return __pyx_result + * cdef __pyx_unpickle_MyDatabase__set_state(MyDatabase __pyx_result, tuple __pyx_state): + */ + if (!(likely(PyTuple_CheckExact(__pyx_v___pyx_state))||((__pyx_v___pyx_state) == Py_None) || __Pyx_RaiseUnexpectedTypeError("tuple", __pyx_v___pyx_state))) __PYX_ERR(1, 9, __pyx_L1_error) + __pyx_t_1 = __pyx_f_11cython_code_8send_ads___pyx_unpickle_MyDatabase__set_state(((struct __pyx_obj_11cython_code_8send_ads_MyDatabase *)__pyx_v___pyx_result), ((PyObject*)__pyx_v___pyx_state)); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":8 + * raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xc59a5d0, 0xee418c5, 0x43b1ea3) = (connection, cursor, database, host, password, user))" % __pyx_checksum + * __pyx_result = MyDatabase.__new__(__pyx_type) + * if __pyx_state is not None: # <<<<<<<<<<<<<< + * __pyx_unpickle_MyDatabase__set_state( __pyx_result, __pyx_state) + * return __pyx_result + */ + } + + /* "(tree fragment)":10 + * if __pyx_state is not None: + * __pyx_unpickle_MyDatabase__set_state( __pyx_result, __pyx_state) + * return __pyx_result # <<<<<<<<<<<<<< + * cdef __pyx_unpickle_MyDatabase__set_state(MyDatabase __pyx_result, tuple __pyx_state): + * __pyx_result.connection = __pyx_state[0]; __pyx_result.cursor = __pyx_state[1]; __pyx_result.database = __pyx_state[2]; __pyx_result.host = __pyx_state[3]; __pyx_result.password = __pyx_state[4]; __pyx_result.user = __pyx_state[5] + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_v___pyx_result); + __pyx_r = __pyx_v___pyx_result; + goto __pyx_L0; + + /* "(tree fragment)":1 + * def __pyx_unpickle_MyDatabase(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_AddTraceback("cython_code.send_ads.__pyx_unpickle_MyDatabase", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XDECREF(__pyx_v___pyx_PickleError); + __Pyx_XDECREF(__pyx_v___pyx_result); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +/* "(tree fragment)":11 + * __pyx_unpickle_MyDatabase__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_MyDatabase__set_state(MyDatabase __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.connection = __pyx_state[0]; __pyx_result.cursor = __pyx_state[1]; __pyx_result.database = __pyx_state[2]; __pyx_result.host = __pyx_state[3]; __pyx_result.password = __pyx_state[4]; __pyx_result.user = __pyx_state[5] + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): + */ + +static PyObject *__pyx_f_11cython_code_8send_ads___pyx_unpickle_MyDatabase__set_state(struct __pyx_obj_11cython_code_8send_ads_MyDatabase *__pyx_v___pyx_result, PyObject *__pyx_v___pyx_state) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + Py_ssize_t __pyx_t_3; + int __pyx_t_4; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + unsigned int __pyx_t_8; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__pyx_unpickle_MyDatabase__set_state", 1); + + /* "(tree fragment)":12 + * return __pyx_result + * cdef __pyx_unpickle_MyDatabase__set_state(MyDatabase __pyx_result, tuple __pyx_state): + * __pyx_result.connection = __pyx_state[0]; __pyx_result.cursor = __pyx_state[1]; __pyx_result.database = __pyx_state[2]; __pyx_result.host = __pyx_state[3]; __pyx_result.password = __pyx_state[4]; __pyx_result.user = __pyx_state[5] # <<<<<<<<<<<<<< + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[6]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 0, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->connection); + __Pyx_DECREF(__pyx_v___pyx_result->connection); + __pyx_v___pyx_result->connection = __pyx_t_1; + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->cursor); + __Pyx_DECREF(__pyx_v___pyx_result->cursor); + __pyx_v___pyx_result->cursor = __pyx_t_1; + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 2, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("unicode", __pyx_t_1))) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->database); + __Pyx_DECREF(__pyx_v___pyx_result->database); + __pyx_v___pyx_result->database = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 3, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("unicode", __pyx_t_1))) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->host); + __Pyx_DECREF(__pyx_v___pyx_result->host); + __pyx_v___pyx_result->host = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 4, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("unicode", __pyx_t_1))) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->password); + __Pyx_DECREF(__pyx_v___pyx_result->password); + __pyx_v___pyx_result->password = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 12, __pyx_L1_error) + } + __pyx_t_1 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 5, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (!(likely(PyUnicode_CheckExact(__pyx_t_1))||((__pyx_t_1) == Py_None) || __Pyx_RaiseUnexpectedTypeError("unicode", __pyx_t_1))) __PYX_ERR(1, 12, __pyx_L1_error) + __Pyx_GIVEREF(__pyx_t_1); + __Pyx_GOTREF(__pyx_v___pyx_result->user); + __Pyx_DECREF(__pyx_v___pyx_result->user); + __pyx_v___pyx_result->user = ((PyObject*)__pyx_t_1); + __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_MyDatabase__set_state(MyDatabase __pyx_result, tuple __pyx_state): + * __pyx_result.connection = __pyx_state[0]; __pyx_result.cursor = __pyx_state[1]; __pyx_result.database = __pyx_state[2]; __pyx_result.host = __pyx_state[3]; __pyx_result.password = __pyx_state[4]; __pyx_result.user = __pyx_state[5] + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[6]) + */ + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "object of type 'NoneType' has no len()"); + __PYX_ERR(1, 13, __pyx_L1_error) + } + __pyx_t_3 = __Pyx_PyTuple_GET_SIZE(__pyx_v___pyx_state); if (unlikely(__pyx_t_3 == ((Py_ssize_t)-1))) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_4 = (__pyx_t_3 > 6); + if (__pyx_t_4) { + } else { + __pyx_t_2 = __pyx_t_4; + goto __pyx_L4_bool_binop_done; + } + __pyx_t_4 = __Pyx_HasAttr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(__pyx_t_4 == ((int)-1))) __PYX_ERR(1, 13, __pyx_L1_error) + __pyx_t_2 = __pyx_t_4; + __pyx_L4_bool_binop_done:; + if (__pyx_t_2) { + + /* "(tree fragment)":14 + * __pyx_result.connection = __pyx_state[0]; __pyx_result.cursor = __pyx_state[1]; __pyx_result.database = __pyx_state[2]; __pyx_result.host = __pyx_state[3]; __pyx_result.password = __pyx_state[4]; __pyx_result.user = __pyx_state[5] + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): + * __pyx_result.__dict__.update(__pyx_state[6]) # <<<<<<<<<<<<<< + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(((PyObject *)__pyx_v___pyx_result), __pyx_n_s_dict); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_update); if (unlikely(!__pyx_t_6)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(__pyx_v___pyx_state == Py_None)) { + PyErr_SetString(PyExc_TypeError, "'NoneType' object is not subscriptable"); + __PYX_ERR(1, 14, __pyx_L1_error) + } + __pyx_t_5 = __Pyx_GetItemInt_Tuple(__pyx_v___pyx_state, 6, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_7 = NULL; + __pyx_t_8 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_7 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_7)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_7); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_8 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_7, __pyx_t_5}; + __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_8, 1+__pyx_t_8); + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(1, 14, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "(tree fragment)":13 + * cdef __pyx_unpickle_MyDatabase__set_state(MyDatabase __pyx_result, tuple __pyx_state): + * __pyx_result.connection = __pyx_state[0]; __pyx_result.cursor = __pyx_state[1]; __pyx_result.database = __pyx_state[2]; __pyx_result.host = __pyx_state[3]; __pyx_result.password = __pyx_state[4]; __pyx_result.user = __pyx_state[5] + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): # <<<<<<<<<<<<<< + * __pyx_result.__dict__.update(__pyx_state[6]) + */ + } + + /* "(tree fragment)":11 + * __pyx_unpickle_MyDatabase__set_state( __pyx_result, __pyx_state) + * return __pyx_result + * cdef __pyx_unpickle_MyDatabase__set_state(MyDatabase __pyx_result, tuple __pyx_state): # <<<<<<<<<<<<<< + * __pyx_result.connection = __pyx_state[0]; __pyx_result.cursor = __pyx_state[1]; __pyx_result.database = __pyx_state[2]; __pyx_result.host = __pyx_state[3]; __pyx_result.password = __pyx_state[4]; __pyx_result.user = __pyx_state[5] + * if len(__pyx_state) > 6 and hasattr(__pyx_result, '__dict__'): + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + __Pyx_AddTraceback("cython_code.send_ads.__pyx_unpickle_MyDatabase__set_state", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = 0; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_tp_new_11cython_code_8send_ads_MyDatabase(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + struct __pyx_obj_11cython_code_8send_ads_MyDatabase *p; + PyObject *o; + #if CYTHON_COMPILING_IN_LIMITED_API + allocfunc alloc_func = (allocfunc)PyType_GetSlot(t, Py_tp_alloc); + o = alloc_func(t, 0); + #else + if (likely(!__Pyx_PyType_HasFeature(t, Py_TPFLAGS_IS_ABSTRACT))) { + o = (*t->tp_alloc)(t, 0); + } else { + o = (PyObject *) PyBaseObject_Type.tp_new(t, __pyx_empty_tuple, 0); + } + if (unlikely(!o)) return 0; + #endif + p = ((struct __pyx_obj_11cython_code_8send_ads_MyDatabase *)o); + p->host = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->user = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->password = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->database = ((PyObject*)Py_None); Py_INCREF(Py_None); + p->connection = Py_None; Py_INCREF(Py_None); + p->cursor = Py_None; Py_INCREF(Py_None); + return o; +} + +static void __pyx_tp_dealloc_11cython_code_8send_ads_MyDatabase(PyObject *o) { + struct __pyx_obj_11cython_code_8send_ads_MyDatabase *p = (struct __pyx_obj_11cython_code_8send_ads_MyDatabase *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && !__Pyx_PyObject_GC_IsFinalized(o)) { + if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_11cython_code_8send_ads_MyDatabase) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->host); + Py_CLEAR(p->user); + Py_CLEAR(p->password); + Py_CLEAR(p->database); + Py_CLEAR(p->connection); + Py_CLEAR(p->cursor); + #if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY + (*Py_TYPE(o)->tp_free)(o); + #else + { + freefunc tp_free = (freefunc)PyType_GetSlot(Py_TYPE(o), Py_tp_free); + if (tp_free) tp_free(o); + } + #endif +} + +static int __pyx_tp_traverse_11cython_code_8send_ads_MyDatabase(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_11cython_code_8send_ads_MyDatabase *p = (struct __pyx_obj_11cython_code_8send_ads_MyDatabase *)o; + if (p->connection) { + e = (*v)(p->connection, a); if (e) return e; + } + if (p->cursor) { + e = (*v)(p->cursor, a); if (e) return e; + } + return 0; +} + +static int __pyx_tp_clear_11cython_code_8send_ads_MyDatabase(PyObject *o) { + PyObject* tmp; + struct __pyx_obj_11cython_code_8send_ads_MyDatabase *p = (struct __pyx_obj_11cython_code_8send_ads_MyDatabase *)o; + tmp = ((PyObject*)p->connection); + p->connection = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + tmp = ((PyObject*)p->cursor); + p->cursor = Py_None; Py_INCREF(Py_None); + Py_XDECREF(tmp); + return 0; +} + +static PyMethodDef __pyx_methods_11cython_code_8send_ads_MyDatabase[] = { + {"reconnect", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_8send_ads_10MyDatabase_3reconnect, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {"select_users_by_id", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_8send_ads_10MyDatabase_5select_users_by_id, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {"__reduce_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_8send_ads_10MyDatabase_7__reduce_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {"__setstate_cython__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_8send_ads_10MyDatabase_9__setstate_cython__, __Pyx_METH_FASTCALL|METH_KEYWORDS, 0}, + {0, 0, 0, 0} +}; +#if CYTHON_USE_TYPE_SPECS +static PyType_Slot __pyx_type_11cython_code_8send_ads_MyDatabase_slots[] = { + {Py_tp_dealloc, (void *)__pyx_tp_dealloc_11cython_code_8send_ads_MyDatabase}, + {Py_tp_traverse, (void *)__pyx_tp_traverse_11cython_code_8send_ads_MyDatabase}, + {Py_tp_clear, (void *)__pyx_tp_clear_11cython_code_8send_ads_MyDatabase}, + {Py_tp_methods, (void *)__pyx_methods_11cython_code_8send_ads_MyDatabase}, + {Py_tp_init, (void *)__pyx_pw_11cython_code_8send_ads_10MyDatabase_1__init__}, + {Py_tp_new, (void *)__pyx_tp_new_11cython_code_8send_ads_MyDatabase}, + {0, 0}, +}; +static PyType_Spec __pyx_type_11cython_code_8send_ads_MyDatabase_spec = { + "cython_code.send_ads.MyDatabase", + sizeof(struct __pyx_obj_11cython_code_8send_ads_MyDatabase), + 0, + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, + __pyx_type_11cython_code_8send_ads_MyDatabase_slots, +}; +#else + +static PyTypeObject __pyx_type_11cython_code_8send_ads_MyDatabase = { + PyVarObject_HEAD_INIT(0, 0) + "cython_code.send_ads.""MyDatabase", /*tp_name*/ + sizeof(struct __pyx_obj_11cython_code_8send_ads_MyDatabase), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_11cython_code_8send_ads_MyDatabase, /*tp_dealloc*/ + #if PY_VERSION_HEX < 0x030800b4 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 + 0, /*tp_vectorcall_offset*/ + #endif + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_BASETYPE|Py_TPFLAGS_HAVE_GC, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_11cython_code_8send_ads_MyDatabase, /*tp_traverse*/ + __pyx_tp_clear_11cython_code_8send_ads_MyDatabase, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + __pyx_methods_11cython_code_8send_ads_MyDatabase, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + #if !CYTHON_USE_TYPE_SPECS + 0, /*tp_dictoffset*/ + #endif + __pyx_pw_11cython_code_8send_ads_10MyDatabase_1__init__, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_11cython_code_8send_ads_MyDatabase, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + #if CYTHON_USE_TP_FINALIZE + 0, /*tp_finalize*/ + #else + NULL, /*tp_finalize*/ + #endif + #endif + #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) + 0, /*tp_vectorcall*/ + #endif + #if __PYX_NEED_TP_PRINT_SLOT == 1 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030C0000 + 0, /*tp_watched*/ + #endif + #if PY_VERSION_HEX >= 0x030d00A4 + 0, /*tp_versions_used*/ + #endif + #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 + 0, /*tp_pypy_flags*/ + #endif +}; +#endif + +static PyMethodDef __pyx_methods[] = { + {0, 0, 0, 0} +}; + +static int __pyx_import_star_set(PyObject *o, PyObject* py_name, char *name) { + static const char* internal_type_names[] = { + "MyDatabase", + "__pyx_ctuple_int", + "__pyx_ctuple_int__and_int", + "__pyx_ctuple_int__and_int__and_int", + "__pyx_ctuple_int__and_int__and_int_struct", + "__pyx_ctuple_int__and_int_struct", + "__pyx_ctuple_int_struct", + "__pyx_ctuple_long", + "__pyx_ctuple_long__and_long__and_long", + "__pyx_ctuple_long__and_long__and_long_struct", + "__pyx_ctuple_long_struct", + 0 + }; + const char** type_name = internal_type_names; + while (*type_name) { + if (__Pyx_StrEq(name, *type_name)) { + PyErr_Format(PyExc_TypeError, "Cannot overwrite C type %s", name); + goto bad; + } + type_name++; + } + if (0); + else if (__Pyx_StrEq(name, "my_db")) { + if (!(likely(((o) == Py_None) || likely(__Pyx_TypeTest(o, __pyx_ptype_11cython_code_8send_ads_MyDatabase))))) __PYX_ERR(0, 50, __pyx_L2_error); + Py_INCREF(o); + Py_DECREF((PyObject *)__pyx_v_11cython_code_8send_ads_my_db); + __pyx_v_11cython_code_8send_ads_my_db = ((struct __pyx_obj_11cython_code_8send_ads_MyDatabase *)o); + } + else { + if (PyObject_SetAttr(__pyx_m, py_name, o) < 0) goto bad; + } + return 0; + __pyx_L2_error:; + __Pyx_AddTraceback("cython_code.send_ads", __pyx_clineno, __pyx_lineno, __pyx_filename); + bad: + return -1; +} + +static int +__Pyx_import_all_from(PyObject *locals, PyObject *v) +{ + PyObject *all = PyObject_GetAttrString(v, "__all__"); + PyObject *dict, *name, *value; + int skip_leading_underscores = 0; + int pos, err; + if (all == NULL) { + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) + return -1; + PyErr_Clear(); + dict = PyObject_GetAttrString(v, "__dict__"); + if (dict == NULL) { + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) + return -1; + PyErr_SetString(PyExc_ImportError, + "from-import-* object has no __dict__ and no __all__"); + return -1; + } +#if PY_MAJOR_VERSION < 3 + all = PyObject_CallMethod(dict, (char *)"keys", NULL); +#else + all = PyMapping_Keys(dict); +#endif + Py_DECREF(dict); + if (all == NULL) + return -1; + skip_leading_underscores = 1; + } + for (pos = 0, err = 0; ; pos++) { + name = PySequence_GetItem(all, pos); + if (name == NULL) { + if (!PyErr_ExceptionMatches(PyExc_IndexError)) + err = -1; + else + PyErr_Clear(); + break; + } + if (skip_leading_underscores && +#if PY_MAJOR_VERSION < 3 + likely(PyString_Check(name)) && + PyString_AS_STRING(name)[0] == '_') +#else + likely(PyUnicode_Check(name)) && + likely(__Pyx_PyUnicode_GET_LENGTH(name)) && + __Pyx_PyUnicode_READ_CHAR(name, 0) == '_') +#endif + { + Py_DECREF(name); + continue; + } + value = PyObject_GetAttr(v, name); + if (value == NULL) + err = -1; + else if (PyDict_CheckExact(locals)) + err = PyDict_SetItem(locals, name, value); + else + err = PyObject_SetItem(locals, name, value); + Py_DECREF(name); + Py_XDECREF(value); + if (err != 0) + break; + } + Py_DECREF(all); + return err; +} +static int __pyx_import_star(PyObject* m) { + int i; + int ret = -1; + char* s; + PyObject *locals = 0; + PyObject *list = 0; +#if PY_MAJOR_VERSION >= 3 + PyObject *utf8_name = 0; +#endif + PyObject *name; + PyObject *item; + locals = PyDict_New(); if (!locals) goto bad; + if (__Pyx_import_all_from(locals, m) < 0) goto bad; + list = PyDict_Items(locals); if (!list) goto bad; + for(i=0; i= 3 + utf8_name = PyUnicode_AsUTF8String(name); + if (!utf8_name) goto bad; + s = PyBytes_AS_STRING(utf8_name); + if (__pyx_import_star_set(item, name, s) < 0) goto bad; + Py_DECREF(utf8_name); utf8_name = 0; +#else + s = PyString_AsString(name); + if (!s) goto bad; + if (__pyx_import_star_set(item, name, s) < 0) goto bad; +#endif + } + ret = 0; +bad: + Py_XDECREF(locals); + Py_XDECREF(list); +#if PY_MAJOR_VERSION >= 3 + Py_XDECREF(utf8_name); +#endif + return ret; +} + + +#ifndef CYTHON_SMALL_CODE +#if defined(__clang__) + #define CYTHON_SMALL_CODE +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) + #define CYTHON_SMALL_CODE __attribute__((cold)) +#else + #define CYTHON_SMALL_CODE +#endif +#endif +/* #### Code section: pystring_table ### */ + +static int __Pyx_CreateStringTabAndInitStrings(void) { + __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_kp_u_, __pyx_k_, sizeof(__pyx_k_), 0, 1, 0, 0}, + {&__pyx_kp_u_Advertisement_Sending_Completed, __pyx_k_Advertisement_Sending_Completed, sizeof(__pyx_k_Advertisement_Sending_Completed), 0, 1, 0, 0}, + {&__pyx_n_s_BOT_TOKEN, __pyx_k_BOT_TOKEN, sizeof(__pyx_k_BOT_TOKEN), 0, 0, 1, 1}, + {&__pyx_kp_u_End_Time, __pyx_k_End_Time, sizeof(__pyx_k_End_Time), 0, 1, 0, 0}, + {&__pyx_n_s_Error, __pyx_k_Error, sizeof(__pyx_k_Error), 0, 0, 1, 1}, + {&__pyx_kp_u_Failed, __pyx_k_Failed, sizeof(__pyx_k_Failed), 0, 1, 0, 0}, + {&__pyx_n_s_HOST, __pyx_k_HOST, sizeof(__pyx_k_HOST), 0, 0, 1, 1}, + {&__pyx_kp_s_Incompatible_checksums_0x_x_vs_0, __pyx_k_Incompatible_checksums_0x_x_vs_0, sizeof(__pyx_k_Incompatible_checksums_0x_x_vs_0), 0, 0, 1, 0}, + {&__pyx_n_s_MYSQL_DATABASE, __pyx_k_MYSQL_DATABASE, sizeof(__pyx_k_MYSQL_DATABASE), 0, 0, 1, 1}, + {&__pyx_n_s_MYSQL_PASSWORD, __pyx_k_MYSQL_PASSWORD, sizeof(__pyx_k_MYSQL_PASSWORD), 0, 0, 1, 1}, + {&__pyx_n_s_MYSQL_USER, __pyx_k_MYSQL_USER, sizeof(__pyx_k_MYSQL_USER), 0, 0, 1, 1}, + {&__pyx_n_s_MyDatabase, __pyx_k_MyDatabase, sizeof(__pyx_k_MyDatabase), 0, 0, 1, 1}, + {&__pyx_n_s_MyDatabase___reduce_cython, __pyx_k_MyDatabase___reduce_cython, sizeof(__pyx_k_MyDatabase___reduce_cython), 0, 0, 1, 1}, + {&__pyx_n_s_MyDatabase___setstate_cython, __pyx_k_MyDatabase___setstate_cython, sizeof(__pyx_k_MyDatabase___setstate_cython), 0, 0, 1, 1}, + {&__pyx_n_s_MyDatabase_reconnect, __pyx_k_MyDatabase_reconnect, sizeof(__pyx_k_MyDatabase_reconnect), 0, 0, 1, 1}, + {&__pyx_n_s_MyDatabase_select_users_by_id, __pyx_k_MyDatabase_select_users_by_id, sizeof(__pyx_k_MyDatabase_select_users_by_id), 0, 0, 1, 1}, + {&__pyx_n_s_PickleError, __pyx_k_PickleError, sizeof(__pyx_k_PickleError), 0, 0, 1, 1}, + {&__pyx_kp_u_SELECT_FROM_users_WHERE_id_s_AND, __pyx_k_SELECT_FROM_users_WHERE_id_s_AND, sizeof(__pyx_k_SELECT_FROM_users_WHERE_id_s_AND), 0, 1, 0, 0}, + {&__pyx_kp_u_Sending_ads_to_users, __pyx_k_Sending_ads_to_users, sizeof(__pyx_k_Sending_ads_to_users), 0, 1, 0, 0}, + {&__pyx_kp_u_Sent, __pyx_k_Sent, sizeof(__pyx_k_Sent), 0, 1, 0, 0}, + {&__pyx_kp_u_Start_Time, __pyx_k_Start_Time, sizeof(__pyx_k_Start_Time), 0, 1, 0, 0}, + {&__pyx_kp_u_Total, __pyx_k_Total, sizeof(__pyx_k_Total), 0, 1, 0, 0}, + {&__pyx_kp_u_Y_m_d_H_M_S, __pyx_k_Y_m_d_H_M_S, sizeof(__pyx_k_Y_m_d_H_M_S), 0, 1, 0, 0}, + {&__pyx_kp_u__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 1, 0, 0}, + {&__pyx_n_s__24, __pyx_k__24, sizeof(__pyx_k__24), 0, 0, 1, 1}, + {&__pyx_kp_u__5, __pyx_k__5, sizeof(__pyx_k__5), 0, 1, 0, 0}, + {&__pyx_n_s__6, __pyx_k__6, sizeof(__pyx_k__6), 0, 0, 1, 1}, + {&__pyx_n_s_add_data, __pyx_k_add_data, sizeof(__pyx_k_add_data), 0, 0, 1, 1}, + {&__pyx_n_u_ads, __pyx_k_ads, sizeof(__pyx_k_ads), 0, 1, 0, 1}, + {&__pyx_n_s_ads_data, __pyx_k_ads_data, sizeof(__pyx_k_ads_data), 0, 0, 1, 1}, + {&__pyx_n_s_asyncio_coroutines, __pyx_k_asyncio_coroutines, sizeof(__pyx_k_asyncio_coroutines), 0, 0, 1, 1}, + {&__pyx_n_s_autocommit, __pyx_k_autocommit, sizeof(__pyx_k_autocommit), 0, 0, 1, 1}, + {&__pyx_n_s_caption, __pyx_k_caption, sizeof(__pyx_k_caption), 0, 0, 1, 1}, + {&__pyx_n_u_caption, __pyx_k_caption, sizeof(__pyx_k_caption), 0, 1, 0, 1}, + {&__pyx_n_s_chat_id, __pyx_k_chat_id, sizeof(__pyx_k_chat_id), 0, 0, 1, 1}, + {&__pyx_n_u_chat_id, __pyx_k_chat_id, sizeof(__pyx_k_chat_id), 0, 1, 0, 1}, + {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, + {&__pyx_n_s_connect, __pyx_k_connect, sizeof(__pyx_k_connect), 0, 0, 1, 1}, + {&__pyx_n_s_connector, __pyx_k_connector, sizeof(__pyx_k_connector), 0, 0, 1, 1}, + {&__pyx_kp_u_copyMessage, __pyx_k_copyMessage, sizeof(__pyx_k_copyMessage), 0, 1, 0, 0}, + {&__pyx_n_s_copy_message_sync, __pyx_k_copy_message_sync, sizeof(__pyx_k_copy_message_sync), 0, 0, 1, 1}, + {&__pyx_n_s_cursor, __pyx_k_cursor, sizeof(__pyx_k_cursor), 0, 0, 1, 1}, + {&__pyx_n_s_cython_code_send_ads, __pyx_k_cython_code_send_ads, sizeof(__pyx_k_cython_code_send_ads), 0, 0, 1, 1}, + {&__pyx_kp_s_cython_code_send_ads_pyx, __pyx_k_cython_code_send_ads_pyx, sizeof(__pyx_k_cython_code_send_ads_pyx), 0, 0, 1, 0}, + {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1}, + {&__pyx_n_s_data_config, __pyx_k_data_config, sizeof(__pyx_k_data_config), 0, 0, 1, 1}, + {&__pyx_n_s_database, __pyx_k_database, sizeof(__pyx_k_database), 0, 0, 1, 1}, + {&__pyx_n_s_db, __pyx_k_db, sizeof(__pyx_k_db), 0, 0, 1, 1}, + {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1}, + {&__pyx_n_s_dict_2, __pyx_k_dict_2, sizeof(__pyx_k_dict_2), 0, 0, 1, 1}, + {&__pyx_kp_u_disable, __pyx_k_disable, sizeof(__pyx_k_disable), 0, 1, 0, 0}, + {&__pyx_n_u_done_count, __pyx_k_done_count, sizeof(__pyx_k_done_count), 0, 1, 0, 1}, + {&__pyx_kp_u_enable, __pyx_k_enable, sizeof(__pyx_k_enable), 0, 1, 0, 0}, + {&__pyx_n_s_end_id, __pyx_k_end_id, sizeof(__pyx_k_end_id), 0, 0, 1, 1}, + {&__pyx_n_s_end_index, __pyx_k_end_index, sizeof(__pyx_k_end_index), 0, 0, 1, 1}, + {&__pyx_n_s_end_time, __pyx_k_end_time, sizeof(__pyx_k_end_time), 0, 0, 1, 1}, + {&__pyx_n_s_err, __pyx_k_err, sizeof(__pyx_k_err), 0, 0, 1, 1}, + {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1}, + {&__pyx_n_s_execute, __pyx_k_execute, sizeof(__pyx_k_execute), 0, 0, 1, 1}, + {&__pyx_n_u_fail_count, __pyx_k_fail_count, sizeof(__pyx_k_fail_count), 0, 1, 0, 1}, + {&__pyx_n_s_fetchall, __pyx_k_fetchall, sizeof(__pyx_k_fetchall), 0, 0, 1, 1}, + {&__pyx_n_s_file_db, __pyx_k_file_db, sizeof(__pyx_k_file_db), 0, 0, 1, 1}, + {&__pyx_n_s_from_chat_id, __pyx_k_from_chat_id, sizeof(__pyx_k_from_chat_id), 0, 0, 1, 1}, + {&__pyx_n_u_from_chat_id, __pyx_k_from_chat_id, sizeof(__pyx_k_from_chat_id), 0, 1, 0, 1}, + {&__pyx_kp_u_gc, __pyx_k_gc, sizeof(__pyx_k_gc), 0, 1, 0, 0}, + {&__pyx_n_s_getstate, __pyx_k_getstate, sizeof(__pyx_k_getstate), 0, 0, 1, 1}, + {&__pyx_n_s_host, __pyx_k_host, sizeof(__pyx_k_host), 0, 0, 1, 1}, + {&__pyx_kp_u_https_api_telegram_org_bot, __pyx_k_https_api_telegram_org_bot, sizeof(__pyx_k_https_api_telegram_org_bot), 0, 1, 0, 0}, + {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, + {&__pyx_n_s_info, __pyx_k_info, sizeof(__pyx_k_info), 0, 0, 1, 1}, + {&__pyx_n_s_initializing, __pyx_k_initializing, sizeof(__pyx_k_initializing), 0, 0, 1, 1}, + {&__pyx_n_s_is_coroutine, __pyx_k_is_coroutine, sizeof(__pyx_k_is_coroutine), 0, 0, 1, 1}, + {&__pyx_kp_u_isenabled, __pyx_k_isenabled, sizeof(__pyx_k_isenabled), 0, 1, 0, 0}, + {&__pyx_n_s_json, __pyx_k_json, sizeof(__pyx_k_json), 0, 0, 1, 1}, + {&__pyx_n_s_key, __pyx_k_key, sizeof(__pyx_k_key), 0, 0, 1, 1}, + {&__pyx_n_s_kwargs, __pyx_k_kwargs, sizeof(__pyx_k_kwargs), 0, 0, 1, 1}, + {&__pyx_n_s_list, __pyx_k_list, sizeof(__pyx_k_list), 0, 0, 1, 1}, + {&__pyx_n_s_loader, __pyx_k_loader, sizeof(__pyx_k_loader), 0, 0, 1, 1}, + {&__pyx_n_s_localtime, __pyx_k_localtime, sizeof(__pyx_k_localtime), 0, 0, 1, 1}, + {&__pyx_n_s_logging, __pyx_k_logging, sizeof(__pyx_k_logging), 0, 0, 1, 1}, + {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_message_id, __pyx_k_message_id, sizeof(__pyx_k_message_id), 0, 0, 1, 1}, + {&__pyx_n_u_message_id, __pyx_k_message_id, sizeof(__pyx_k_message_id), 0, 1, 0, 1}, + {&__pyx_n_s_mysql, __pyx_k_mysql, sizeof(__pyx_k_mysql), 0, 0, 1, 1}, + {&__pyx_n_s_mysql_connector, __pyx_k_mysql_connector, sizeof(__pyx_k_mysql_connector), 0, 0, 1, 1}, + {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, + {&__pyx_n_s_new, __pyx_k_new, sizeof(__pyx_k_new), 0, 0, 1, 1}, + {&__pyx_n_s_password, __pyx_k_password, sizeof(__pyx_k_password), 0, 0, 1, 1}, + {&__pyx_n_s_per_time, __pyx_k_per_time, sizeof(__pyx_k_per_time), 0, 0, 1, 1}, + {&__pyx_n_u_per_time, __pyx_k_per_time, sizeof(__pyx_k_per_time), 0, 1, 0, 1}, + {&__pyx_n_s_pickle, __pyx_k_pickle, sizeof(__pyx_k_pickle), 0, 0, 1, 1}, + {&__pyx_n_s_post, __pyx_k_post, sizeof(__pyx_k_post), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_PickleError, __pyx_k_pyx_PickleError, sizeof(__pyx_k_pyx_PickleError), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_checksum, __pyx_k_pyx_checksum, sizeof(__pyx_k_pyx_checksum), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_result, __pyx_k_pyx_result, sizeof(__pyx_k_pyx_result), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_state, __pyx_k_pyx_state, sizeof(__pyx_k_pyx_state), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_type, __pyx_k_pyx_type, sizeof(__pyx_k_pyx_type), 0, 0, 1, 1}, + {&__pyx_n_s_pyx_unpickle_MyDatabase, __pyx_k_pyx_unpickle_MyDatabase, sizeof(__pyx_k_pyx_unpickle_MyDatabase), 0, 0, 1, 1}, + {&__pyx_n_s_query_values, __pyx_k_query_values, sizeof(__pyx_k_query_values), 0, 0, 1, 1}, + {&__pyx_n_s_reading_db, __pyx_k_reading_db, sizeof(__pyx_k_reading_db), 0, 0, 1, 1}, + {&__pyx_n_s_reconnect, __pyx_k_reconnect, sizeof(__pyx_k_reconnect), 0, 0, 1, 1}, + {&__pyx_n_s_reduce, __pyx_k_reduce, sizeof(__pyx_k_reduce), 0, 0, 1, 1}, + {&__pyx_n_s_reduce_cython, __pyx_k_reduce_cython, sizeof(__pyx_k_reduce_cython), 0, 0, 1, 1}, + {&__pyx_n_s_reduce_ex, __pyx_k_reduce_ex, sizeof(__pyx_k_reduce_ex), 0, 0, 1, 1}, + {&__pyx_n_s_reply_markup, __pyx_k_reply_markup, sizeof(__pyx_k_reply_markup), 0, 0, 1, 1}, + {&__pyx_n_u_reply_markup, __pyx_k_reply_markup, sizeof(__pyx_k_reply_markup), 0, 1, 0, 1}, + {&__pyx_n_s_requests, __pyx_k_requests, sizeof(__pyx_k_requests), 0, 0, 1, 1}, + {&__pyx_n_s_response, __pyx_k_response, sizeof(__pyx_k_response), 0, 0, 1, 1}, + {&__pyx_n_s_result, __pyx_k_result, sizeof(__pyx_k_result), 0, 0, 1, 1}, + {&__pyx_n_s_return, __pyx_k_return, sizeof(__pyx_k_return), 0, 0, 1, 1}, + {&__pyx_n_s_select_users_by_id, __pyx_k_select_users_by_id, sizeof(__pyx_k_select_users_by_id), 0, 0, 1, 1}, + {&__pyx_n_s_self, __pyx_k_self, sizeof(__pyx_k_self), 0, 0, 1, 1}, + {&__pyx_kp_u_sendMessage, __pyx_k_sendMessage, sizeof(__pyx_k_sendMessage), 0, 1, 0, 0}, + {&__pyx_n_s_send_ads, __pyx_k_send_ads, sizeof(__pyx_k_send_ads), 0, 0, 1, 1}, + {&__pyx_n_s_send_message_sync, __pyx_k_send_message_sync, sizeof(__pyx_k_send_message_sync), 0, 0, 1, 1}, + {&__pyx_n_s_setstate, __pyx_k_setstate, sizeof(__pyx_k_setstate), 0, 0, 1, 1}, + {&__pyx_n_s_setstate_cython, __pyx_k_setstate_cython, sizeof(__pyx_k_setstate_cython), 0, 0, 1, 1}, + {&__pyx_n_s_sleep, __pyx_k_sleep, sizeof(__pyx_k_sleep), 0, 0, 1, 1}, + {&__pyx_n_s_spec, __pyx_k_spec, sizeof(__pyx_k_spec), 0, 0, 1, 1}, + {&__pyx_n_s_sql_query, __pyx_k_sql_query, sizeof(__pyx_k_sql_query), 0, 0, 1, 1}, + {&__pyx_n_u_start, __pyx_k_start, sizeof(__pyx_k_start), 0, 1, 0, 1}, + {&__pyx_n_s_start_id, __pyx_k_start_id, sizeof(__pyx_k_start_id), 0, 0, 1, 1}, + {&__pyx_n_s_start_index, __pyx_k_start_index, sizeof(__pyx_k_start_index), 0, 0, 1, 1}, + {&__pyx_kp_u_start_time, __pyx_k_start_time, sizeof(__pyx_k_start_time), 0, 1, 0, 0}, + {&__pyx_n_s_start_time_2, __pyx_k_start_time_2, sizeof(__pyx_k_start_time_2), 0, 0, 1, 1}, + {&__pyx_n_s_state, __pyx_k_state, sizeof(__pyx_k_state), 0, 0, 1, 1}, + {&__pyx_n_s_strftime, __pyx_k_strftime, sizeof(__pyx_k_strftime), 0, 0, 1, 1}, + {&__pyx_kp_s_stringsource, __pyx_k_stringsource, sizeof(__pyx_k_stringsource), 0, 0, 1, 0}, + {&__pyx_n_s_summary_message, __pyx_k_summary_message, sizeof(__pyx_k_summary_message), 0, 0, 1, 1}, + {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {&__pyx_n_s_text, __pyx_k_text, sizeof(__pyx_k_text), 0, 0, 1, 1}, + {&__pyx_n_u_text, __pyx_k_text, sizeof(__pyx_k_text), 0, 1, 0, 1}, + {&__pyx_n_s_time, __pyx_k_time, sizeof(__pyx_k_time), 0, 0, 1, 1}, + {&__pyx_n_s_total_time, __pyx_k_total_time, sizeof(__pyx_k_total_time), 0, 0, 1, 1}, + {&__pyx_n_s_total_users, __pyx_k_total_users, sizeof(__pyx_k_total_users), 0, 0, 1, 1}, + {&__pyx_n_u_total_users, __pyx_k_total_users, sizeof(__pyx_k_total_users), 0, 1, 0, 1}, + {&__pyx_n_s_update, __pyx_k_update, sizeof(__pyx_k_update), 0, 0, 1, 1}, + {&__pyx_n_s_url, __pyx_k_url, sizeof(__pyx_k_url), 0, 0, 1, 1}, + {&__pyx_n_s_use_setstate, __pyx_k_use_setstate, sizeof(__pyx_k_use_setstate), 0, 0, 1, 1}, + {&__pyx_n_s_user, __pyx_k_user, sizeof(__pyx_k_user), 0, 0, 1, 1}, + {&__pyx_n_s_users_batch, __pyx_k_users_batch, sizeof(__pyx_k_users_batch), 0, 0, 1, 1}, + {0, 0, 0, 0, 0, 0, 0} + }; + return __Pyx_InitStrings(__pyx_string_tab); +} +/* #### Code section: cached_builtins ### */ +static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { + return 0; +} +/* #### Code section: cached_constants ### */ + +static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "cython_code/send_ads.pyx":119 + * return send_ads() + * else: + * file_db.add_data(False, key='ads') # <<<<<<<<<<<<<< + * summary_message = ( + * f" Advertisement Sending Completed\n\n" + */ + __pyx_tuple__3 = PyTuple_Pack(1, Py_False); if (unlikely(!__pyx_tuple__3)) __PYX_ERR(0, 119, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__3); + __Pyx_GIVEREF(__pyx_tuple__3); + + /* "(tree fragment)":4 + * cdef object __pyx_PickleError + * cdef object __pyx_result + * if __pyx_checksum not in (0xc59a5d0, 0xee418c5, 0x43b1ea3): # <<<<<<<<<<<<<< + * from pickle import PickleError as __pyx_PickleError + * raise __pyx_PickleError, "Incompatible checksums (0x%x vs (0xc59a5d0, 0xee418c5, 0x43b1ea3) = (connection, cursor, database, host, password, user))" % __pyx_checksum + */ + __pyx_tuple__4 = PyTuple_Pack(3, __pyx_int_207201744, __pyx_int_249829573, __pyx_int_70983331); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(1, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); + + /* "cython_code/send_ads.pyx":5 + * import logging + * import time + * import mysql.connector # Import normally, do not use 'cimport' # <<<<<<<<<<<<<< + * from data.config import * + * from loader import db, file_db + */ + __pyx_tuple__7 = PyTuple_Pack(2, __pyx_n_s_mysql, __pyx_n_s_connector); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__7); + __Pyx_GIVEREF(__pyx_tuple__7); + + /* "cython_code/send_ads.pyx":21 + * self.reconnect() + * + * def reconnect(self): # <<<<<<<<<<<<<< + * try: + * self.connection = mysql.connector.connect( + */ + __pyx_tuple__8 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_err); if (unlikely(!__pyx_tuple__8)) __PYX_ERR(0, 21, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__8); + __Pyx_GIVEREF(__pyx_tuple__8); + __pyx_codeobj__9 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__8, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cython_code_send_ads_pyx, __pyx_n_s_reconnect, 21, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__9)) __PYX_ERR(0, 21, __pyx_L1_error) + + /* "cython_code/send_ads.pyx":37 + * logging.error(err) + * + * def select_users_by_id(self, int start_id, int end_id) -> list: # <<<<<<<<<<<<<< + * try: + * sql_query = "SELECT * FROM `users` WHERE `id` >= %s AND `id` < %s;" + */ + __pyx_tuple__10 = PyTuple_Pack(7, __pyx_n_s_self, __pyx_n_s_start_id, __pyx_n_s_end_id, __pyx_n_s_sql_query, __pyx_n_s_query_values, __pyx_n_s_result, __pyx_n_s_err); if (unlikely(!__pyx_tuple__10)) __PYX_ERR(0, 37, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__10); + __Pyx_GIVEREF(__pyx_tuple__10); + __pyx_codeobj__11 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__10, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cython_code_send_ads_pyx, __pyx_n_s_select_users_by_id, 37, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__11)) __PYX_ERR(0, 37, __pyx_L1_error) + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + __pyx_tuple__12 = PyTuple_Pack(4, __pyx_n_s_self, __pyx_n_s_state, __pyx_n_s_dict_2, __pyx_n_s_use_setstate); if (unlikely(!__pyx_tuple__12)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__12); + __Pyx_GIVEREF(__pyx_tuple__12); + __pyx_codeobj__13 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 4, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__12, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_reduce_cython, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__13)) __PYX_ERR(1, 1, __pyx_L1_error) + + /* "(tree fragment)":16 + * else: + * return __pyx_unpickle_MyDatabase, (type(self), 0xc59a5d0, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_MyDatabase__set_state(self, __pyx_state) + */ + __pyx_tuple__14 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_pyx_state); if (unlikely(!__pyx_tuple__14)) __PYX_ERR(1, 16, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__14); + __Pyx_GIVEREF(__pyx_tuple__14); + __pyx_codeobj__15 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__14, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_setstate_cython, 16, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__15)) __PYX_ERR(1, 16, __pyx_L1_error) + + /* "cython_code/send_ads.pyx":52 + * cdef MyDatabase my_db = MyDatabase(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) + * + * def copy_message_sync(int chat_id, int from_chat_id, int message_id, **kwargs): # <<<<<<<<<<<<<< + * url = f"https://api.telegram.org/bot{BOT_TOKEN}/copyMessage" + * data = { + */ + __pyx_tuple__16 = PyTuple_Pack(7, __pyx_n_s_chat_id, __pyx_n_s_from_chat_id, __pyx_n_s_message_id, __pyx_n_s_kwargs, __pyx_n_s_url, __pyx_n_s_data, __pyx_n_s_response); if (unlikely(!__pyx_tuple__16)) __PYX_ERR(0, 52, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__16); + __Pyx_GIVEREF(__pyx_tuple__16); + __pyx_codeobj__17 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 7, 0, CO_OPTIMIZED|CO_NEWLOCALS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__16, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cython_code_send_ads_pyx, __pyx_n_s_copy_message_sync, 52, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__17)) __PYX_ERR(0, 52, __pyx_L1_error) + + /* "cython_code/send_ads.pyx":63 + * return response.json() + * + * def send_message_sync(int chat_id, str text, **kwargs): # <<<<<<<<<<<<<< + * url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage" + * data = { + */ + __pyx_tuple__18 = PyTuple_Pack(6, __pyx_n_s_chat_id, __pyx_n_s_text, __pyx_n_s_kwargs, __pyx_n_s_url, __pyx_n_s_data, __pyx_n_s_response); if (unlikely(!__pyx_tuple__18)) __PYX_ERR(0, 63, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__18); + __Pyx_GIVEREF(__pyx_tuple__18); + __pyx_codeobj__19 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 6, 0, CO_OPTIMIZED|CO_NEWLOCALS|CO_VARKEYWORDS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__18, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cython_code_send_ads_pyx, __pyx_n_s_send_message_sync, 63, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__19)) __PYX_ERR(0, 63, __pyx_L1_error) + + /* "cython_code/send_ads.pyx":73 + * return response.json() + * + * def send_ads(): # <<<<<<<<<<<<<< + * cdef float start_time, end_time, total_time, per_time + * cdef int start_index, end_index, total_users, chat_id, from_chat_id, message_id + */ + __pyx_tuple__20 = PyTuple_Pack(17, __pyx_n_s_start_time_2, __pyx_n_s_end_time, __pyx_n_s_total_time, __pyx_n_s_per_time, __pyx_n_s_start_index, __pyx_n_s_end_index, __pyx_n_s_total_users, __pyx_n_s_chat_id, __pyx_n_s_from_chat_id, __pyx_n_s_message_id, __pyx_n_s_caption, __pyx_n_s_users_batch, __pyx_n_s_reply_markup, __pyx_n_s_ads_data, __pyx_n_s_user, __pyx_n_s_err, __pyx_n_s_summary_message); if (unlikely(!__pyx_tuple__20)) __PYX_ERR(0, 73, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__20); + __Pyx_GIVEREF(__pyx_tuple__20); + __pyx_codeobj__21 = (PyObject*)__Pyx_PyCode_New(0, 0, 0, 17, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__20, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cython_code_send_ads_pyx, __pyx_n_s_send_ads, 73, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__21)) __PYX_ERR(0, 73, __pyx_L1_error) + + /* "(tree fragment)":1 + * def __pyx_unpickle_MyDatabase(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + __pyx_tuple__22 = PyTuple_Pack(5, __pyx_n_s_pyx_type, __pyx_n_s_pyx_checksum, __pyx_n_s_pyx_state, __pyx_n_s_pyx_PickleError, __pyx_n_s_pyx_result); if (unlikely(!__pyx_tuple__22)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__22); + __Pyx_GIVEREF(__pyx_tuple__22); + __pyx_codeobj__23 = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 5, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__22, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_stringsource, __pyx_n_s_pyx_unpickle_MyDatabase, 1, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__23)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} +/* #### Code section: init_constants ### */ + +static CYTHON_SMALL_CODE int __Pyx_InitConstants(void) { + __pyx_umethod_PyDict_Type_update.type = (PyObject*)&PyDict_Type; + __pyx_umethod_PyDict_Type_update.method_name = &__pyx_n_s_update; + if (__Pyx_CreateStringTabAndInitStrings() < 0) __PYX_ERR(0, 1, __pyx_L1_error); + __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_70983331 = PyInt_FromLong(70983331L); if (unlikely(!__pyx_int_70983331)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_207201744 = PyInt_FromLong(207201744L); if (unlikely(!__pyx_int_207201744)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_249829573 = PyInt_FromLong(249829573L); if (unlikely(!__pyx_int_249829573)) __PYX_ERR(0, 1, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} +/* #### Code section: init_globals ### */ + +static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { + return 0; +} +/* #### Code section: init_module ### */ + +static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/ + +static int __Pyx_modinit_global_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); + /*--- Global init code ---*/ + __pyx_v_11cython_code_8send_ads_my_db = ((struct __pyx_obj_11cython_code_8send_ads_MyDatabase *)Py_None); Py_INCREF(Py_None); + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); + /*--- Variable export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); + /*--- Function export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_type_init_code(void) { + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); + /*--- Type init code ---*/ + #if CYTHON_USE_TYPE_SPECS + __pyx_ptype_11cython_code_8send_ads_MyDatabase = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_11cython_code_8send_ads_MyDatabase_spec, NULL); if (unlikely(!__pyx_ptype_11cython_code_8send_ads_MyDatabase)) __PYX_ERR(0, 9, __pyx_L1_error) + if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_11cython_code_8send_ads_MyDatabase_spec, __pyx_ptype_11cython_code_8send_ads_MyDatabase) < 0) __PYX_ERR(0, 9, __pyx_L1_error) + #else + __pyx_ptype_11cython_code_8send_ads_MyDatabase = &__pyx_type_11cython_code_8send_ads_MyDatabase; + #endif + #if !CYTHON_COMPILING_IN_LIMITED_API + #endif + #if !CYTHON_USE_TYPE_SPECS + if (__Pyx_PyType_Ready(__pyx_ptype_11cython_code_8send_ads_MyDatabase) < 0) __PYX_ERR(0, 9, __pyx_L1_error) + #endif + #if PY_MAJOR_VERSION < 3 + __pyx_ptype_11cython_code_8send_ads_MyDatabase->tp_print = 0; + #endif + #if !CYTHON_COMPILING_IN_LIMITED_API + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_11cython_code_8send_ads_MyDatabase->tp_dictoffset && __pyx_ptype_11cython_code_8send_ads_MyDatabase->tp_getattro == PyObject_GenericGetAttr)) { + __pyx_ptype_11cython_code_8send_ads_MyDatabase->tp_getattro = __Pyx_PyObject_GenericGetAttr; + } + #endif + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_MyDatabase, (PyObject *) __pyx_ptype_11cython_code_8send_ads_MyDatabase) < 0) __PYX_ERR(0, 9, __pyx_L1_error) + #if !CYTHON_COMPILING_IN_LIMITED_API + if (__Pyx_setup_reduce((PyObject *) __pyx_ptype_11cython_code_8send_ads_MyDatabase) < 0) __PYX_ERR(0, 9, __pyx_L1_error) + #endif + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_modinit_type_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); + /*--- Type import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); + /*--- Variable import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); + /*--- Function import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + + +#if PY_MAJOR_VERSION >= 3 +#if CYTHON_PEP489_MULTI_PHASE_INIT +static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ +static int __pyx_pymod_exec_send_ads(PyObject* module); /*proto*/ +static PyModuleDef_Slot __pyx_moduledef_slots[] = { + {Py_mod_create, (void*)__pyx_pymod_create}, + {Py_mod_exec, (void*)__pyx_pymod_exec_send_ads}, + {0, NULL} +}; +#endif + +#ifdef __cplusplus +namespace { + struct PyModuleDef __pyx_moduledef = + #else + static struct PyModuleDef __pyx_moduledef = + #endif + { + PyModuleDef_HEAD_INIT, + "send_ads", + 0, /* m_doc */ + #if CYTHON_PEP489_MULTI_PHASE_INIT + 0, /* m_size */ + #elif CYTHON_USE_MODULE_STATE + sizeof(__pyx_mstate), /* m_size */ + #else + -1, /* m_size */ + #endif + __pyx_methods /* m_methods */, + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_moduledef_slots, /* m_slots */ + #else + NULL, /* m_reload */ + #endif + #if CYTHON_USE_MODULE_STATE + __pyx_m_traverse, /* m_traverse */ + __pyx_m_clear, /* m_clear */ + NULL /* m_free */ + #else + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ + #endif + }; + #ifdef __cplusplus +} /* anonymous namespace */ +#endif +#endif + +#ifndef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#elif PY_MAJOR_VERSION < 3 +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" void +#else +#define __Pyx_PyMODINIT_FUNC void +#endif +#else +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" PyObject * +#else +#define __Pyx_PyMODINIT_FUNC PyObject * +#endif +#endif + + +#if PY_MAJOR_VERSION < 3 +__Pyx_PyMODINIT_FUNC initsend_ads(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC initsend_ads(void) +#else +__Pyx_PyMODINIT_FUNC PyInit_send_ads(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC PyInit_send_ads(void) +#if CYTHON_PEP489_MULTI_PHASE_INIT +{ + return PyModuleDef_Init(&__pyx_moduledef); +} +static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { + #if PY_VERSION_HEX >= 0x030700A1 + static PY_INT64_T main_interpreter_id = -1; + PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); + if (main_interpreter_id == -1) { + main_interpreter_id = current_id; + return (unlikely(current_id == -1)) ? -1 : 0; + } else if (unlikely(main_interpreter_id != current_id)) + #else + static PyInterpreterState *main_interpreter = NULL; + PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; + if (!main_interpreter) { + main_interpreter = current_interpreter; + } else if (unlikely(main_interpreter != current_interpreter)) + #endif + { + PyErr_SetString( + PyExc_ImportError, + "Interpreter change detected - this module can only be loaded into one interpreter per process."); + return -1; + } + return 0; +} +#if CYTHON_COMPILING_IN_LIMITED_API +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *module, const char* from_name, const char* to_name, int allow_none) +#else +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) +#endif +{ + PyObject *value = PyObject_GetAttrString(spec, from_name); + int result = 0; + if (likely(value)) { + if (allow_none || value != Py_None) { +#if CYTHON_COMPILING_IN_LIMITED_API + result = PyModule_AddObject(module, to_name, value); +#else + result = PyDict_SetItemString(moddict, to_name, value); +#endif + } + Py_DECREF(value); + } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + } else { + result = -1; + } + return result; +} +static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def) { + PyObject *module = NULL, *moddict, *modname; + CYTHON_UNUSED_VAR(def); + if (__Pyx_check_single_interpreter()) + return NULL; + if (__pyx_m) + return __Pyx_NewRef(__pyx_m); + modname = PyObject_GetAttrString(spec, "name"); + if (unlikely(!modname)) goto bad; + module = PyModule_NewObject(modname); + Py_DECREF(modname); + if (unlikely(!module)) goto bad; +#if CYTHON_COMPILING_IN_LIMITED_API + moddict = module; +#else + moddict = PyModule_GetDict(module); + if (unlikely(!moddict)) goto bad; +#endif + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; + return module; +bad: + Py_XDECREF(module); + return NULL; +} + + +static CYTHON_SMALL_CODE int __pyx_pymod_exec_send_ads(PyObject *__pyx_pyinit_module) +#endif +#endif +{ + int stringtab_initialized = 0; + #if CYTHON_USE_MODULE_STATE + int pystate_addmodule_run = 0; + #endif + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannyDeclarations + #if CYTHON_PEP489_MULTI_PHASE_INIT + if (__pyx_m) { + if (__pyx_m == __pyx_pyinit_module) return 0; + PyErr_SetString(PyExc_RuntimeError, "Module 'send_ads' has already been imported. Re-initialisation is not supported."); + return -1; + } + #elif PY_MAJOR_VERSION >= 3 + if (__pyx_m) return __Pyx_NewRef(__pyx_m); + #endif + /*--- Module creation code ---*/ + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_m = __pyx_pyinit_module; + Py_INCREF(__pyx_m); + #else + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4("send_ads", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #elif CYTHON_USE_MODULE_STATE + __pyx_t_1 = PyModule_Create(&__pyx_moduledef); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) + { + int add_module_result = PyState_AddModule(__pyx_t_1, &__pyx_moduledef); + __pyx_t_1 = 0; /* transfer ownership from __pyx_t_1 to "send_ads" pseudovariable */ + if (unlikely((add_module_result < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + pystate_addmodule_run = 1; + } + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #endif + CYTHON_UNUSED_VAR(__pyx_t_1); + __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_d); + __pyx_b = __Pyx_PyImport_AddModuleRef(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_cython_runtime = __Pyx_PyImport_AddModuleRef((const char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if CYTHON_REFNANNY +__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); +if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); +} +#endif + __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_send_ads(void)", 0); + if (__Pyx_check_binary_version(__PYX_LIMITED_VERSION_HEX, __Pyx_get_runtime_version(), CYTHON_COMPILING_IN_LIMITED_API) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pxy_PyFrame_Initialize_Offsets + __Pxy_PyFrame_Initialize_Offsets(); + #endif + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pyx_CyFunction_USED + if (__pyx_CyFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_FusedFunction_USED + if (__pyx_FusedFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Coroutine_USED + if (__pyx_Coroutine_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Generator_USED + if (__pyx_Generator_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_AsyncGen_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_StopAsyncIteration_USED + if (__pyx_StopAsyncIteration_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + /*--- Library function declarations ---*/ + /*--- Threads initialization code ---*/ + #if defined(WITH_THREAD) && PY_VERSION_HEX < 0x030700F0 && defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + PyEval_InitThreads(); + #endif + /*--- Initialize various global constants etc. ---*/ + if (__Pyx_InitConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + stringtab_initialized = 1; + if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) + if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + if (__pyx_module_is_main_cython_code__send_ads) { + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + } + #if PY_MAJOR_VERSION >= 3 + { + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) + if (!PyDict_GetItemString(modules, "cython_code.send_ads")) { + if (unlikely((PyDict_SetItemString(modules, "cython_code.send_ads", __pyx_m) < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + } + } + #endif + /*--- Builtin init code ---*/ + if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Constants init code ---*/ + if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Global type/function init code ---*/ + (void)__Pyx_modinit_global_init_code(); + (void)__Pyx_modinit_variable_export_code(); + (void)__Pyx_modinit_function_export_code(); + if (unlikely((__Pyx_modinit_type_init_code() < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + (void)__Pyx_modinit_type_import_code(); + (void)__Pyx_modinit_variable_import_code(); + (void)__Pyx_modinit_function_import_code(); + /*--- Execution code ---*/ + #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + + /* "cython_code/send_ads.pyx":2 + * # send_ads.pyx + * import requests # <<<<<<<<<<<<<< + * import logging + * import time + */ + __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_requests, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_requests, __pyx_t_2) < 0) __PYX_ERR(0, 2, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/send_ads.pyx":3 + * # send_ads.pyx + * import requests + * import logging # <<<<<<<<<<<<<< + * import time + * import mysql.connector # Import normally, do not use 'cimport' + */ + __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_logging, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_logging, __pyx_t_2) < 0) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/send_ads.pyx":4 + * import requests + * import logging + * import time # <<<<<<<<<<<<<< + * import mysql.connector # Import normally, do not use 'cimport' + * from data.config import * + */ + __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_time, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_time, __pyx_t_2) < 0) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/send_ads.pyx":5 + * import logging + * import time + * import mysql.connector # Import normally, do not use 'cimport' # <<<<<<<<<<<<<< + * from data.config import * + * from loader import db, file_db + */ + __pyx_t_2 = __Pyx_Import(__pyx_n_s_mysql_connector, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_mysql, __pyx_t_2) < 0) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/send_ads.pyx":6 + * import time + * import mysql.connector # Import normally, do not use 'cimport' + * from data.config import * # <<<<<<<<<<<<<< + * from loader import db, file_db + * + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s__6); + __Pyx_GIVEREF(__pyx_n_s__6); + if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s__6)) __PYX_ERR(0, 6, __pyx_L1_error); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_data_config, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__pyx_import_star(__pyx_t_3) < 0) __PYX_ERR(0, 6, __pyx_L1_error); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "cython_code/send_ads.pyx":7 + * import mysql.connector # Import normally, do not use 'cimport' + * from data.config import * + * from loader import db, file_db # <<<<<<<<<<<<<< + * + * cdef class MyDatabase: + */ + __pyx_t_3 = PyList_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_n_s_db); + __Pyx_GIVEREF(__pyx_n_s_db); + if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_db)) __PYX_ERR(0, 7, __pyx_L1_error); + __Pyx_INCREF(__pyx_n_s_file_db); + __Pyx_GIVEREF(__pyx_n_s_file_db); + if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_file_db)) __PYX_ERR(0, 7, __pyx_L1_error); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_loader, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_db); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_db, __pyx_t_3) < 0) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_file_db); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_file_db, __pyx_t_3) < 0) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/send_ads.pyx":21 + * self.reconnect() + * + * def reconnect(self): # <<<<<<<<<<<<<< + * try: + * self.connection = mysql.connector.connect( + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_8send_ads_10MyDatabase_3reconnect, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_MyDatabase_reconnect, NULL, __pyx_n_s_cython_code_send_ads, __pyx_d, ((PyObject *)__pyx_codeobj__9)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 21, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_11cython_code_8send_ads_MyDatabase, __pyx_n_s_reconnect, __pyx_t_2) < 0) __PYX_ERR(0, 21, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + PyType_Modified(__pyx_ptype_11cython_code_8send_ads_MyDatabase); + + /* "cython_code/send_ads.pyx":37 + * logging.error(err) + * + * def select_users_by_id(self, int start_id, int end_id) -> list: # <<<<<<<<<<<<<< + * try: + * sql_query = "SELECT * FROM `users` WHERE `id` >= %s AND `id` < %s;" + */ + __pyx_t_2 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 37, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_return, __pyx_n_s_list) < 0) __PYX_ERR(0, 37, __pyx_L1_error) + __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_8send_ads_10MyDatabase_5select_users_by_id, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_MyDatabase_select_users_by_id, NULL, __pyx_n_s_cython_code_send_ads, __pyx_d, ((PyObject *)__pyx_codeobj__11)); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 37, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_3, __pyx_t_2); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_11cython_code_8send_ads_MyDatabase, __pyx_n_s_select_users_by_id, __pyx_t_3) < 0) __PYX_ERR(0, 37, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + PyType_Modified(__pyx_ptype_11cython_code_8send_ads_MyDatabase); + + /* "(tree fragment)":1 + * def __reduce_cython__(self): # <<<<<<<<<<<<<< + * cdef tuple state + * cdef object _dict + */ + __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_8send_ads_10MyDatabase_7__reduce_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_MyDatabase___reduce_cython, NULL, __pyx_n_s_cython_code_send_ads, __pyx_d, ((PyObject *)__pyx_codeobj__13)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_11cython_code_8send_ads_MyDatabase, __pyx_n_s_reduce_cython, __pyx_t_3) < 0) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + PyType_Modified(__pyx_ptype_11cython_code_8send_ads_MyDatabase); + + /* "(tree fragment)":16 + * else: + * return __pyx_unpickle_MyDatabase, (type(self), 0xc59a5d0, state) + * def __setstate_cython__(self, __pyx_state): # <<<<<<<<<<<<<< + * __pyx_unpickle_MyDatabase__set_state(self, __pyx_state) + */ + __pyx_t_3 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_8send_ads_10MyDatabase_9__setstate_cython__, __Pyx_CYFUNCTION_CCLASS, __pyx_n_s_MyDatabase___setstate_cython, NULL, __pyx_n_s_cython_code_send_ads, __pyx_d, ((PyObject *)__pyx_codeobj__15)); if (unlikely(!__pyx_t_3)) __PYX_ERR(1, 16, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (__Pyx_SetItemOnTypeDict((PyObject *)__pyx_ptype_11cython_code_8send_ads_MyDatabase, __pyx_n_s_setstate_cython, __pyx_t_3) < 0) __PYX_ERR(1, 16, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + PyType_Modified(__pyx_ptype_11cython_code_8send_ads_MyDatabase); + + /* "cython_code/send_ads.pyx":50 + * logging.error(err) + * + * cdef MyDatabase my_db = MyDatabase(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) # <<<<<<<<<<<<<< + * + * def copy_message_sync(int chat_id, int from_chat_id, int message_id, **kwargs): + */ + __pyx_t_3 = __Pyx_PyDict_NewPresized(4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_HOST); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_host, __pyx_t_2) < 0) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_MYSQL_USER); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_user, __pyx_t_2) < 0) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_MYSQL_PASSWORD); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_password, __pyx_t_2) < 0) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_MYSQL_DATABASE); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_3, __pyx_n_s_database, __pyx_t_2) < 0) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyObject_Call(((PyObject *)__pyx_ptype_11cython_code_8send_ads_MyDatabase), __pyx_empty_tuple, __pyx_t_3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XGOTREF((PyObject *)__pyx_v_11cython_code_8send_ads_my_db); + __Pyx_DECREF_SET(__pyx_v_11cython_code_8send_ads_my_db, ((struct __pyx_obj_11cython_code_8send_ads_MyDatabase *)__pyx_t_2)); + __Pyx_GIVEREF(__pyx_t_2); + __pyx_t_2 = 0; + + /* "cython_code/send_ads.pyx":52 + * cdef MyDatabase my_db = MyDatabase(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) + * + * def copy_message_sync(int chat_id, int from_chat_id, int message_id, **kwargs): # <<<<<<<<<<<<<< + * url = f"https://api.telegram.org/bot{BOT_TOKEN}/copyMessage" + * data = { + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_8send_ads_1copy_message_sync, 0, __pyx_n_s_copy_message_sync, NULL, __pyx_n_s_cython_code_send_ads, __pyx_d, ((PyObject *)__pyx_codeobj__17)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 52, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_copy_message_sync, __pyx_t_2) < 0) __PYX_ERR(0, 52, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/send_ads.pyx":63 + * return response.json() + * + * def send_message_sync(int chat_id, str text, **kwargs): # <<<<<<<<<<<<<< + * url = f"https://api.telegram.org/bot{BOT_TOKEN}/sendMessage" + * data = { + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_8send_ads_3send_message_sync, 0, __pyx_n_s_send_message_sync, NULL, __pyx_n_s_cython_code_send_ads, __pyx_d, ((PyObject *)__pyx_codeobj__19)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 63, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_send_message_sync, __pyx_t_2) < 0) __PYX_ERR(0, 63, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/send_ads.pyx":73 + * return response.json() + * + * def send_ads(): # <<<<<<<<<<<<<< + * cdef float start_time, end_time, total_time, per_time + * cdef int start_index, end_index, total_users, chat_id, from_chat_id, message_id + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_8send_ads_5send_ads, 0, __pyx_n_s_send_ads, NULL, __pyx_n_s_cython_code_send_ads, __pyx_d, ((PyObject *)__pyx_codeobj__21)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 73, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_send_ads, __pyx_t_2) < 0) __PYX_ERR(0, 73, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "(tree fragment)":1 + * def __pyx_unpickle_MyDatabase(__pyx_type, long __pyx_checksum, __pyx_state): # <<<<<<<<<<<<<< + * cdef object __pyx_PickleError + * cdef object __pyx_result + */ + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_8send_ads_7__pyx_unpickle_MyDatabase, 0, __pyx_n_s_pyx_unpickle_MyDatabase, NULL, __pyx_n_s_cython_code_send_ads, __pyx_d, ((PyObject *)__pyx_codeobj__23)); if (unlikely(!__pyx_t_2)) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_pyx_unpickle_MyDatabase, __pyx_t_2) < 0) __PYX_ERR(1, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/send_ads.pyx":1 + * # send_ads.pyx # <<<<<<<<<<<<<< + * import requests + * import logging + */ + __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /*--- Wrapped vars code ---*/ + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + if (__pyx_m) { + if (__pyx_d && stringtab_initialized) { + __Pyx_AddTraceback("init cython_code.send_ads", __pyx_clineno, __pyx_lineno, __pyx_filename); + } + #if !CYTHON_USE_MODULE_STATE + Py_CLEAR(__pyx_m); + #else + Py_DECREF(__pyx_m); + if (pystate_addmodule_run) { + PyObject *tp, *value, *tb; + PyErr_Fetch(&tp, &value, &tb); + PyState_RemoveModule(&__pyx_moduledef); + PyErr_Restore(tp, value, tb); + } + #endif + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init cython_code.send_ads"); + } + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + #if CYTHON_PEP489_MULTI_PHASE_INIT + return (__pyx_m != NULL) ? 0 : -1; + #elif PY_MAJOR_VERSION >= 3 + return __pyx_m; + #else + return; + #endif +} +/* #### Code section: cleanup_globals ### */ +/* #### Code section: cleanup_module ### */ +/* #### Code section: main_method ### */ +/* #### Code section: utility_code_pragmas ### */ +#ifdef _MSC_VER +#pragma warning( push ) +/* Warning 4127: conditional expression is constant + * Cython uses constant conditional expressions to allow in inline functions to be optimized at + * compile-time, so this warning is not useful + */ +#pragma warning( disable : 4127 ) +#endif + + + +/* #### Code section: utility_code_def ### */ + +/* --- Runtime support code --- */ +/* Refnanny */ +#if CYTHON_REFNANNY +static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { + PyObject *m = NULL, *p = NULL; + void *r = NULL; + m = PyImport_ImportModule(modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, "RefNannyAPI"); + if (!p) goto end; + r = PyLong_AsVoidPtr(p); +end: + Py_XDECREF(p); + Py_XDECREF(m); + return (__Pyx_RefNannyAPIStruct *)r; +} +#endif + +/* TupleAndListFromArray */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE void __Pyx_copy_object_array(PyObject *const *CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) { + PyObject *v; + Py_ssize_t i; + for (i = 0; i < length; i++) { + v = dest[i] = src[i]; + Py_INCREF(v); + } +} +static CYTHON_INLINE PyObject * +__Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n) +{ + PyObject *res; + if (n <= 0) { + Py_INCREF(__pyx_empty_tuple); + return __pyx_empty_tuple; + } + res = PyTuple_New(n); + if (unlikely(res == NULL)) return NULL; + __Pyx_copy_object_array(src, ((PyTupleObject*)res)->ob_item, n); + return res; +} +static CYTHON_INLINE PyObject * +__Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n) +{ + PyObject *res; + if (n <= 0) { + return PyList_New(0); + } + res = PyList_New(n); + if (unlikely(res == NULL)) return NULL; + __Pyx_copy_object_array(src, ((PyListObject*)res)->ob_item, n); + return res; +} +#endif + +/* BytesEquals */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API + return PyObject_RichCompareBool(s1, s2, equals); +#else + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { + const char *ps1, *ps2; + Py_ssize_t length = PyBytes_GET_SIZE(s1); + if (length != PyBytes_GET_SIZE(s2)) + return (equals == Py_NE); + ps1 = PyBytes_AS_STRING(s1); + ps2 = PyBytes_AS_STRING(s2); + if (ps1[0] != ps2[0]) { + return (equals == Py_NE); + } else if (length == 1) { + return (equals == Py_EQ); + } else { + int result; +#if CYTHON_USE_UNICODE_INTERNALS && (PY_VERSION_HEX < 0x030B0000) + Py_hash_t hash1, hash2; + hash1 = ((PyBytesObject*)s1)->ob_shash; + hash2 = ((PyBytesObject*)s2)->ob_shash; + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + return (equals == Py_NE); + } +#endif + result = memcmp(ps1, ps2, (size_t)length); + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +#endif +} + +/* UnicodeEquals */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API + return PyObject_RichCompareBool(s1, s2, equals); +#else +#if PY_MAJOR_VERSION < 3 + PyObject* owned_ref = NULL; +#endif + int s1_is_unicode, s2_is_unicode; + if (s1 == s2) { + goto return_eq; + } + s1_is_unicode = PyUnicode_CheckExact(s1); + s2_is_unicode = PyUnicode_CheckExact(s2); +#if PY_MAJOR_VERSION < 3 + if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { + owned_ref = PyUnicode_FromObject(s2); + if (unlikely(!owned_ref)) + return -1; + s2 = owned_ref; + s2_is_unicode = 1; + } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { + owned_ref = PyUnicode_FromObject(s1); + if (unlikely(!owned_ref)) + return -1; + s1 = owned_ref; + s1_is_unicode = 1; + } else if (((!s2_is_unicode) & (!s1_is_unicode))) { + return __Pyx_PyBytes_Equals(s1, s2, equals); + } +#endif + if (s1_is_unicode & s2_is_unicode) { + Py_ssize_t length; + int kind; + void *data1, *data2; + if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) + return -1; + length = __Pyx_PyUnicode_GET_LENGTH(s1); + if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { + goto return_ne; + } +#if CYTHON_USE_UNICODE_INTERNALS + { + Py_hash_t hash1, hash2; + #if CYTHON_PEP393_ENABLED + hash1 = ((PyASCIIObject*)s1)->hash; + hash2 = ((PyASCIIObject*)s2)->hash; + #else + hash1 = ((PyUnicodeObject*)s1)->hash; + hash2 = ((PyUnicodeObject*)s2)->hash; + #endif + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + goto return_ne; + } + } +#endif + kind = __Pyx_PyUnicode_KIND(s1); + if (kind != __Pyx_PyUnicode_KIND(s2)) { + goto return_ne; + } + data1 = __Pyx_PyUnicode_DATA(s1); + data2 = __Pyx_PyUnicode_DATA(s2); + if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { + goto return_ne; + } else if (length == 1) { + goto return_eq; + } else { + int result = memcmp(data1, data2, (size_t)(length * kind)); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & s2_is_unicode) { + goto return_ne; + } else if ((s2 == Py_None) & s1_is_unicode) { + goto return_ne; + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +return_eq: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ); +return_ne: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_NE); +#endif +} + +/* fastcall */ +#if CYTHON_METH_FASTCALL +static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s) +{ + Py_ssize_t i, n = PyTuple_GET_SIZE(kwnames); + for (i = 0; i < n; i++) + { + if (s == PyTuple_GET_ITEM(kwnames, i)) return kwvalues[i]; + } + for (i = 0; i < n; i++) + { + int eq = __Pyx_PyUnicode_Equals(s, PyTuple_GET_ITEM(kwnames, i), Py_EQ); + if (unlikely(eq != 0)) { + if (unlikely(eq < 0)) return NULL; + return kwvalues[i]; + } + } + return NULL; +} +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000 +CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues) { + Py_ssize_t i, nkwargs = PyTuple_GET_SIZE(kwnames); + PyObject *dict; + dict = PyDict_New(); + if (unlikely(!dict)) + return NULL; + for (i=0; i= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AsString(kw_name)); + #endif +} + +/* ParseKeywords */ +static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject *const *kwvalues, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + int kwds_is_tuple = CYTHON_METH_FASTCALL && likely(PyTuple_Check(kwds)); + while (1) { + Py_XDECREF(key); key = NULL; + Py_XDECREF(value); value = NULL; + if (kwds_is_tuple) { + Py_ssize_t size; +#if CYTHON_ASSUME_SAFE_MACROS + size = PyTuple_GET_SIZE(kwds); +#else + size = PyTuple_Size(kwds); + if (size < 0) goto bad; +#endif + if (pos >= size) break; +#if CYTHON_AVOID_BORROWED_REFS + key = __Pyx_PySequence_ITEM(kwds, pos); + if (!key) goto bad; +#elif CYTHON_ASSUME_SAFE_MACROS + key = PyTuple_GET_ITEM(kwds, pos); +#else + key = PyTuple_GetItem(kwds, pos); + if (!key) goto bad; +#endif + value = kwvalues[pos]; + pos++; + } + else + { + if (!PyDict_Next(kwds, &pos, &key, &value)) break; +#if CYTHON_AVOID_BORROWED_REFS + Py_INCREF(key); +#endif + } + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; +#if CYTHON_AVOID_BORROWED_REFS + Py_INCREF(value); + Py_DECREF(key); +#endif + key = NULL; + value = NULL; + continue; + } +#if !CYTHON_AVOID_BORROWED_REFS + Py_INCREF(key); +#endif + Py_INCREF(value); + name = first_kw_arg; + #if PY_MAJOR_VERSION < 3 + if (likely(PyString_Check(key))) { + while (*name) { + if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) + && _PyString_Eq(**name, key)) { + values[name-argnames] = value; +#if CYTHON_AVOID_BORROWED_REFS + value = NULL; +#endif + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + if ((**argname == key) || ( + (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) + && _PyString_Eq(**argname, key))) { + goto arg_passed_twice; + } + argname++; + } + } + } else + #endif + if (likely(PyUnicode_Check(key))) { + while (*name) { + int cmp = ( + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : + #endif + PyUnicode_Compare(**name, key) + ); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) { + values[name-argnames] = value; +#if CYTHON_AVOID_BORROWED_REFS + value = NULL; +#endif + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + int cmp = (**argname == key) ? 0 : + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : + #endif + PyUnicode_Compare(**argname, key); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) goto arg_passed_twice; + argname++; + } + } + } else + goto invalid_keyword_type; + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; + } + } + Py_XDECREF(key); + Py_XDECREF(value); + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, key); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + #if PY_MAJOR_VERSION < 3 + PyErr_Format(PyExc_TypeError, + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + PyErr_Format(PyExc_TypeError, + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + Py_XDECREF(key); + Py_XDECREF(value); + return -1; +} + +/* ArgTypeTest */ +static int __Pyx__ArgTypeTest(PyObject *obj, PyTypeObject *type, const char *name, int exact) +{ + __Pyx_TypeName type_name; + __Pyx_TypeName obj_type_name; + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; + } + else if (exact) { + #if PY_MAJOR_VERSION == 2 + if ((type == &PyBaseString_Type) && likely(__Pyx_PyBaseString_CheckExact(obj))) return 1; + #endif + } + else { + if (likely(__Pyx_TypeCheck(obj, type))) return 1; + } + type_name = __Pyx_PyType_GetName(type); + obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj)); + PyErr_Format(PyExc_TypeError, + "Argument '%.200s' has incorrect type (expected " __Pyx_FMT_TYPENAME + ", got " __Pyx_FMT_TYPENAME ")", name, type_name, obj_type_name); + __Pyx_DECREF_TypeName(type_name); + __Pyx_DECREF_TypeName(obj_type_name); + return 0; +} + +/* PyObjectGetAttrStr */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro)) + return tp->tp_getattro(obj, attr_name); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_getattr)) + return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); +#endif + return PyObject_GetAttr(obj, attr_name); +} +#endif + +/* PyFunctionFastCall */ +#if CYTHON_FAST_PYCALL && !CYTHON_VECTORCALL +static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na, + PyObject *globals) { + PyFrameObject *f; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject **fastlocals; + Py_ssize_t i; + PyObject *result; + assert(globals != NULL); + /* XXX Perhaps we should create a specialized + PyFrame_New() that doesn't take locals, but does + take builtins without sanity checking them. + */ + assert(tstate != NULL); + f = PyFrame_New(tstate, co, globals, NULL); + if (f == NULL) { + return NULL; + } + fastlocals = __Pyx_PyFrame_GetLocalsplus(f); + for (i = 0; i < na; i++) { + Py_INCREF(*args); + fastlocals[i] = *args++; + } + result = PyEval_EvalFrameEx(f,0); + ++tstate->recursion_depth; + Py_DECREF(f); + --tstate->recursion_depth; + return result; +} +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) { + PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); + PyObject *globals = PyFunction_GET_GLOBALS(func); + PyObject *argdefs = PyFunction_GET_DEFAULTS(func); + PyObject *closure; +#if PY_MAJOR_VERSION >= 3 + PyObject *kwdefs; +#endif + PyObject *kwtuple, **k; + PyObject **d; + Py_ssize_t nd; + Py_ssize_t nk; + PyObject *result; + assert(kwargs == NULL || PyDict_Check(kwargs)); + nk = kwargs ? PyDict_Size(kwargs) : 0; + #if PY_MAJOR_VERSION < 3 + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) { + return NULL; + } + #else + if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) { + return NULL; + } + #endif + if ( +#if PY_MAJOR_VERSION >= 3 + co->co_kwonlyargcount == 0 && +#endif + likely(kwargs == NULL || nk == 0) && + co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { + if (argdefs == NULL && co->co_argcount == nargs) { + result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals); + goto done; + } + else if (nargs == 0 && argdefs != NULL + && co->co_argcount == Py_SIZE(argdefs)) { + /* function called with no arguments, but all parameters have + a default value: use default values as arguments .*/ + args = &PyTuple_GET_ITEM(argdefs, 0); + result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals); + goto done; + } + } + if (kwargs != NULL) { + Py_ssize_t pos, i; + kwtuple = PyTuple_New(2 * nk); + if (kwtuple == NULL) { + result = NULL; + goto done; + } + k = &PyTuple_GET_ITEM(kwtuple, 0); + pos = i = 0; + while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) { + Py_INCREF(k[i]); + Py_INCREF(k[i+1]); + i += 2; + } + nk = i / 2; + } + else { + kwtuple = NULL; + k = NULL; + } + closure = PyFunction_GET_CLOSURE(func); +#if PY_MAJOR_VERSION >= 3 + kwdefs = PyFunction_GET_KW_DEFAULTS(func); +#endif + if (argdefs != NULL) { + d = &PyTuple_GET_ITEM(argdefs, 0); + nd = Py_SIZE(argdefs); + } + else { + d = NULL; + nd = 0; + } +#if PY_MAJOR_VERSION >= 3 + result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL, + args, (int)nargs, + k, (int)nk, + d, (int)nd, kwdefs, closure); +#else + result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, + args, (int)nargs, + k, (int)nk, + d, (int)nd, closure); +#endif + Py_XDECREF(kwtuple); +done: + Py_LeaveRecursiveCall(); + return result; +} +#endif + +/* PyObjectCall */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *result; + ternaryfunc call = Py_TYPE(func)->tp_call; + if (unlikely(!call)) + return PyObject_Call(func, arg, kw); + #if PY_MAJOR_VERSION < 3 + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + #else + if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) + return NULL; + #endif + result = (*call)(func, arg, kw); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* PyObjectCallMethO */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) { + PyObject *self, *result; + PyCFunction cfunc; + cfunc = __Pyx_CyOrPyCFunction_GET_FUNCTION(func); + self = __Pyx_CyOrPyCFunction_GET_SELF(func); + #if PY_MAJOR_VERSION < 3 + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + #else + if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) + return NULL; + #endif + result = cfunc(self, arg); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* PyObjectFastCall */ +#if PY_VERSION_HEX < 0x03090000 || CYTHON_COMPILING_IN_LIMITED_API +static PyObject* __Pyx_PyObject_FastCall_fallback(PyObject *func, PyObject **args, size_t nargs, PyObject *kwargs) { + PyObject *argstuple; + PyObject *result = 0; + size_t i; + argstuple = PyTuple_New((Py_ssize_t)nargs); + if (unlikely(!argstuple)) return NULL; + for (i = 0; i < nargs; i++) { + Py_INCREF(args[i]); + if (__Pyx_PyTuple_SET_ITEM(argstuple, (Py_ssize_t)i, args[i]) < 0) goto bad; + } + result = __Pyx_PyObject_Call(func, argstuple, kwargs); + bad: + Py_DECREF(argstuple); + return result; +} +#endif +static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject **args, size_t _nargs, PyObject *kwargs) { + Py_ssize_t nargs = __Pyx_PyVectorcall_NARGS(_nargs); +#if CYTHON_COMPILING_IN_CPYTHON + if (nargs == 0 && kwargs == NULL) { + if (__Pyx_CyOrPyCFunction_Check(func) && likely( __Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_NOARGS)) + return __Pyx_PyObject_CallMethO(func, NULL); + } + else if (nargs == 1 && kwargs == NULL) { + if (__Pyx_CyOrPyCFunction_Check(func) && likely( __Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_O)) + return __Pyx_PyObject_CallMethO(func, args[0]); + } +#endif + #if PY_VERSION_HEX < 0x030800B1 + #if CYTHON_FAST_PYCCALL + if (PyCFunction_Check(func)) { + if (kwargs) { + return _PyCFunction_FastCallDict(func, args, nargs, kwargs); + } else { + return _PyCFunction_FastCallKeywords(func, args, nargs, NULL); + } + } + #if PY_VERSION_HEX >= 0x030700A1 + if (!kwargs && __Pyx_IS_TYPE(func, &PyMethodDescr_Type)) { + return _PyMethodDescr_FastCallKeywords(func, args, nargs, NULL); + } + #endif + #endif + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(func)) { + return __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs); + } + #endif + #endif + if (kwargs == NULL) { + #if CYTHON_VECTORCALL + #if PY_VERSION_HEX < 0x03090000 + vectorcallfunc f = _PyVectorcall_Function(func); + #else + vectorcallfunc f = PyVectorcall_Function(func); + #endif + if (f) { + return f(func, args, (size_t)nargs, NULL); + } + #elif defined(__Pyx_CyFunction_USED) && CYTHON_BACKPORT_VECTORCALL + if (__Pyx_CyFunction_CheckExact(func)) { + __pyx_vectorcallfunc f = __Pyx_CyFunction_func_vectorcall(func); + if (f) return f(func, args, (size_t)nargs, NULL); + } + #endif + } + if (nargs == 0) { + return __Pyx_PyObject_Call(func, __pyx_empty_tuple, kwargs); + } + #if PY_VERSION_HEX >= 0x03090000 && !CYTHON_COMPILING_IN_LIMITED_API + return PyObject_VectorcallDict(func, args, (size_t)nargs, kwargs); + #else + return __Pyx_PyObject_FastCall_fallback(func, args, (size_t)nargs, kwargs); + #endif +} + +/* KeywordStringCheck */ +static int __Pyx_CheckKeywordStrings( + PyObject *kw, + const char* function_name, + int kw_allowed) +{ + PyObject* key = 0; + Py_ssize_t pos = 0; +#if CYTHON_COMPILING_IN_PYPY + if (!kw_allowed && PyDict_Next(kw, &pos, &key, 0)) + goto invalid_keyword; + return 1; +#else + if (CYTHON_METH_FASTCALL && likely(PyTuple_Check(kw))) { + Py_ssize_t kwsize; +#if CYTHON_ASSUME_SAFE_MACROS + kwsize = PyTuple_GET_SIZE(kw); +#else + kwsize = PyTuple_Size(kw); + if (kwsize < 0) return 0; +#endif + if (unlikely(kwsize == 0)) + return 1; + if (!kw_allowed) { +#if CYTHON_ASSUME_SAFE_MACROS + key = PyTuple_GET_ITEM(kw, 0); +#else + key = PyTuple_GetItem(kw, pos); + if (!key) return 0; +#endif + goto invalid_keyword; + } +#if PY_VERSION_HEX < 0x03090000 + for (pos = 0; pos < kwsize; pos++) { +#if CYTHON_ASSUME_SAFE_MACROS + key = PyTuple_GET_ITEM(kw, pos); +#else + key = PyTuple_GetItem(kw, pos); + if (!key) return 0; +#endif + if (unlikely(!PyUnicode_Check(key))) + goto invalid_keyword_type; + } +#endif + return 1; + } + while (PyDict_Next(kw, &pos, &key, 0)) { + #if PY_MAJOR_VERSION < 3 + if (unlikely(!PyString_Check(key))) + #endif + if (unlikely(!PyUnicode_Check(key))) + goto invalid_keyword_type; + } + if (!kw_allowed && unlikely(key)) + goto invalid_keyword; + return 1; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + return 0; +#endif +invalid_keyword: + #if PY_MAJOR_VERSION < 3 + PyErr_Format(PyExc_TypeError, + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + PyErr_Format(PyExc_TypeError, + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif + return 0; +} + +/* PyErrExceptionMatches */ +#if CYTHON_FAST_THREAD_STATE +static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; i= 0x030C00A6 + PyObject *current_exception = tstate->current_exception; + if (unlikely(!current_exception)) return 0; + exc_type = (PyObject*) Py_TYPE(current_exception); + if (exc_type == err) return 1; +#else + exc_type = tstate->curexc_type; + if (exc_type == err) return 1; + if (unlikely(!exc_type)) return 0; +#endif + #if CYTHON_AVOID_BORROWED_REFS + Py_INCREF(exc_type); + #endif + if (unlikely(PyTuple_Check(err))) { + result = __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); + } else { + result = __Pyx_PyErr_GivenExceptionMatches(exc_type, err); + } + #if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(exc_type); + #endif + return result; +} +#endif + +/* PyErrFetchRestore */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { +#if PY_VERSION_HEX >= 0x030C00A6 + PyObject *tmp_value; + assert(type == NULL || (value != NULL && type == (PyObject*) Py_TYPE(value))); + if (value) { + #if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(((PyBaseExceptionObject*) value)->traceback != tb)) + #endif + PyException_SetTraceback(value, tb); + } + tmp_value = tstate->current_exception; + tstate->current_exception = value; + Py_XDECREF(tmp_value); + Py_XDECREF(type); + Py_XDECREF(tb); +#else + PyObject *tmp_type, *tmp_value, *tmp_tb; + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#endif +} +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { +#if PY_VERSION_HEX >= 0x030C00A6 + PyObject* exc_value; + exc_value = tstate->current_exception; + tstate->current_exception = 0; + *value = exc_value; + *type = NULL; + *tb = NULL; + if (exc_value) { + *type = (PyObject*) Py_TYPE(exc_value); + Py_INCREF(*type); + #if CYTHON_COMPILING_IN_CPYTHON + *tb = ((PyBaseExceptionObject*) exc_value)->traceback; + Py_XINCREF(*tb); + #else + *tb = PyException_GetTraceback(exc_value); + #endif + } +#else + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +#endif +} +#endif + +/* PyObjectGetAttrStrNoError */ +#if __PYX_LIMITED_VERSION_HEX < 0x030d00A1 +static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + __Pyx_PyErr_Clear(); +} +#endif +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { + PyObject *result; +#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1 + (void) PyObject_GetOptionalAttr(obj, attr_name, &result); + return result; +#else +#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { + return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); + } +#endif + result = __Pyx_PyObject_GetAttrStr(obj, attr_name); + if (unlikely(!result)) { + __Pyx_PyObject_GetAttrStr_ClearAttributeError(); + } + return result; +#endif +} + +/* GetBuiltinName */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name) { + PyObject* result = __Pyx_PyObject_GetAttrStrNoError(__pyx_b, name); + if (unlikely(!result) && !PyErr_Occurred()) { + PyErr_Format(PyExc_NameError, +#if PY_MAJOR_VERSION >= 3 + "name '%U' is not defined", name); +#else + "name '%.200s' is not defined", PyString_AS_STRING(name)); +#endif + } + return result; +} + +/* PyDictVersioning */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { + PyObject **dictptr = NULL; + Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; + if (offset) { +#if CYTHON_COMPILING_IN_CPYTHON + dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); +#else + dictptr = _PyObject_GetDictPtr(obj); +#endif + } + return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; +} +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) + return 0; + return obj_dict_version == __Pyx_get_object_dict_version(obj); +} +#endif + +/* GetModuleGlobalName */ +#if CYTHON_USE_DICT_VERSIONS +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) +#else +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) +#endif +{ + PyObject *result; +#if !CYTHON_AVOID_BORROWED_REFS +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && PY_VERSION_HEX < 0x030d0000 + result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } else if (unlikely(PyErr_Occurred())) { + return NULL; + } +#elif CYTHON_COMPILING_IN_LIMITED_API + if (unlikely(!__pyx_m)) { + return NULL; + } + result = PyObject_GetAttr(__pyx_m, name); + if (likely(result)) { + return result; + } +#else + result = PyDict_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } +#endif +#else + result = PyObject_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } + PyErr_Clear(); +#endif + return __Pyx_GetBuiltinName(name); +} + +/* GetTopmostException */ +#if CYTHON_USE_EXC_INFO_STACK && CYTHON_FAST_THREAD_STATE +static _PyErr_StackItem * +__Pyx_PyErr_GetTopmostException(PyThreadState *tstate) +{ + _PyErr_StackItem *exc_info = tstate->exc_info; + while ((exc_info->exc_value == NULL || exc_info->exc_value == Py_None) && + exc_info->previous_item != NULL) + { + exc_info = exc_info->previous_item; + } + return exc_info; +} +#endif + +/* SaveResetException */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4 + _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); + PyObject *exc_value = exc_info->exc_value; + if (exc_value == NULL || exc_value == Py_None) { + *value = NULL; + *type = NULL; + *tb = NULL; + } else { + *value = exc_value; + Py_INCREF(*value); + *type = (PyObject*) Py_TYPE(exc_value); + Py_INCREF(*type); + *tb = PyException_GetTraceback(exc_value); + } + #elif CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); + *type = exc_info->exc_type; + *value = exc_info->exc_value; + *tb = exc_info->exc_traceback; + Py_XINCREF(*type); + Py_XINCREF(*value); + Py_XINCREF(*tb); + #else + *type = tstate->exc_type; + *value = tstate->exc_value; + *tb = tstate->exc_traceback; + Py_XINCREF(*type); + Py_XINCREF(*value); + Py_XINCREF(*tb); + #endif +} +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { + #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4 + _PyErr_StackItem *exc_info = tstate->exc_info; + PyObject *tmp_value = exc_info->exc_value; + exc_info->exc_value = value; + Py_XDECREF(tmp_value); + Py_XDECREF(type); + Py_XDECREF(tb); + #else + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = type; + exc_info->exc_value = value; + exc_info->exc_traceback = tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = type; + tstate->exc_value = value; + tstate->exc_traceback = tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); + #endif +} +#endif + +/* FastTypeChecks */ +#if CYTHON_COMPILING_IN_CPYTHON +static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { + while (a) { + a = __Pyx_PyType_GetSlot(a, tp_base, PyTypeObject*); + if (a == b) + return 1; + } + return b == &PyBaseObject_Type; +} +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { + PyObject *mro; + if (a == b) return 1; + mro = a->tp_mro; + if (likely(mro)) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) + return 1; + } + return 0; + } + return __Pyx_InBases(a, b); +} +static CYTHON_INLINE int __Pyx_IsAnySubtype2(PyTypeObject *cls, PyTypeObject *a, PyTypeObject *b) { + PyObject *mro; + if (cls == a || cls == b) return 1; + mro = cls->tp_mro; + if (likely(mro)) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + PyObject *base = PyTuple_GET_ITEM(mro, i); + if (base == (PyObject *)a || base == (PyObject *)b) + return 1; + } + return 0; + } + return __Pyx_InBases(cls, a) || __Pyx_InBases(cls, b); +} +#if PY_MAJOR_VERSION == 2 +static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { + PyObject *exception, *value, *tb; + int res; + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&exception, &value, &tb); + res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + if (!res) { + res = PyObject_IsSubclass(err, exc_type2); + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + } + __Pyx_ErrRestore(exception, value, tb); + return res; +} +#else +static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { + if (exc_type1) { + return __Pyx_IsAnySubtype2((PyTypeObject*)err, (PyTypeObject*)exc_type1, (PyTypeObject*)exc_type2); + } else { + return __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); + } +} +#endif +static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + assert(PyExceptionClass_Check(exc_type)); + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; i= 0x030C00A6 + local_value = tstate->current_exception; + tstate->current_exception = 0; + if (likely(local_value)) { + local_type = (PyObject*) Py_TYPE(local_value); + Py_INCREF(local_type); + local_tb = PyException_GetTraceback(local_value); + } + #else + local_type = tstate->curexc_type; + local_value = tstate->curexc_value; + local_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; + #endif +#else + PyErr_Fetch(&local_type, &local_value, &local_tb); +#endif + PyErr_NormalizeException(&local_type, &local_value, &local_tb); +#if CYTHON_FAST_THREAD_STATE && PY_VERSION_HEX >= 0x030C00A6 + if (unlikely(tstate->current_exception)) +#elif CYTHON_FAST_THREAD_STATE + if (unlikely(tstate->curexc_type)) +#else + if (unlikely(PyErr_Occurred())) +#endif + goto bad; + #if PY_MAJOR_VERSION >= 3 + if (local_tb) { + if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) + goto bad; + } + #endif + Py_XINCREF(local_tb); + Py_XINCREF(local_type); + Py_XINCREF(local_value); + *type = local_type; + *value = local_value; + *tb = local_tb; +#if CYTHON_FAST_THREAD_STATE + #if CYTHON_USE_EXC_INFO_STACK + { + _PyErr_StackItem *exc_info = tstate->exc_info; + #if PY_VERSION_HEX >= 0x030B00a4 + tmp_value = exc_info->exc_value; + exc_info->exc_value = local_value; + tmp_type = NULL; + tmp_tb = NULL; + Py_XDECREF(local_type); + Py_XDECREF(local_tb); + #else + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = local_type; + exc_info->exc_value = local_value; + exc_info->exc_traceback = local_tb; + #endif + } + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = local_type; + tstate->exc_value = local_value; + tstate->exc_traceback = local_tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#else + PyErr_SetExcInfo(local_type, local_value, local_tb); +#endif + return 0; +bad: + *type = 0; + *value = 0; + *tb = 0; + Py_XDECREF(local_type); + Py_XDECREF(local_value); + Py_XDECREF(local_tb); + return -1; +} + +/* SwapException */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4 + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_value = exc_info->exc_value; + exc_info->exc_value = *value; + if (tmp_value == NULL || tmp_value == Py_None) { + Py_XDECREF(tmp_value); + tmp_value = NULL; + tmp_type = NULL; + tmp_tb = NULL; + } else { + tmp_type = (PyObject*) Py_TYPE(tmp_value); + Py_INCREF(tmp_type); + #if CYTHON_COMPILING_IN_CPYTHON + tmp_tb = ((PyBaseExceptionObject*) tmp_value)->traceback; + Py_XINCREF(tmp_tb); + #else + tmp_tb = PyException_GetTraceback(tmp_value); + #endif + } + #elif CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = *type; + exc_info->exc_value = *value; + exc_info->exc_traceback = *tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = *type; + tstate->exc_value = *value; + tstate->exc_traceback = *tb; + #endif + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb); + PyErr_SetExcInfo(*type, *value, *tb); + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#endif + +/* RaiseUnexpectedTypeError */ +static int +__Pyx_RaiseUnexpectedTypeError(const char *expected, PyObject *obj) +{ + __Pyx_TypeName obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj)); + PyErr_Format(PyExc_TypeError, "Expected %s, got " __Pyx_FMT_TYPENAME, + expected, obj_type_name); + __Pyx_DECREF_TypeName(obj_type_name); + return 0; +} + +/* GetAttr3 */ +#if __PYX_LIMITED_VERSION_HEX < 0x030d00A1 +static PyObject *__Pyx_GetAttr3Default(PyObject *d) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (unlikely(!__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + return NULL; + __Pyx_PyErr_Clear(); + Py_INCREF(d); + return d; +} +#endif +static CYTHON_INLINE PyObject *__Pyx_GetAttr3(PyObject *o, PyObject *n, PyObject *d) { + PyObject *r; +#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1 + int res = PyObject_GetOptionalAttr(o, n, &r); + return (res != 0) ? r : __Pyx_NewRef(d); +#else + #if CYTHON_USE_TYPE_SLOTS + if (likely(PyString_Check(n))) { + r = __Pyx_PyObject_GetAttrStrNoError(o, n); + if (unlikely(!r) && likely(!PyErr_Occurred())) { + r = __Pyx_NewRef(d); + } + return r; + } + #endif + r = PyObject_GetAttr(o, n); + return (likely(r)) ? r : __Pyx_GetAttr3Default(d); +#endif +} + +/* JoinPyUnicode */ +static PyObject* __Pyx_PyUnicode_Join(PyObject* value_tuple, Py_ssize_t value_count, Py_ssize_t result_ulength, + Py_UCS4 max_char) { +#if CYTHON_USE_UNICODE_INTERNALS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + PyObject *result_uval; + int result_ukind, kind_shift; + Py_ssize_t i, char_pos; + void *result_udata; + CYTHON_MAYBE_UNUSED_VAR(max_char); +#if CYTHON_PEP393_ENABLED + result_uval = PyUnicode_New(result_ulength, max_char); + if (unlikely(!result_uval)) return NULL; + result_ukind = (max_char <= 255) ? PyUnicode_1BYTE_KIND : (max_char <= 65535) ? PyUnicode_2BYTE_KIND : PyUnicode_4BYTE_KIND; + kind_shift = (result_ukind == PyUnicode_4BYTE_KIND) ? 2 : result_ukind - 1; + result_udata = PyUnicode_DATA(result_uval); +#else + result_uval = PyUnicode_FromUnicode(NULL, result_ulength); + if (unlikely(!result_uval)) return NULL; + result_ukind = sizeof(Py_UNICODE); + kind_shift = (result_ukind == 4) ? 2 : result_ukind - 1; + result_udata = PyUnicode_AS_UNICODE(result_uval); +#endif + assert(kind_shift == 2 || kind_shift == 1 || kind_shift == 0); + char_pos = 0; + for (i=0; i < value_count; i++) { + int ukind; + Py_ssize_t ulength; + void *udata; + PyObject *uval = PyTuple_GET_ITEM(value_tuple, i); + if (unlikely(__Pyx_PyUnicode_READY(uval))) + goto bad; + ulength = __Pyx_PyUnicode_GET_LENGTH(uval); + if (unlikely(!ulength)) + continue; + if (unlikely((PY_SSIZE_T_MAX >> kind_shift) - ulength < char_pos)) + goto overflow; + ukind = __Pyx_PyUnicode_KIND(uval); + udata = __Pyx_PyUnicode_DATA(uval); + if (!CYTHON_PEP393_ENABLED || ukind == result_ukind) { + memcpy((char *)result_udata + (char_pos << kind_shift), udata, (size_t) (ulength << kind_shift)); + } else { + #if PY_VERSION_HEX >= 0x030d0000 + if (unlikely(PyUnicode_CopyCharacters(result_uval, char_pos, uval, 0, ulength) < 0)) goto bad; + #elif CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030300F0 || defined(_PyUnicode_FastCopyCharacters) + _PyUnicode_FastCopyCharacters(result_uval, char_pos, uval, 0, ulength); + #else + Py_ssize_t j; + for (j=0; j < ulength; j++) { + Py_UCS4 uchar = __Pyx_PyUnicode_READ(ukind, udata, j); + __Pyx_PyUnicode_WRITE(result_ukind, result_udata, char_pos+j, uchar); + } + #endif + } + char_pos += ulength; + } + return result_uval; +overflow: + PyErr_SetString(PyExc_OverflowError, "join() result is too long for a Python string"); +bad: + Py_DECREF(result_uval); + return NULL; +#else + CYTHON_UNUSED_VAR(max_char); + CYTHON_UNUSED_VAR(result_ulength); + CYTHON_UNUSED_VAR(value_count); + return PyUnicode_Join(__pyx_empty_unicode, value_tuple); +#endif +} + +/* UnpackUnboundCMethod */ +static PyObject *__Pyx_SelflessCall(PyObject *method, PyObject *args, PyObject *kwargs) { + PyObject *result; + PyObject *selfless_args = PyTuple_GetSlice(args, 1, PyTuple_Size(args)); + if (unlikely(!selfless_args)) return NULL; + result = PyObject_Call(method, selfless_args, kwargs); + Py_DECREF(selfless_args); + return result; +} +static PyMethodDef __Pyx_UnboundCMethod_Def = { + "CythonUnboundCMethod", + __PYX_REINTERPRET_FUNCION(PyCFunction, __Pyx_SelflessCall), + METH_VARARGS | METH_KEYWORDS, + NULL +}; +static int __Pyx_TryUnpackUnboundCMethod(__Pyx_CachedCFunction* target) { + PyObject *method; + method = __Pyx_PyObject_GetAttrStr(target->type, *target->method_name); + if (unlikely(!method)) + return -1; + target->method = method; +#if CYTHON_COMPILING_IN_CPYTHON + #if PY_MAJOR_VERSION >= 3 + if (likely(__Pyx_TypeCheck(method, &PyMethodDescr_Type))) + #else + if (likely(!__Pyx_CyOrPyCFunction_Check(method))) + #endif + { + PyMethodDescrObject *descr = (PyMethodDescrObject*) method; + target->func = descr->d_method->ml_meth; + target->flag = descr->d_method->ml_flags & ~(METH_CLASS | METH_STATIC | METH_COEXIST | METH_STACKLESS); + } else +#endif +#if CYTHON_COMPILING_IN_PYPY +#else + if (PyCFunction_Check(method)) +#endif + { + PyObject *self; + int self_found; +#if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_PYPY + self = PyObject_GetAttrString(method, "__self__"); + if (!self) { + PyErr_Clear(); + } +#else + self = PyCFunction_GET_SELF(method); +#endif + self_found = (self && self != Py_None); +#if CYTHON_COMPILING_IN_LIMITED_API || CYTHON_COMPILING_IN_PYPY + Py_XDECREF(self); +#endif + if (self_found) { + PyObject *unbound_method = PyCFunction_New(&__Pyx_UnboundCMethod_Def, method); + if (unlikely(!unbound_method)) return -1; + Py_DECREF(method); + target->method = unbound_method; + } + } + return 0; +} + +/* CallUnboundCMethod1 */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg) { + if (likely(cfunc->func)) { + int flag = cfunc->flag; + if (flag == METH_O) { + return (*(cfunc->func))(self, arg); + } else if ((PY_VERSION_HEX >= 0x030600B1) && flag == METH_FASTCALL) { + #if PY_VERSION_HEX >= 0x030700A0 + return (*(__Pyx_PyCFunctionFast)(void*)(PyCFunction)cfunc->func)(self, &arg, 1); + #else + return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL); + #endif + } else if ((PY_VERSION_HEX >= 0x030700A0) && flag == (METH_FASTCALL | METH_KEYWORDS)) { + return (*(__Pyx_PyCFunctionFastWithKeywords)(void*)(PyCFunction)cfunc->func)(self, &arg, 1, NULL); + } + } + return __Pyx__CallUnboundCMethod1(cfunc, self, arg); +} +#endif +static PyObject* __Pyx__CallUnboundCMethod1(__Pyx_CachedCFunction* cfunc, PyObject* self, PyObject* arg){ + PyObject *args, *result = NULL; + if (unlikely(!cfunc->func && !cfunc->method) && unlikely(__Pyx_TryUnpackUnboundCMethod(cfunc) < 0)) return NULL; +#if CYTHON_COMPILING_IN_CPYTHON + if (cfunc->func && (cfunc->flag & METH_VARARGS)) { + args = PyTuple_New(1); + if (unlikely(!args)) goto bad; + Py_INCREF(arg); + PyTuple_SET_ITEM(args, 0, arg); + if (cfunc->flag & METH_KEYWORDS) + result = (*(PyCFunctionWithKeywords)(void*)(PyCFunction)cfunc->func)(self, args, NULL); + else + result = (*cfunc->func)(self, args); + } else { + args = PyTuple_New(2); + if (unlikely(!args)) goto bad; + Py_INCREF(self); + PyTuple_SET_ITEM(args, 0, self); + Py_INCREF(arg); + PyTuple_SET_ITEM(args, 1, arg); + result = __Pyx_PyObject_Call(cfunc->method, args, NULL); + } +#else + args = PyTuple_Pack(2, self, arg); + if (unlikely(!args)) goto bad; + result = __Pyx_PyObject_Call(cfunc->method, args, NULL); +#endif +bad: + Py_XDECREF(args); + return result; +} + +/* DictGetItem */ +#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY +static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { + PyObject *value; + value = PyDict_GetItemWithError(d, key); + if (unlikely(!value)) { + if (!PyErr_Occurred()) { + if (unlikely(PyTuple_Check(key))) { + PyObject* args = PyTuple_Pack(1, key); + if (likely(args)) { + PyErr_SetObject(PyExc_KeyError, args); + Py_DECREF(args); + } + } else { + PyErr_SetObject(PyExc_KeyError, key); + } + } + return NULL; + } + Py_INCREF(value); + return value; +} +#endif + +/* CIntToDigits */ +static const char DIGIT_PAIRS_10[2*10*10+1] = { + "00010203040506070809" + "10111213141516171819" + "20212223242526272829" + "30313233343536373839" + "40414243444546474849" + "50515253545556575859" + "60616263646566676869" + "70717273747576777879" + "80818283848586878889" + "90919293949596979899" +}; +static const char DIGIT_PAIRS_8[2*8*8+1] = { + "0001020304050607" + "1011121314151617" + "2021222324252627" + "3031323334353637" + "4041424344454647" + "5051525354555657" + "6061626364656667" + "7071727374757677" +}; +static const char DIGITS_HEX[2*16+1] = { + "0123456789abcdef" + "0123456789ABCDEF" +}; + +/* BuildPyUnicode */ +static PyObject* __Pyx_PyUnicode_BuildFromAscii(Py_ssize_t ulength, char* chars, int clength, + int prepend_sign, char padding_char) { + PyObject *uval; + Py_ssize_t uoffset = ulength - clength; +#if CYTHON_USE_UNICODE_INTERNALS + Py_ssize_t i; +#if CYTHON_PEP393_ENABLED + void *udata; + uval = PyUnicode_New(ulength, 127); + if (unlikely(!uval)) return NULL; + udata = PyUnicode_DATA(uval); +#else + Py_UNICODE *udata; + uval = PyUnicode_FromUnicode(NULL, ulength); + if (unlikely(!uval)) return NULL; + udata = PyUnicode_AS_UNICODE(uval); +#endif + if (uoffset > 0) { + i = 0; + if (prepend_sign) { + __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, 0, '-'); + i++; + } + for (; i < uoffset; i++) { + __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, i, padding_char); + } + } + for (i=0; i < clength; i++) { + __Pyx_PyUnicode_WRITE(PyUnicode_1BYTE_KIND, udata, uoffset+i, chars[i]); + } +#else + { + PyObject *sign = NULL, *padding = NULL; + uval = NULL; + if (uoffset > 0) { + prepend_sign = !!prepend_sign; + if (uoffset > prepend_sign) { + padding = PyUnicode_FromOrdinal(padding_char); + if (likely(padding) && uoffset > prepend_sign + 1) { + PyObject *tmp; + PyObject *repeat = PyInt_FromSsize_t(uoffset - prepend_sign); + if (unlikely(!repeat)) goto done_or_error; + tmp = PyNumber_Multiply(padding, repeat); + Py_DECREF(repeat); + Py_DECREF(padding); + padding = tmp; + } + if (unlikely(!padding)) goto done_or_error; + } + if (prepend_sign) { + sign = PyUnicode_FromOrdinal('-'); + if (unlikely(!sign)) goto done_or_error; + } + } + uval = PyUnicode_DecodeASCII(chars, clength, NULL); + if (likely(uval) && padding) { + PyObject *tmp = PyNumber_Add(padding, uval); + Py_DECREF(uval); + uval = tmp; + } + if (likely(uval) && sign) { + PyObject *tmp = PyNumber_Add(sign, uval); + Py_DECREF(uval); + uval = tmp; + } +done_or_error: + Py_XDECREF(padding); + Py_XDECREF(sign); + } +#endif + return uval; +} + +/* CIntToPyUnicode */ +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_int(int value, Py_ssize_t width, char padding_char, char format_char) { + char digits[sizeof(int)*3+2]; + char *dpos, *end = digits + sizeof(int)*3+2; + const char *hex_digits = DIGITS_HEX; + Py_ssize_t length, ulength; + int prepend_sign, last_one_off; + int remaining; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const int neg_one = (int) -1, const_zero = (int) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (format_char == 'X') { + hex_digits += 16; + format_char = 'x'; + } + remaining = value; + last_one_off = 0; + dpos = end; + do { + int digit_pos; + switch (format_char) { + case 'o': + digit_pos = abs((int)(remaining % (8*8))); + remaining = (int) (remaining / (8*8)); + dpos -= 2; + memcpy(dpos, DIGIT_PAIRS_8 + digit_pos * 2, 2); + last_one_off = (digit_pos < 8); + break; + case 'd': + digit_pos = abs((int)(remaining % (10*10))); + remaining = (int) (remaining / (10*10)); + dpos -= 2; + memcpy(dpos, DIGIT_PAIRS_10 + digit_pos * 2, 2); + last_one_off = (digit_pos < 10); + break; + case 'x': + *(--dpos) = hex_digits[abs((int)(remaining % 16))]; + remaining = (int) (remaining / 16); + break; + default: + assert(0); + break; + } + } while (unlikely(remaining != 0)); + assert(!last_one_off || *dpos == '0'); + dpos += last_one_off; + length = end - dpos; + ulength = length; + prepend_sign = 0; + if (!is_unsigned && value <= neg_one) { + if (padding_char == ' ' || width <= length + 1) { + *(--dpos) = '-'; + ++length; + } else { + prepend_sign = 1; + } + ++ulength; + } + if (width > ulength) { + ulength = width; + } + if (ulength == 1) { + return PyUnicode_FromOrdinal(*dpos); + } + return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char); +} + +/* CIntToPyUnicode */ +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_From_Py_ssize_t(Py_ssize_t value, Py_ssize_t width, char padding_char, char format_char) { + char digits[sizeof(Py_ssize_t)*3+2]; + char *dpos, *end = digits + sizeof(Py_ssize_t)*3+2; + const char *hex_digits = DIGITS_HEX; + Py_ssize_t length, ulength; + int prepend_sign, last_one_off; + Py_ssize_t remaining; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const Py_ssize_t neg_one = (Py_ssize_t) -1, const_zero = (Py_ssize_t) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (format_char == 'X') { + hex_digits += 16; + format_char = 'x'; + } + remaining = value; + last_one_off = 0; + dpos = end; + do { + int digit_pos; + switch (format_char) { + case 'o': + digit_pos = abs((int)(remaining % (8*8))); + remaining = (Py_ssize_t) (remaining / (8*8)); + dpos -= 2; + memcpy(dpos, DIGIT_PAIRS_8 + digit_pos * 2, 2); + last_one_off = (digit_pos < 8); + break; + case 'd': + digit_pos = abs((int)(remaining % (10*10))); + remaining = (Py_ssize_t) (remaining / (10*10)); + dpos -= 2; + memcpy(dpos, DIGIT_PAIRS_10 + digit_pos * 2, 2); + last_one_off = (digit_pos < 10); + break; + case 'x': + *(--dpos) = hex_digits[abs((int)(remaining % 16))]; + remaining = (Py_ssize_t) (remaining / 16); + break; + default: + assert(0); + break; + } + } while (unlikely(remaining != 0)); + assert(!last_one_off || *dpos == '0'); + dpos += last_one_off; + length = end - dpos; + ulength = length; + prepend_sign = 0; + if (!is_unsigned && value <= neg_one) { + if (padding_char == ' ' || width <= length + 1) { + *(--dpos) = '-'; + ++length; + } else { + prepend_sign = 1; + } + ++ulength; + } + if (width > ulength) { + ulength = width; + } + if (ulength == 1) { + return PyUnicode_FromOrdinal(*dpos); + } + return __Pyx_PyUnicode_BuildFromAscii(ulength, dpos, (int) length, prepend_sign, padding_char); +} + +/* GetItemInt */ +static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { + PyObject *r; + if (unlikely(!j)) return NULL; + r = PyObject_GetItem(o, j); + Py_DECREF(j); + return r; +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + Py_ssize_t wrapped_i = i; + if (wraparound & unlikely(i < 0)) { + wrapped_i += PyList_GET_SIZE(o); + } + if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, wrapped_i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + Py_ssize_t wrapped_i = i; + if (wraparound & unlikely(i < 0)) { + wrapped_i += PyTuple_GET_SIZE(o); + } + if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, wrapped_i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS + if (is_list || PyList_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); + if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) { + PyObject *r = PyList_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } + else if (PyTuple_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); + if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } else { + PyMappingMethods *mm = Py_TYPE(o)->tp_as_mapping; + PySequenceMethods *sm = Py_TYPE(o)->tp_as_sequence; + if (mm && mm->mp_subscript) { + PyObject *r, *key = PyInt_FromSsize_t(i); + if (unlikely(!key)) return NULL; + r = mm->mp_subscript(o, key); + Py_DECREF(key); + return r; + } + if (likely(sm && sm->sq_item)) { + if (wraparound && unlikely(i < 0) && likely(sm->sq_length)) { + Py_ssize_t l = sm->sq_length(o); + if (likely(l >= 0)) { + i += l; + } else { + if (!PyErr_ExceptionMatches(PyExc_OverflowError)) + return NULL; + PyErr_Clear(); + } + } + return sm->sq_item(o, i); + } + } +#else + if (is_list || !PyMapping_Check(o)) { + return PySequence_GetItem(o, i); + } +#endif + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} + +/* PyIntBinop */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) { + CYTHON_MAYBE_UNUSED_VAR(intval); + CYTHON_MAYBE_UNUSED_VAR(inplace); + CYTHON_UNUSED_VAR(zerodivision_check); + #if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(op1))) { + const long b = intval; + long x; + long a = PyInt_AS_LONG(op1); + + x = (long)((unsigned long)a + (unsigned long)b); + if (likely((x^a) >= 0 || (x^b) >= 0)) + return PyInt_FromLong(x); + return PyLong_Type.tp_as_number->nb_add(op1, op2); + } + #endif + #if CYTHON_USE_PYLONG_INTERNALS + if (likely(PyLong_CheckExact(op1))) { + const long b = intval; + long a, x; +#ifdef HAVE_LONG_LONG + const PY_LONG_LONG llb = intval; + PY_LONG_LONG lla, llx; +#endif + if (unlikely(__Pyx_PyLong_IsZero(op1))) { + return __Pyx_NewRef(op2); + } + if (likely(__Pyx_PyLong_IsCompact(op1))) { + a = __Pyx_PyLong_CompactValue(op1); + } else { + const digit* digits = __Pyx_PyLong_Digits(op1); + const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount(op1); + switch (size) { + case -2: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + #ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; + #endif + } + CYTHON_FALLTHROUGH; + case 2: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + #ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; + #endif + } + CYTHON_FALLTHROUGH; + case -3: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + #ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; + #endif + } + CYTHON_FALLTHROUGH; + case 3: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + #ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; + #endif + } + CYTHON_FALLTHROUGH; + case -4: + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + #ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; + #endif + } + CYTHON_FALLTHROUGH; + case 4: + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + #ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; + #endif + } + CYTHON_FALLTHROUGH; + default: return PyLong_Type.tp_as_number->nb_add(op1, op2); + } + } + x = a + b; + return PyLong_FromLong(x); +#ifdef HAVE_LONG_LONG + long_long: + llx = lla + llb; + return PyLong_FromLongLong(llx); +#endif + + + } + #endif + if (PyFloat_CheckExact(op1)) { + const long b = intval; +#if CYTHON_COMPILING_IN_LIMITED_API + double a = __pyx_PyFloat_AsDouble(op1); +#else + double a = PyFloat_AS_DOUBLE(op1); +#endif + double result; + + PyFPE_START_PROTECT("add", return NULL) + result = ((double)a) + (double)b; + PyFPE_END_PROTECT(result) + return PyFloat_FromDouble(result); + } + return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2); +} +#endif + +/* Import */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { + PyObject *module = 0; + PyObject *empty_dict = 0; + PyObject *empty_list = 0; + #if PY_MAJOR_VERSION < 3 + PyObject *py_import; + py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); + if (unlikely(!py_import)) + goto bad; + if (!from_list) { + empty_list = PyList_New(0); + if (unlikely(!empty_list)) + goto bad; + from_list = empty_list; + } + #endif + empty_dict = PyDict_New(); + if (unlikely(!empty_dict)) + goto bad; + { + #if PY_MAJOR_VERSION >= 3 + if (level == -1) { + if (strchr(__Pyx_MODULE_NAME, '.') != NULL) { + module = PyImport_ImportModuleLevelObject( + name, __pyx_d, empty_dict, from_list, 1); + if (unlikely(!module)) { + if (unlikely(!PyErr_ExceptionMatches(PyExc_ImportError))) + goto bad; + PyErr_Clear(); + } + } + level = 0; + } + #endif + if (!module) { + #if PY_MAJOR_VERSION < 3 + PyObject *py_level = PyInt_FromLong(level); + if (unlikely(!py_level)) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, __pyx_d, empty_dict, from_list, py_level, (PyObject *)NULL); + Py_DECREF(py_level); + #else + module = PyImport_ImportModuleLevelObject( + name, __pyx_d, empty_dict, from_list, level); + #endif + } + } +bad: + Py_XDECREF(empty_dict); + Py_XDECREF(empty_list); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(py_import); + #endif + return module; +} + +/* ImportFrom */ +static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) { + PyObject* value = __Pyx_PyObject_GetAttrStr(module, name); + if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) { + const char* module_name_str = 0; + PyObject* module_name = 0; + PyObject* module_dot = 0; + PyObject* full_name = 0; + PyErr_Clear(); + module_name_str = PyModule_GetName(module); + if (unlikely(!module_name_str)) { goto modbad; } + module_name = PyUnicode_FromString(module_name_str); + if (unlikely(!module_name)) { goto modbad; } + module_dot = PyUnicode_Concat(module_name, __pyx_kp_u__5); + if (unlikely(!module_dot)) { goto modbad; } + full_name = PyUnicode_Concat(module_dot, name); + if (unlikely(!full_name)) { goto modbad; } + #if PY_VERSION_HEX < 0x030700A1 || (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM < 0x07030400) + { + PyObject *modules = PyImport_GetModuleDict(); + if (unlikely(!modules)) + goto modbad; + value = PyObject_GetItem(modules, full_name); + } + #else + value = PyImport_GetModule(full_name); + #endif + modbad: + Py_XDECREF(full_name); + Py_XDECREF(module_dot); + Py_XDECREF(module_name); + } + if (unlikely(!value)) { + PyErr_Format(PyExc_ImportError, + #if PY_MAJOR_VERSION < 3 + "cannot import name %.230s", PyString_AS_STRING(name)); + #else + "cannot import name %S", name); + #endif + } + return value; +} + +/* RaiseException */ +#if PY_MAJOR_VERSION < 3 +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + __Pyx_PyThreadState_declare + CYTHON_UNUSED_VAR(cause); + Py_XINCREF(type); + if (!value || value == Py_None) + value = NULL; + else + Py_INCREF(value); + if (!tb || tb == Py_None) + tb = NULL; + else { + Py_INCREF(tb); + if (!PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + } + if (PyType_Check(type)) { +#if CYTHON_COMPILING_IN_PYPY + if (!value) { + Py_INCREF(Py_None); + value = Py_None; + } +#endif + PyErr_NormalizeException(&type, &value, &tb); + } else { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + value = type; + type = (PyObject*) Py_TYPE(type); + Py_INCREF(type); + if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto raise_error; + } + } + __Pyx_PyThreadState_assign + __Pyx_ErrRestore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} +#else +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + PyObject* owned_instance = NULL; + if (tb == Py_None) { + tb = 0; + } else if (tb && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto bad; + } + if (value == Py_None) + value = 0; + if (PyExceptionInstance_Check(type)) { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto bad; + } + value = type; + type = (PyObject*) Py_TYPE(value); + } else if (PyExceptionClass_Check(type)) { + PyObject *instance_class = NULL; + if (value && PyExceptionInstance_Check(value)) { + instance_class = (PyObject*) Py_TYPE(value); + if (instance_class != type) { + int is_subclass = PyObject_IsSubclass(instance_class, type); + if (!is_subclass) { + instance_class = NULL; + } else if (unlikely(is_subclass == -1)) { + goto bad; + } else { + type = instance_class; + } + } + } + if (!instance_class) { + PyObject *args; + if (!value) + args = PyTuple_New(0); + else if (PyTuple_Check(value)) { + Py_INCREF(value); + args = value; + } else + args = PyTuple_Pack(1, value); + if (!args) + goto bad; + owned_instance = PyObject_Call(type, args, NULL); + Py_DECREF(args); + if (!owned_instance) + goto bad; + value = owned_instance; + if (!PyExceptionInstance_Check(value)) { + PyErr_Format(PyExc_TypeError, + "calling %R should have returned an instance of " + "BaseException, not %R", + type, Py_TYPE(value)); + goto bad; + } + } + } else { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto bad; + } + if (cause) { + PyObject *fixed_cause; + if (cause == Py_None) { + fixed_cause = NULL; + } else if (PyExceptionClass_Check(cause)) { + fixed_cause = PyObject_CallObject(cause, NULL); + if (fixed_cause == NULL) + goto bad; + } else if (PyExceptionInstance_Check(cause)) { + fixed_cause = cause; + Py_INCREF(fixed_cause); + } else { + PyErr_SetString(PyExc_TypeError, + "exception causes must derive from " + "BaseException"); + goto bad; + } + PyException_SetCause(value, fixed_cause); + } + PyErr_SetObject(type, value); + if (tb) { + #if PY_VERSION_HEX >= 0x030C00A6 + PyException_SetTraceback(value, tb); + #elif CYTHON_FAST_THREAD_STATE + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject* tmp_tb = tstate->curexc_traceback; + if (tb != tmp_tb) { + Py_INCREF(tb); + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_tb); + } +#else + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); + Py_INCREF(tb); + PyErr_Restore(tmp_type, tmp_value, tb); + Py_XDECREF(tmp_tb); +#endif + } +bad: + Py_XDECREF(owned_instance); + return; +} +#endif + +/* GetAttr */ +static CYTHON_INLINE PyObject *__Pyx_GetAttr(PyObject *o, PyObject *n) { +#if CYTHON_USE_TYPE_SLOTS +#if PY_MAJOR_VERSION >= 3 + if (likely(PyUnicode_Check(n))) +#else + if (likely(PyString_Check(n))) +#endif + return __Pyx_PyObject_GetAttrStr(o, n); +#endif + return PyObject_GetAttr(o, n); +} + +/* HasAttr */ +static CYTHON_INLINE int __Pyx_HasAttr(PyObject *o, PyObject *n) { + PyObject *r; + if (unlikely(!__Pyx_PyBaseString_Check(n))) { + PyErr_SetString(PyExc_TypeError, + "hasattr(): attribute name must be string"); + return -1; + } + r = __Pyx_GetAttr(o, n); + if (!r) { + PyErr_Clear(); + return 0; + } else { + Py_DECREF(r); + return 1; + } +} + +/* FixUpExtensionType */ +#if CYTHON_USE_TYPE_SPECS +static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type) { +#if PY_VERSION_HEX > 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + CYTHON_UNUSED_VAR(spec); + CYTHON_UNUSED_VAR(type); +#else + const PyType_Slot *slot = spec->slots; + while (slot && slot->slot && slot->slot != Py_tp_members) + slot++; + if (slot && slot->slot == Py_tp_members) { + int changed = 0; +#if !(PY_VERSION_HEX <= 0x030900b1 && CYTHON_COMPILING_IN_CPYTHON) + const +#endif + PyMemberDef *memb = (PyMemberDef*) slot->pfunc; + while (memb && memb->name) { + if (memb->name[0] == '_' && memb->name[1] == '_') { +#if PY_VERSION_HEX < 0x030900b1 + if (strcmp(memb->name, "__weaklistoffset__") == 0) { + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); + type->tp_weaklistoffset = memb->offset; + changed = 1; + } + else if (strcmp(memb->name, "__dictoffset__") == 0) { + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); + type->tp_dictoffset = memb->offset; + changed = 1; + } +#if CYTHON_METH_FASTCALL + else if (strcmp(memb->name, "__vectorcalloffset__") == 0) { + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); +#if PY_VERSION_HEX >= 0x030800b4 + type->tp_vectorcall_offset = memb->offset; +#else + type->tp_print = (printfunc) memb->offset; +#endif + changed = 1; + } +#endif +#else + if ((0)); +#endif +#if PY_VERSION_HEX <= 0x030900b1 && CYTHON_COMPILING_IN_CPYTHON + else if (strcmp(memb->name, "__module__") == 0) { + PyObject *descr; + assert(memb->type == T_OBJECT); + assert(memb->flags == 0 || memb->flags == READONLY); + descr = PyDescr_NewMember(type, memb); + if (unlikely(!descr)) + return -1; + if (unlikely(PyDict_SetItem(type->tp_dict, PyDescr_NAME(descr), descr) < 0)) { + Py_DECREF(descr); + return -1; + } + Py_DECREF(descr); + changed = 1; + } +#endif + } + memb++; + } + if (changed) + PyType_Modified(type); + } +#endif + return 0; +} +#endif + +/* PyObjectCallNoArg */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { + PyObject *arg[2] = {NULL, NULL}; + return __Pyx_PyObject_FastCall(func, arg + 1, 0 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET); +} + +/* PyObjectCallOneArg */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { + PyObject *args[2] = {NULL, arg}; + return __Pyx_PyObject_FastCall(func, args+1, 1 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET); +} + +/* PyObjectGetMethod */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) { + PyObject *attr; +#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP + __Pyx_TypeName type_name; + PyTypeObject *tp = Py_TYPE(obj); + PyObject *descr; + descrgetfunc f = NULL; + PyObject **dictptr, *dict; + int meth_found = 0; + assert (*method == NULL); + if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) { + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; + } + if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) { + return 0; + } + descr = _PyType_Lookup(tp, name); + if (likely(descr != NULL)) { + Py_INCREF(descr); +#if defined(Py_TPFLAGS_METHOD_DESCRIPTOR) && Py_TPFLAGS_METHOD_DESCRIPTOR + if (__Pyx_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR)) +#elif PY_MAJOR_VERSION >= 3 + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type))) + #endif +#else + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr))) + #endif +#endif + { + meth_found = 1; + } else { + f = Py_TYPE(descr)->tp_descr_get; + if (f != NULL && PyDescr_IsData(descr)) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + } + } + dictptr = _PyObject_GetDictPtr(obj); + if (dictptr != NULL && (dict = *dictptr) != NULL) { + Py_INCREF(dict); + attr = __Pyx_PyDict_GetItemStr(dict, name); + if (attr != NULL) { + Py_INCREF(attr); + Py_DECREF(dict); + Py_XDECREF(descr); + goto try_unpack; + } + Py_DECREF(dict); + } + if (meth_found) { + *method = descr; + return 1; + } + if (f != NULL) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + if (likely(descr != NULL)) { + *method = descr; + return 0; + } + type_name = __Pyx_PyType_GetName(tp); + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%U'", + type_name, name); +#else + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%.400s'", + type_name, PyString_AS_STRING(name)); +#endif + __Pyx_DECREF_TypeName(type_name); + return 0; +#else + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; +#endif +try_unpack: +#if CYTHON_UNPACK_METHODS + if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) { + PyObject *function = PyMethod_GET_FUNCTION(attr); + Py_INCREF(function); + Py_DECREF(attr); + *method = function; + return 1; + } +#endif + *method = attr; + return 0; +} + +/* PyObjectCallMethod0 */ +static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) { + PyObject *method = NULL, *result = NULL; + int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); + if (likely(is_method)) { + result = __Pyx_PyObject_CallOneArg(method, obj); + Py_DECREF(method); + return result; + } + if (unlikely(!method)) goto bad; + result = __Pyx_PyObject_CallNoArg(method); + Py_DECREF(method); +bad: + return result; +} + +/* ValidateBasesTuple */ +#if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS +static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases) { + Py_ssize_t i, n; +#if CYTHON_ASSUME_SAFE_MACROS + n = PyTuple_GET_SIZE(bases); +#else + n = PyTuple_Size(bases); + if (n < 0) return -1; +#endif + for (i = 1; i < n; i++) + { +#if CYTHON_AVOID_BORROWED_REFS + PyObject *b0 = PySequence_GetItem(bases, i); + if (!b0) return -1; +#elif CYTHON_ASSUME_SAFE_MACROS + PyObject *b0 = PyTuple_GET_ITEM(bases, i); +#else + PyObject *b0 = PyTuple_GetItem(bases, i); + if (!b0) return -1; +#endif + PyTypeObject *b; +#if PY_MAJOR_VERSION < 3 + if (PyClass_Check(b0)) + { + PyErr_Format(PyExc_TypeError, "base class '%.200s' is an old-style class", + PyString_AS_STRING(((PyClassObject*)b0)->cl_name)); +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + return -1; + } +#endif + b = (PyTypeObject*) b0; + if (!__Pyx_PyType_HasFeature(b, Py_TPFLAGS_HEAPTYPE)) + { + __Pyx_TypeName b_name = __Pyx_PyType_GetName(b); + PyErr_Format(PyExc_TypeError, + "base class '" __Pyx_FMT_TYPENAME "' is not a heap type", b_name); + __Pyx_DECREF_TypeName(b_name); +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + return -1; + } + if (dictoffset == 0) + { + Py_ssize_t b_dictoffset = 0; +#if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY + b_dictoffset = b->tp_dictoffset; +#else + PyObject *py_b_dictoffset = PyObject_GetAttrString((PyObject*)b, "__dictoffset__"); + if (!py_b_dictoffset) goto dictoffset_return; + b_dictoffset = PyLong_AsSsize_t(py_b_dictoffset); + Py_DECREF(py_b_dictoffset); + if (b_dictoffset == -1 && PyErr_Occurred()) goto dictoffset_return; +#endif + if (b_dictoffset) { + { + __Pyx_TypeName b_name = __Pyx_PyType_GetName(b); + PyErr_Format(PyExc_TypeError, + "extension type '%.200s' has no __dict__ slot, " + "but base type '" __Pyx_FMT_TYPENAME "' has: " + "either add 'cdef dict __dict__' to the extension type " + "or add '__slots__ = [...]' to the base type", + type_name, b_name); + __Pyx_DECREF_TypeName(b_name); + } +#if !(CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY) + dictoffset_return: +#endif +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + return -1; + } + } +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + } + return 0; +} +#endif + +/* PyType_Ready */ +static int __Pyx_PyType_Ready(PyTypeObject *t) { +#if CYTHON_USE_TYPE_SPECS || !(CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API) || defined(PYSTON_MAJOR_VERSION) + (void)__Pyx_PyObject_CallMethod0; +#if CYTHON_USE_TYPE_SPECS + (void)__Pyx_validate_bases_tuple; +#endif + return PyType_Ready(t); +#else + int r; + PyObject *bases = __Pyx_PyType_GetSlot(t, tp_bases, PyObject*); + if (bases && unlikely(__Pyx_validate_bases_tuple(t->tp_name, t->tp_dictoffset, bases) == -1)) + return -1; +#if PY_VERSION_HEX >= 0x03050000 && !defined(PYSTON_MAJOR_VERSION) + { + int gc_was_enabled; + #if PY_VERSION_HEX >= 0x030A00b1 + gc_was_enabled = PyGC_Disable(); + (void)__Pyx_PyObject_CallMethod0; + #else + PyObject *ret, *py_status; + PyObject *gc = NULL; + #if PY_VERSION_HEX >= 0x030700a1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM+0 >= 0x07030400) + gc = PyImport_GetModule(__pyx_kp_u_gc); + #endif + if (unlikely(!gc)) gc = PyImport_Import(__pyx_kp_u_gc); + if (unlikely(!gc)) return -1; + py_status = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_isenabled); + if (unlikely(!py_status)) { + Py_DECREF(gc); + return -1; + } + gc_was_enabled = __Pyx_PyObject_IsTrue(py_status); + Py_DECREF(py_status); + if (gc_was_enabled > 0) { + ret = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_disable); + if (unlikely(!ret)) { + Py_DECREF(gc); + return -1; + } + Py_DECREF(ret); + } else if (unlikely(gc_was_enabled == -1)) { + Py_DECREF(gc); + return -1; + } + #endif + t->tp_flags |= Py_TPFLAGS_HEAPTYPE; +#if PY_VERSION_HEX >= 0x030A0000 + t->tp_flags |= Py_TPFLAGS_IMMUTABLETYPE; +#endif +#else + (void)__Pyx_PyObject_CallMethod0; +#endif + r = PyType_Ready(t); +#if PY_VERSION_HEX >= 0x03050000 && !defined(PYSTON_MAJOR_VERSION) + t->tp_flags &= ~Py_TPFLAGS_HEAPTYPE; + #if PY_VERSION_HEX >= 0x030A00b1 + if (gc_was_enabled) + PyGC_Enable(); + #else + if (gc_was_enabled) { + PyObject *tp, *v, *tb; + PyErr_Fetch(&tp, &v, &tb); + ret = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_enable); + if (likely(ret || r == -1)) { + Py_XDECREF(ret); + PyErr_Restore(tp, v, tb); + } else { + Py_XDECREF(tp); + Py_XDECREF(v); + Py_XDECREF(tb); + r = -1; + } + } + Py_DECREF(gc); + #endif + } +#endif + return r; +#endif +} + +/* PyObject_GenericGetAttrNoDict */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) { + __Pyx_TypeName type_name = __Pyx_PyType_GetName(tp); + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%U'", + type_name, attr_name); +#else + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%.400s'", + type_name, PyString_AS_STRING(attr_name)); +#endif + __Pyx_DECREF_TypeName(type_name); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) { + PyObject *descr; + PyTypeObject *tp = Py_TYPE(obj); + if (unlikely(!PyString_Check(attr_name))) { + return PyObject_GenericGetAttr(obj, attr_name); + } + assert(!tp->tp_dictoffset); + descr = _PyType_Lookup(tp, attr_name); + if (unlikely(!descr)) { + return __Pyx_RaiseGenericGetAttributeError(tp, attr_name); + } + Py_INCREF(descr); + #if PY_MAJOR_VERSION < 3 + if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS))) + #endif + { + descrgetfunc f = Py_TYPE(descr)->tp_descr_get; + if (unlikely(f)) { + PyObject *res = f(descr, obj, (PyObject *)tp); + Py_DECREF(descr); + return res; + } + } + return descr; +} +#endif + +/* PyObject_GenericGetAttr */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject* __Pyx_PyObject_GenericGetAttr(PyObject* obj, PyObject* attr_name) { + if (unlikely(Py_TYPE(obj)->tp_dictoffset)) { + return PyObject_GenericGetAttr(obj, attr_name); + } + return __Pyx_PyObject_GenericGetAttrNoDict(obj, attr_name); +} +#endif + +/* SetupReduce */ +#if !CYTHON_COMPILING_IN_LIMITED_API +static int __Pyx_setup_reduce_is_named(PyObject* meth, PyObject* name) { + int ret; + PyObject *name_attr; + name_attr = __Pyx_PyObject_GetAttrStrNoError(meth, __pyx_n_s_name); + if (likely(name_attr)) { + ret = PyObject_RichCompareBool(name_attr, name, Py_EQ); + } else { + ret = -1; + } + if (unlikely(ret < 0)) { + PyErr_Clear(); + ret = 0; + } + Py_XDECREF(name_attr); + return ret; +} +static int __Pyx_setup_reduce(PyObject* type_obj) { + int ret = 0; + PyObject *object_reduce = NULL; + PyObject *object_getstate = NULL; + PyObject *object_reduce_ex = NULL; + PyObject *reduce = NULL; + PyObject *reduce_ex = NULL; + PyObject *reduce_cython = NULL; + PyObject *setstate = NULL; + PyObject *setstate_cython = NULL; + PyObject *getstate = NULL; +#if CYTHON_USE_PYTYPE_LOOKUP + getstate = _PyType_Lookup((PyTypeObject*)type_obj, __pyx_n_s_getstate); +#else + getstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_getstate); + if (!getstate && PyErr_Occurred()) { + goto __PYX_BAD; + } +#endif + if (getstate) { +#if CYTHON_USE_PYTYPE_LOOKUP + object_getstate = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_getstate); +#else + object_getstate = __Pyx_PyObject_GetAttrStrNoError((PyObject*)&PyBaseObject_Type, __pyx_n_s_getstate); + if (!object_getstate && PyErr_Occurred()) { + goto __PYX_BAD; + } +#endif + if (object_getstate != getstate) { + goto __PYX_GOOD; + } + } +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce_ex = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; +#else + object_reduce_ex = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce_ex); if (!object_reduce_ex) goto __PYX_BAD; +#endif + reduce_ex = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce_ex); if (unlikely(!reduce_ex)) goto __PYX_BAD; + if (reduce_ex == object_reduce_ex) { +#if CYTHON_USE_PYTYPE_LOOKUP + object_reduce = _PyType_Lookup(&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; +#else + object_reduce = __Pyx_PyObject_GetAttrStr((PyObject*)&PyBaseObject_Type, __pyx_n_s_reduce); if (!object_reduce) goto __PYX_BAD; +#endif + reduce = __Pyx_PyObject_GetAttrStr(type_obj, __pyx_n_s_reduce); if (unlikely(!reduce)) goto __PYX_BAD; + if (reduce == object_reduce || __Pyx_setup_reduce_is_named(reduce, __pyx_n_s_reduce_cython)) { + reduce_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_reduce_cython); + if (likely(reduce_cython)) { + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce, reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_reduce_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + } else if (reduce == object_reduce || PyErr_Occurred()) { + goto __PYX_BAD; + } + setstate = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate); + if (!setstate) PyErr_Clear(); + if (!setstate || __Pyx_setup_reduce_is_named(setstate, __pyx_n_s_setstate_cython)) { + setstate_cython = __Pyx_PyObject_GetAttrStrNoError(type_obj, __pyx_n_s_setstate_cython); + if (likely(setstate_cython)) { + ret = PyDict_SetItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate, setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + ret = PyDict_DelItem(((PyTypeObject*)type_obj)->tp_dict, __pyx_n_s_setstate_cython); if (unlikely(ret < 0)) goto __PYX_BAD; + } else if (!setstate || PyErr_Occurred()) { + goto __PYX_BAD; + } + } + PyType_Modified((PyTypeObject*)type_obj); + } + } + goto __PYX_GOOD; +__PYX_BAD: + if (!PyErr_Occurred()) { + __Pyx_TypeName type_obj_name = + __Pyx_PyType_GetName((PyTypeObject*)type_obj); + PyErr_Format(PyExc_RuntimeError, + "Unable to initialize pickling for " __Pyx_FMT_TYPENAME, type_obj_name); + __Pyx_DECREF_TypeName(type_obj_name); + } + ret = -1; +__PYX_GOOD: +#if !CYTHON_USE_PYTYPE_LOOKUP + Py_XDECREF(object_reduce); + Py_XDECREF(object_reduce_ex); + Py_XDECREF(object_getstate); + Py_XDECREF(getstate); +#endif + Py_XDECREF(reduce); + Py_XDECREF(reduce_ex); + Py_XDECREF(reduce_cython); + Py_XDECREF(setstate); + Py_XDECREF(setstate_cython); + return ret; +} +#endif + +/* ImportDottedModule */ +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx__ImportDottedModule_Error(PyObject *name, PyObject *parts_tuple, Py_ssize_t count) { + PyObject *partial_name = NULL, *slice = NULL, *sep = NULL; + if (unlikely(PyErr_Occurred())) { + PyErr_Clear(); + } + if (likely(PyTuple_GET_SIZE(parts_tuple) == count)) { + partial_name = name; + } else { + slice = PySequence_GetSlice(parts_tuple, 0, count); + if (unlikely(!slice)) + goto bad; + sep = PyUnicode_FromStringAndSize(".", 1); + if (unlikely(!sep)) + goto bad; + partial_name = PyUnicode_Join(sep, slice); + } + PyErr_Format( +#if PY_MAJOR_VERSION < 3 + PyExc_ImportError, + "No module named '%s'", PyString_AS_STRING(partial_name)); +#else +#if PY_VERSION_HEX >= 0x030600B1 + PyExc_ModuleNotFoundError, +#else + PyExc_ImportError, +#endif + "No module named '%U'", partial_name); +#endif +bad: + Py_XDECREF(sep); + Py_XDECREF(slice); + Py_XDECREF(partial_name); + return NULL; +} +#endif +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx__ImportDottedModule_Lookup(PyObject *name) { + PyObject *imported_module; +#if PY_VERSION_HEX < 0x030700A1 || (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM < 0x07030400) + PyObject *modules = PyImport_GetModuleDict(); + if (unlikely(!modules)) + return NULL; + imported_module = __Pyx_PyDict_GetItemStr(modules, name); + Py_XINCREF(imported_module); +#else + imported_module = PyImport_GetModule(name); +#endif + return imported_module; +} +#endif +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple) { + Py_ssize_t i, nparts; + nparts = PyTuple_GET_SIZE(parts_tuple); + for (i=1; i < nparts && module; i++) { + PyObject *part, *submodule; +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + part = PyTuple_GET_ITEM(parts_tuple, i); +#else + part = PySequence_ITEM(parts_tuple, i); +#endif + submodule = __Pyx_PyObject_GetAttrStrNoError(module, part); +#if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) + Py_DECREF(part); +#endif + Py_DECREF(module); + module = submodule; + } + if (unlikely(!module)) { + return __Pyx__ImportDottedModule_Error(name, parts_tuple, i); + } + return module; +} +#endif +static PyObject *__Pyx__ImportDottedModule(PyObject *name, PyObject *parts_tuple) { +#if PY_MAJOR_VERSION < 3 + PyObject *module, *from_list, *star = __pyx_n_s__6; + CYTHON_UNUSED_VAR(parts_tuple); + from_list = PyList_New(1); + if (unlikely(!from_list)) + return NULL; + Py_INCREF(star); + PyList_SET_ITEM(from_list, 0, star); + module = __Pyx_Import(name, from_list, 0); + Py_DECREF(from_list); + return module; +#else + PyObject *imported_module; + PyObject *module = __Pyx_Import(name, NULL, 0); + if (!parts_tuple || unlikely(!module)) + return module; + imported_module = __Pyx__ImportDottedModule_Lookup(name); + if (likely(imported_module)) { + Py_DECREF(module); + return imported_module; + } + PyErr_Clear(); + return __Pyx_ImportDottedModule_WalkParts(module, name, parts_tuple); +#endif +} +static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030400B1 + PyObject *module = __Pyx__ImportDottedModule_Lookup(name); + if (likely(module)) { + PyObject *spec = __Pyx_PyObject_GetAttrStrNoError(module, __pyx_n_s_spec); + if (likely(spec)) { + PyObject *unsafe = __Pyx_PyObject_GetAttrStrNoError(spec, __pyx_n_s_initializing); + if (likely(!unsafe || !__Pyx_PyObject_IsTrue(unsafe))) { + Py_DECREF(spec); + spec = NULL; + } + Py_XDECREF(unsafe); + } + if (likely(!spec)) { + PyErr_Clear(); + return module; + } + Py_DECREF(spec); + Py_DECREF(module); + } else if (PyErr_Occurred()) { + PyErr_Clear(); + } +#endif + return __Pyx__ImportDottedModule(name, parts_tuple); +} + +/* FetchSharedCythonModule */ +static PyObject *__Pyx_FetchSharedCythonABIModule(void) { + return __Pyx_PyImport_AddModuleRef((char*) __PYX_ABI_MODULE_NAME); +} + +/* FetchCommonType */ +static int __Pyx_VerifyCachedType(PyObject *cached_type, + const char *name, + Py_ssize_t basicsize, + Py_ssize_t expected_basicsize) { + if (!PyType_Check(cached_type)) { + PyErr_Format(PyExc_TypeError, + "Shared Cython type %.200s is not a type object", name); + return -1; + } + if (basicsize != expected_basicsize) { + PyErr_Format(PyExc_TypeError, + "Shared Cython type %.200s has the wrong size, try recompiling", + name); + return -1; + } + return 0; +} +#if !CYTHON_USE_TYPE_SPECS +static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) { + PyObject* abi_module; + const char* object_name; + PyTypeObject *cached_type = NULL; + abi_module = __Pyx_FetchSharedCythonABIModule(); + if (!abi_module) return NULL; + object_name = strrchr(type->tp_name, '.'); + object_name = object_name ? object_name+1 : type->tp_name; + cached_type = (PyTypeObject*) PyObject_GetAttrString(abi_module, object_name); + if (cached_type) { + if (__Pyx_VerifyCachedType( + (PyObject *)cached_type, + object_name, + cached_type->tp_basicsize, + type->tp_basicsize) < 0) { + goto bad; + } + goto done; + } + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; + PyErr_Clear(); + if (PyType_Ready(type) < 0) goto bad; + if (PyObject_SetAttrString(abi_module, object_name, (PyObject *)type) < 0) + goto bad; + Py_INCREF(type); + cached_type = type; +done: + Py_DECREF(abi_module); + return cached_type; +bad: + Py_XDECREF(cached_type); + cached_type = NULL; + goto done; +} +#else +static PyTypeObject *__Pyx_FetchCommonTypeFromSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) { + PyObject *abi_module, *cached_type = NULL; + const char* object_name = strrchr(spec->name, '.'); + object_name = object_name ? object_name+1 : spec->name; + abi_module = __Pyx_FetchSharedCythonABIModule(); + if (!abi_module) return NULL; + cached_type = PyObject_GetAttrString(abi_module, object_name); + if (cached_type) { + Py_ssize_t basicsize; +#if CYTHON_COMPILING_IN_LIMITED_API + PyObject *py_basicsize; + py_basicsize = PyObject_GetAttrString(cached_type, "__basicsize__"); + if (unlikely(!py_basicsize)) goto bad; + basicsize = PyLong_AsSsize_t(py_basicsize); + Py_DECREF(py_basicsize); + py_basicsize = 0; + if (unlikely(basicsize == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad; +#else + basicsize = likely(PyType_Check(cached_type)) ? ((PyTypeObject*) cached_type)->tp_basicsize : -1; +#endif + if (__Pyx_VerifyCachedType( + cached_type, + object_name, + basicsize, + spec->basicsize) < 0) { + goto bad; + } + goto done; + } + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; + PyErr_Clear(); + CYTHON_UNUSED_VAR(module); + cached_type = __Pyx_PyType_FromModuleAndSpec(abi_module, spec, bases); + if (unlikely(!cached_type)) goto bad; + if (unlikely(__Pyx_fix_up_extension_type_from_spec(spec, (PyTypeObject *) cached_type) < 0)) goto bad; + if (PyObject_SetAttrString(abi_module, object_name, cached_type) < 0) goto bad; +done: + Py_DECREF(abi_module); + assert(cached_type == NULL || PyType_Check(cached_type)); + return (PyTypeObject *) cached_type; +bad: + Py_XDECREF(cached_type); + cached_type = NULL; + goto done; +} +#endif + +/* PyVectorcallFastCallDict */ +#if CYTHON_METH_FASTCALL +static PyObject *__Pyx_PyVectorcall_FastCallDict_kw(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw) +{ + PyObject *res = NULL; + PyObject *kwnames; + PyObject **newargs; + PyObject **kwvalues; + Py_ssize_t i, pos; + size_t j; + PyObject *key, *value; + unsigned long keys_are_strings; + Py_ssize_t nkw = PyDict_GET_SIZE(kw); + newargs = (PyObject **)PyMem_Malloc((nargs + (size_t)nkw) * sizeof(args[0])); + if (unlikely(newargs == NULL)) { + PyErr_NoMemory(); + return NULL; + } + for (j = 0; j < nargs; j++) newargs[j] = args[j]; + kwnames = PyTuple_New(nkw); + if (unlikely(kwnames == NULL)) { + PyMem_Free(newargs); + return NULL; + } + kwvalues = newargs + nargs; + pos = i = 0; + keys_are_strings = Py_TPFLAGS_UNICODE_SUBCLASS; + while (PyDict_Next(kw, &pos, &key, &value)) { + keys_are_strings &= Py_TYPE(key)->tp_flags; + Py_INCREF(key); + Py_INCREF(value); + PyTuple_SET_ITEM(kwnames, i, key); + kwvalues[i] = value; + i++; + } + if (unlikely(!keys_are_strings)) { + PyErr_SetString(PyExc_TypeError, "keywords must be strings"); + goto cleanup; + } + res = vc(func, newargs, nargs, kwnames); +cleanup: + Py_DECREF(kwnames); + for (i = 0; i < nkw; i++) + Py_DECREF(kwvalues[i]); + PyMem_Free(newargs); + return res; +} +static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw) +{ + if (likely(kw == NULL) || PyDict_GET_SIZE(kw) == 0) { + return vc(func, args, nargs, NULL); + } + return __Pyx_PyVectorcall_FastCallDict_kw(func, vc, args, nargs, kw); +} +#endif + +/* CythonFunctionShared */ +#if CYTHON_COMPILING_IN_LIMITED_API +static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc) { + if (__Pyx_CyFunction_Check(func)) { + return PyCFunction_GetFunction(((__pyx_CyFunctionObject*)func)->func) == (PyCFunction) cfunc; + } else if (PyCFunction_Check(func)) { + return PyCFunction_GetFunction(func) == (PyCFunction) cfunc; + } + return 0; +} +#else +static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc) { + return __Pyx_CyOrPyCFunction_Check(func) && __Pyx_CyOrPyCFunction_GET_FUNCTION(func) == (PyCFunction) cfunc; +} +#endif +static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj) { +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + __Pyx_Py_XDECREF_SET( + __Pyx_CyFunction_GetClassObj(f), + ((classobj) ? __Pyx_NewRef(classobj) : NULL)); +#else + __Pyx_Py_XDECREF_SET( + ((PyCMethodObject *) (f))->mm_class, + (PyTypeObject*)((classobj) ? __Pyx_NewRef(classobj) : NULL)); +#endif +} +static PyObject * +__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, void *closure) +{ + CYTHON_UNUSED_VAR(closure); + if (unlikely(op->func_doc == NULL)) { +#if CYTHON_COMPILING_IN_LIMITED_API + op->func_doc = PyObject_GetAttrString(op->func, "__doc__"); + if (unlikely(!op->func_doc)) return NULL; +#else + if (((PyCFunctionObject*)op)->m_ml->ml_doc) { +#if PY_MAJOR_VERSION >= 3 + op->func_doc = PyUnicode_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc); +#else + op->func_doc = PyString_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc); +#endif + if (unlikely(op->func_doc == NULL)) + return NULL; + } else { + Py_INCREF(Py_None); + return Py_None; + } +#endif + } + Py_INCREF(op->func_doc); + return op->func_doc; +} +static int +__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (value == NULL) { + value = Py_None; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_doc, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (unlikely(op->func_name == NULL)) { +#if CYTHON_COMPILING_IN_LIMITED_API + op->func_name = PyObject_GetAttrString(op->func, "__name__"); +#elif PY_MAJOR_VERSION >= 3 + op->func_name = PyUnicode_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name); +#else + op->func_name = PyString_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name); +#endif + if (unlikely(op->func_name == NULL)) + return NULL; + } + Py_INCREF(op->func_name); + return op->func_name; +} +static int +__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) +#else + if (unlikely(value == NULL || !PyString_Check(value))) +#endif + { + PyErr_SetString(PyExc_TypeError, + "__name__ must be set to a string object"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_name, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + Py_INCREF(op->func_qualname); + return op->func_qualname; +} +static int +__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) +#else + if (unlikely(value == NULL || !PyString_Check(value))) +#endif + { + PyErr_SetString(PyExc_TypeError, + "__qualname__ must be set to a string object"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_qualname, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (unlikely(op->func_dict == NULL)) { + op->func_dict = PyDict_New(); + if (unlikely(op->func_dict == NULL)) + return NULL; + } + Py_INCREF(op->func_dict); + return op->func_dict; +} +static int +__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (unlikely(value == NULL)) { + PyErr_SetString(PyExc_TypeError, + "function's dictionary may not be deleted"); + return -1; + } + if (unlikely(!PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "setting function's dictionary to a non-dict"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_dict, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + Py_INCREF(op->func_globals); + return op->func_globals; +} +static PyObject * +__Pyx_CyFunction_get_closure(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(op); + CYTHON_UNUSED_VAR(context); + Py_INCREF(Py_None); + return Py_None; +} +static PyObject * +__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op, void *context) +{ + PyObject* result = (op->func_code) ? op->func_code : Py_None; + CYTHON_UNUSED_VAR(context); + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) { + int result = 0; + PyObject *res = op->defaults_getter((PyObject *) op); + if (unlikely(!res)) + return -1; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + op->defaults_tuple = PyTuple_GET_ITEM(res, 0); + Py_INCREF(op->defaults_tuple); + op->defaults_kwdict = PyTuple_GET_ITEM(res, 1); + Py_INCREF(op->defaults_kwdict); + #else + op->defaults_tuple = __Pyx_PySequence_ITEM(res, 0); + if (unlikely(!op->defaults_tuple)) result = -1; + else { + op->defaults_kwdict = __Pyx_PySequence_ITEM(res, 1); + if (unlikely(!op->defaults_kwdict)) result = -1; + } + #endif + Py_DECREF(res); + return result; +} +static int +__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + if (!value) { + value = Py_None; + } else if (unlikely(value != Py_None && !PyTuple_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "__defaults__ must be set to a tuple object"); + return -1; + } + PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__defaults__ will not " + "currently affect the values used in function calls", 1); + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->defaults_tuple, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op, void *context) { + PyObject* result = op->defaults_tuple; + CYTHON_UNUSED_VAR(context); + if (unlikely(!result)) { + if (op->defaults_getter) { + if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL; + result = op->defaults_tuple; + } else { + result = Py_None; + } + } + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + if (!value) { + value = Py_None; + } else if (unlikely(value != Py_None && !PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "__kwdefaults__ must be set to a dict object"); + return -1; + } + PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__kwdefaults__ will not " + "currently affect the values used in function calls", 1); + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->defaults_kwdict, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op, void *context) { + PyObject* result = op->defaults_kwdict; + CYTHON_UNUSED_VAR(context); + if (unlikely(!result)) { + if (op->defaults_getter) { + if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL; + result = op->defaults_kwdict; + } else { + result = Py_None; + } + } + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + if (!value || value == Py_None) { + value = NULL; + } else if (unlikely(!PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "__annotations__ must be set to a dict object"); + return -1; + } + Py_XINCREF(value); + __Pyx_Py_XDECREF_SET(op->func_annotations, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op, void *context) { + PyObject* result = op->func_annotations; + CYTHON_UNUSED_VAR(context); + if (unlikely(!result)) { + result = PyDict_New(); + if (unlikely(!result)) return NULL; + op->func_annotations = result; + } + Py_INCREF(result); + return result; +} +static PyObject * +__Pyx_CyFunction_get_is_coroutine(__pyx_CyFunctionObject *op, void *context) { + int is_coroutine; + CYTHON_UNUSED_VAR(context); + if (op->func_is_coroutine) { + return __Pyx_NewRef(op->func_is_coroutine); + } + is_coroutine = op->flags & __Pyx_CYFUNCTION_COROUTINE; +#if PY_VERSION_HEX >= 0x03050000 + if (is_coroutine) { + PyObject *module, *fromlist, *marker = __pyx_n_s_is_coroutine; + fromlist = PyList_New(1); + if (unlikely(!fromlist)) return NULL; + Py_INCREF(marker); +#if CYTHON_ASSUME_SAFE_MACROS + PyList_SET_ITEM(fromlist, 0, marker); +#else + if (unlikely(PyList_SetItem(fromlist, 0, marker) < 0)) { + Py_DECREF(marker); + Py_DECREF(fromlist); + return NULL; + } +#endif + module = PyImport_ImportModuleLevelObject(__pyx_n_s_asyncio_coroutines, NULL, NULL, fromlist, 0); + Py_DECREF(fromlist); + if (unlikely(!module)) goto ignore; + op->func_is_coroutine = __Pyx_PyObject_GetAttrStr(module, marker); + Py_DECREF(module); + if (likely(op->func_is_coroutine)) { + return __Pyx_NewRef(op->func_is_coroutine); + } +ignore: + PyErr_Clear(); + } +#endif + op->func_is_coroutine = __Pyx_PyBool_FromLong(is_coroutine); + return __Pyx_NewRef(op->func_is_coroutine); +} +#if CYTHON_COMPILING_IN_LIMITED_API +static PyObject * +__Pyx_CyFunction_get_module(__pyx_CyFunctionObject *op, void *context) { + CYTHON_UNUSED_VAR(context); + return PyObject_GetAttrString(op->func, "__module__"); +} +static int +__Pyx_CyFunction_set_module(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + return PyObject_SetAttrString(op->func, "__module__", value); +} +#endif +static PyGetSetDef __pyx_CyFunction_getsets[] = { + {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, + {(char *) "__doc__", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, + {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, + {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, + {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0}, + {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, + {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, + {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, + {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, + {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, + {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, + {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, + {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, + {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, + {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, + {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0}, + {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0}, + {(char *) "_is_coroutine", (getter)__Pyx_CyFunction_get_is_coroutine, 0, 0, 0}, +#if CYTHON_COMPILING_IN_LIMITED_API + {"__module__", (getter)__Pyx_CyFunction_get_module, (setter)__Pyx_CyFunction_set_module, 0, 0}, +#endif + {0, 0, 0, 0, 0} +}; +static PyMemberDef __pyx_CyFunction_members[] = { +#if !CYTHON_COMPILING_IN_LIMITED_API + {(char *) "__module__", T_OBJECT, offsetof(PyCFunctionObject, m_module), 0, 0}, +#endif +#if CYTHON_USE_TYPE_SPECS + {(char *) "__dictoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_dict), READONLY, 0}, +#if CYTHON_METH_FASTCALL +#if CYTHON_BACKPORT_VECTORCALL + {(char *) "__vectorcalloffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_vectorcall), READONLY, 0}, +#else +#if !CYTHON_COMPILING_IN_LIMITED_API + {(char *) "__vectorcalloffset__", T_PYSSIZET, offsetof(PyCFunctionObject, vectorcall), READONLY, 0}, +#endif +#endif +#endif +#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API + {(char *) "__weaklistoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_weakreflist), READONLY, 0}, +#else + {(char *) "__weaklistoffset__", T_PYSSIZET, offsetof(PyCFunctionObject, m_weakreflist), READONLY, 0}, +#endif +#endif + {0, 0, 0, 0, 0} +}; +static PyObject * +__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, PyObject *args) +{ + CYTHON_UNUSED_VAR(args); +#if PY_MAJOR_VERSION >= 3 + Py_INCREF(m->func_qualname); + return m->func_qualname; +#else + return PyString_FromString(((PyCFunctionObject*)m)->m_ml->ml_name); +#endif +} +static PyMethodDef __pyx_CyFunction_methods[] = { + {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0}, + {0, 0, 0, 0} +}; +#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API +#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist) +#else +#define __Pyx_CyFunction_weakreflist(cyfunc) (((PyCFunctionObject*)cyfunc)->m_weakreflist) +#endif +static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject *op, PyMethodDef *ml, int flags, PyObject* qualname, + PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { +#if !CYTHON_COMPILING_IN_LIMITED_API + PyCFunctionObject *cf = (PyCFunctionObject*) op; +#endif + if (unlikely(op == NULL)) + return NULL; +#if CYTHON_COMPILING_IN_LIMITED_API + op->func = PyCFunction_NewEx(ml, (PyObject*)op, module); + if (unlikely(!op->func)) return NULL; +#endif + op->flags = flags; + __Pyx_CyFunction_weakreflist(op) = NULL; +#if !CYTHON_COMPILING_IN_LIMITED_API + cf->m_ml = ml; + cf->m_self = (PyObject *) op; +#endif + Py_XINCREF(closure); + op->func_closure = closure; +#if !CYTHON_COMPILING_IN_LIMITED_API + Py_XINCREF(module); + cf->m_module = module; +#endif + op->func_dict = NULL; + op->func_name = NULL; + Py_INCREF(qualname); + op->func_qualname = qualname; + op->func_doc = NULL; +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + op->func_classobj = NULL; +#else + ((PyCMethodObject*)op)->mm_class = NULL; +#endif + op->func_globals = globals; + Py_INCREF(op->func_globals); + Py_XINCREF(code); + op->func_code = code; + op->defaults_pyobjects = 0; + op->defaults_size = 0; + op->defaults = NULL; + op->defaults_tuple = NULL; + op->defaults_kwdict = NULL; + op->defaults_getter = NULL; + op->func_annotations = NULL; + op->func_is_coroutine = NULL; +#if CYTHON_METH_FASTCALL + switch (ml->ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O | METH_KEYWORDS | METH_METHOD)) { + case METH_NOARGS: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_NOARGS; + break; + case METH_O: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_O; + break; + case METH_METHOD | METH_FASTCALL | METH_KEYWORDS: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD; + break; + case METH_FASTCALL | METH_KEYWORDS: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS; + break; + case METH_VARARGS | METH_KEYWORDS: + __Pyx_CyFunction_func_vectorcall(op) = NULL; + break; + default: + PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction"); + Py_DECREF(op); + return NULL; + } +#endif + return (PyObject *) op; +} +static int +__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m) +{ + Py_CLEAR(m->func_closure); +#if CYTHON_COMPILING_IN_LIMITED_API + Py_CLEAR(m->func); +#else + Py_CLEAR(((PyCFunctionObject*)m)->m_module); +#endif + Py_CLEAR(m->func_dict); + Py_CLEAR(m->func_name); + Py_CLEAR(m->func_qualname); + Py_CLEAR(m->func_doc); + Py_CLEAR(m->func_globals); + Py_CLEAR(m->func_code); +#if !CYTHON_COMPILING_IN_LIMITED_API +#if PY_VERSION_HEX < 0x030900B1 + Py_CLEAR(__Pyx_CyFunction_GetClassObj(m)); +#else + { + PyObject *cls = (PyObject*) ((PyCMethodObject *) (m))->mm_class; + ((PyCMethodObject *) (m))->mm_class = NULL; + Py_XDECREF(cls); + } +#endif +#endif + Py_CLEAR(m->defaults_tuple); + Py_CLEAR(m->defaults_kwdict); + Py_CLEAR(m->func_annotations); + Py_CLEAR(m->func_is_coroutine); + if (m->defaults) { + PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); + int i; + for (i = 0; i < m->defaults_pyobjects; i++) + Py_XDECREF(pydefaults[i]); + PyObject_Free(m->defaults); + m->defaults = NULL; + } + return 0; +} +static void __Pyx__CyFunction_dealloc(__pyx_CyFunctionObject *m) +{ + if (__Pyx_CyFunction_weakreflist(m) != NULL) + PyObject_ClearWeakRefs((PyObject *) m); + __Pyx_CyFunction_clear(m); + __Pyx_PyHeapTypeObject_GC_Del(m); +} +static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m) +{ + PyObject_GC_UnTrack(m); + __Pyx__CyFunction_dealloc(m); +} +static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg) +{ + Py_VISIT(m->func_closure); +#if CYTHON_COMPILING_IN_LIMITED_API + Py_VISIT(m->func); +#else + Py_VISIT(((PyCFunctionObject*)m)->m_module); +#endif + Py_VISIT(m->func_dict); + Py_VISIT(m->func_name); + Py_VISIT(m->func_qualname); + Py_VISIT(m->func_doc); + Py_VISIT(m->func_globals); + Py_VISIT(m->func_code); +#if !CYTHON_COMPILING_IN_LIMITED_API + Py_VISIT(__Pyx_CyFunction_GetClassObj(m)); +#endif + Py_VISIT(m->defaults_tuple); + Py_VISIT(m->defaults_kwdict); + Py_VISIT(m->func_is_coroutine); + if (m->defaults) { + PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); + int i; + for (i = 0; i < m->defaults_pyobjects; i++) + Py_VISIT(pydefaults[i]); + } + return 0; +} +static PyObject* +__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op) +{ +#if PY_MAJOR_VERSION >= 3 + return PyUnicode_FromFormat("", + op->func_qualname, (void *)op); +#else + return PyString_FromFormat("", + PyString_AsString(op->func_qualname), (void *)op); +#endif +} +static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) { +#if CYTHON_COMPILING_IN_LIMITED_API + PyObject *f = ((__pyx_CyFunctionObject*)func)->func; + PyObject *py_name = NULL; + PyCFunction meth; + int flags; + meth = PyCFunction_GetFunction(f); + if (unlikely(!meth)) return NULL; + flags = PyCFunction_GetFlags(f); + if (unlikely(flags < 0)) return NULL; +#else + PyCFunctionObject* f = (PyCFunctionObject*)func; + PyCFunction meth = f->m_ml->ml_meth; + int flags = f->m_ml->ml_flags; +#endif + Py_ssize_t size; + switch (flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) { + case METH_VARARGS: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) + return (*meth)(self, arg); + break; + case METH_VARARGS | METH_KEYWORDS: + return (*(PyCFunctionWithKeywords)(void*)meth)(self, arg, kw); + case METH_NOARGS: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) { +#if CYTHON_ASSUME_SAFE_MACROS + size = PyTuple_GET_SIZE(arg); +#else + size = PyTuple_Size(arg); + if (unlikely(size < 0)) return NULL; +#endif + if (likely(size == 0)) + return (*meth)(self, NULL); +#if CYTHON_COMPILING_IN_LIMITED_API + py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); + if (!py_name) return NULL; + PyErr_Format(PyExc_TypeError, + "%.200S() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + py_name, size); + Py_DECREF(py_name); +#else + PyErr_Format(PyExc_TypeError, + "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + f->m_ml->ml_name, size); +#endif + return NULL; + } + break; + case METH_O: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) { +#if CYTHON_ASSUME_SAFE_MACROS + size = PyTuple_GET_SIZE(arg); +#else + size = PyTuple_Size(arg); + if (unlikely(size < 0)) return NULL; +#endif + if (likely(size == 1)) { + PyObject *result, *arg0; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + arg0 = PyTuple_GET_ITEM(arg, 0); + #else + arg0 = __Pyx_PySequence_ITEM(arg, 0); if (unlikely(!arg0)) return NULL; + #endif + result = (*meth)(self, arg0); + #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) + Py_DECREF(arg0); + #endif + return result; + } +#if CYTHON_COMPILING_IN_LIMITED_API + py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); + if (!py_name) return NULL; + PyErr_Format(PyExc_TypeError, + "%.200S() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + py_name, size); + Py_DECREF(py_name); +#else + PyErr_Format(PyExc_TypeError, + "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + f->m_ml->ml_name, size); +#endif + return NULL; + } + break; + default: + PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction"); + return NULL; + } +#if CYTHON_COMPILING_IN_LIMITED_API + py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); + if (!py_name) return NULL; + PyErr_Format(PyExc_TypeError, "%.200S() takes no keyword arguments", + py_name); + Py_DECREF(py_name); +#else + PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments", + f->m_ml->ml_name); +#endif + return NULL; +} +static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *self, *result; +#if CYTHON_COMPILING_IN_LIMITED_API + self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)func)->func); + if (unlikely(!self) && PyErr_Occurred()) return NULL; +#else + self = ((PyCFunctionObject*)func)->m_self; +#endif + result = __Pyx_CyFunction_CallMethod(func, self, arg, kw); + return result; +} +static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) { + PyObject *result; + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func; +#if CYTHON_METH_FASTCALL + __pyx_vectorcallfunc vc = __Pyx_CyFunction_func_vectorcall(cyfunc); + if (vc) { +#if CYTHON_ASSUME_SAFE_MACROS + return __Pyx_PyVectorcall_FastCallDict(func, vc, &PyTuple_GET_ITEM(args, 0), (size_t)PyTuple_GET_SIZE(args), kw); +#else + (void) &__Pyx_PyVectorcall_FastCallDict; + return PyVectorcall_Call(func, args, kw); +#endif + } +#endif + if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { + Py_ssize_t argc; + PyObject *new_args; + PyObject *self; +#if CYTHON_ASSUME_SAFE_MACROS + argc = PyTuple_GET_SIZE(args); +#else + argc = PyTuple_Size(args); + if (unlikely(!argc) < 0) return NULL; +#endif + new_args = PyTuple_GetSlice(args, 1, argc); + if (unlikely(!new_args)) + return NULL; + self = PyTuple_GetItem(args, 0); + if (unlikely(!self)) { + Py_DECREF(new_args); +#if PY_MAJOR_VERSION > 2 + PyErr_Format(PyExc_TypeError, + "unbound method %.200S() needs an argument", + cyfunc->func_qualname); +#else + PyErr_SetString(PyExc_TypeError, + "unbound method needs an argument"); +#endif + return NULL; + } + result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw); + Py_DECREF(new_args); + } else { + result = __Pyx_CyFunction_Call(func, args, kw); + } + return result; +} +#if CYTHON_METH_FASTCALL +static CYTHON_INLINE int __Pyx_CyFunction_Vectorcall_CheckArgs(__pyx_CyFunctionObject *cyfunc, Py_ssize_t nargs, PyObject *kwnames) +{ + int ret = 0; + if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { + if (unlikely(nargs < 1)) { + PyErr_Format(PyExc_TypeError, "%.200s() needs an argument", + ((PyCFunctionObject*)cyfunc)->m_ml->ml_name); + return -1; + } + ret = 1; + } + if (unlikely(kwnames) && unlikely(PyTuple_GET_SIZE(kwnames))) { + PyErr_Format(PyExc_TypeError, + "%.200s() takes no keyword arguments", ((PyCFunctionObject*)cyfunc)->m_ml->ml_name); + return -1; + } + return ret; +} +static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + if (unlikely(nargs != 0)) { + PyErr_Format(PyExc_TypeError, + "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + def->ml_name, nargs); + return NULL; + } + return def->ml_meth(self, NULL); +} +static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + if (unlikely(nargs != 1)) { + PyErr_Format(PyExc_TypeError, + "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + def->ml_name, nargs); + return NULL; + } + return def->ml_meth(self, args[0]); +} +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + return ((__Pyx_PyCFunctionFastWithKeywords)(void(*)(void))def->ml_meth)(self, args, nargs, kwnames); +} +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; + PyTypeObject *cls = (PyTypeObject *) __Pyx_CyFunction_GetClassObj(cyfunc); +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + return ((__Pyx_PyCMethod)(void(*)(void))def->ml_meth)(self, cls, args, (size_t)nargs, kwnames); +} +#endif +#if CYTHON_USE_TYPE_SPECS +static PyType_Slot __pyx_CyFunctionType_slots[] = { + {Py_tp_dealloc, (void *)__Pyx_CyFunction_dealloc}, + {Py_tp_repr, (void *)__Pyx_CyFunction_repr}, + {Py_tp_call, (void *)__Pyx_CyFunction_CallAsMethod}, + {Py_tp_traverse, (void *)__Pyx_CyFunction_traverse}, + {Py_tp_clear, (void *)__Pyx_CyFunction_clear}, + {Py_tp_methods, (void *)__pyx_CyFunction_methods}, + {Py_tp_members, (void *)__pyx_CyFunction_members}, + {Py_tp_getset, (void *)__pyx_CyFunction_getsets}, + {Py_tp_descr_get, (void *)__Pyx_PyMethod_New}, + {0, 0}, +}; +static PyType_Spec __pyx_CyFunctionType_spec = { + __PYX_TYPE_MODULE_PREFIX "cython_function_or_method", + sizeof(__pyx_CyFunctionObject), + 0, +#ifdef Py_TPFLAGS_METHOD_DESCRIPTOR + Py_TPFLAGS_METHOD_DESCRIPTOR | +#endif +#if (defined(_Py_TPFLAGS_HAVE_VECTORCALL) && CYTHON_METH_FASTCALL) + _Py_TPFLAGS_HAVE_VECTORCALL | +#endif + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, + __pyx_CyFunctionType_slots +}; +#else +static PyTypeObject __pyx_CyFunctionType_type = { + PyVarObject_HEAD_INIT(0, 0) + __PYX_TYPE_MODULE_PREFIX "cython_function_or_method", + sizeof(__pyx_CyFunctionObject), + 0, + (destructor) __Pyx_CyFunction_dealloc, +#if !CYTHON_METH_FASTCALL + 0, +#elif CYTHON_BACKPORT_VECTORCALL + (printfunc)offsetof(__pyx_CyFunctionObject, func_vectorcall), +#else + offsetof(PyCFunctionObject, vectorcall), +#endif + 0, + 0, +#if PY_MAJOR_VERSION < 3 + 0, +#else + 0, +#endif + (reprfunc) __Pyx_CyFunction_repr, + 0, + 0, + 0, + 0, + __Pyx_CyFunction_CallAsMethod, + 0, + 0, + 0, + 0, +#ifdef Py_TPFLAGS_METHOD_DESCRIPTOR + Py_TPFLAGS_METHOD_DESCRIPTOR | +#endif +#if defined(_Py_TPFLAGS_HAVE_VECTORCALL) && CYTHON_METH_FASTCALL + _Py_TPFLAGS_HAVE_VECTORCALL | +#endif + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, + 0, + (traverseproc) __Pyx_CyFunction_traverse, + (inquiry) __Pyx_CyFunction_clear, + 0, +#if PY_VERSION_HEX < 0x030500A0 + offsetof(__pyx_CyFunctionObject, func_weakreflist), +#else + offsetof(PyCFunctionObject, m_weakreflist), +#endif + 0, + 0, + __pyx_CyFunction_methods, + __pyx_CyFunction_members, + __pyx_CyFunction_getsets, + 0, + 0, + __Pyx_PyMethod_New, + 0, + offsetof(__pyx_CyFunctionObject, func_dict), + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +#if PY_VERSION_HEX >= 0x030400a1 + 0, +#endif +#if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) + 0, +#endif +#if __PYX_NEED_TP_PRINT_SLOT + 0, +#endif +#if PY_VERSION_HEX >= 0x030C0000 + 0, +#endif +#if PY_VERSION_HEX >= 0x030d00A4 + 0, +#endif +#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 + 0, +#endif +}; +#endif +static int __pyx_CyFunction_init(PyObject *module) { +#if CYTHON_USE_TYPE_SPECS + __pyx_CyFunctionType = __Pyx_FetchCommonTypeFromSpec(module, &__pyx_CyFunctionType_spec, NULL); +#else + CYTHON_UNUSED_VAR(module); + __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type); +#endif + if (unlikely(__pyx_CyFunctionType == NULL)) { + return -1; + } + return 0; +} +static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults = PyObject_Malloc(size); + if (unlikely(!m->defaults)) + return PyErr_NoMemory(); + memset(m->defaults, 0, size); + m->defaults_pyobjects = pyobjects; + m->defaults_size = size; + return m->defaults; +} +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults_tuple = tuple; + Py_INCREF(tuple); +} +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults_kwdict = dict; + Py_INCREF(dict); +} +static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->func_annotations = dict; + Py_INCREF(dict); +} + +/* CythonFunction */ +static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, int flags, PyObject* qualname, + PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { + PyObject *op = __Pyx_CyFunction_Init( + PyObject_GC_New(__pyx_CyFunctionObject, __pyx_CyFunctionType), + ml, flags, qualname, closure, module, globals, code + ); + if (likely(op)) { + PyObject_GC_Track(op); + } + return op; +} + +/* CLineInTraceback */ +#ifndef CYTHON_CLINE_IN_TRACEBACK +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line) { + PyObject *use_cline; + PyObject *ptype, *pvalue, *ptraceback; +#if CYTHON_COMPILING_IN_CPYTHON + PyObject **cython_runtime_dict; +#endif + CYTHON_MAYBE_UNUSED_VAR(tstate); + if (unlikely(!__pyx_cython_runtime)) { + return c_line; + } + __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); +#if CYTHON_COMPILING_IN_CPYTHON + cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime); + if (likely(cython_runtime_dict)) { + __PYX_PY_DICT_LOOKUP_IF_MODIFIED( + use_cline, *cython_runtime_dict, + __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback)) + } else +#endif + { + PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStrNoError(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback); + if (use_cline_obj) { + use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True; + Py_DECREF(use_cline_obj); + } else { + PyErr_Clear(); + use_cline = NULL; + } + } + if (!use_cline) { + c_line = 0; + (void) PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False); + } + else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) { + c_line = 0; + } + __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); + return c_line; +} +#endif + +/* CodeObjectCache */ +#if !CYTHON_COMPILING_IN_LIMITED_API +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { + int start = 0, mid = 0, end = count - 1; + if (end >= 0 && code_line > entries[end].code_line) { + return count; + } + while (start < end) { + mid = start + (end - start) / 2; + if (code_line < entries[mid].code_line) { + end = mid; + } else if (code_line > entries[mid].code_line) { + start = mid + 1; + } else { + return mid; + } + } + if (code_line <= entries[mid].code_line) { + return mid; + } else { + return mid + 1; + } +} +static PyCodeObject *__pyx_find_code_object(int code_line) { + PyCodeObject* code_object; + int pos; + if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { + return NULL; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { + return NULL; + } + code_object = __pyx_code_cache.entries[pos].code_object; + Py_INCREF(code_object); + return code_object; +} +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { + int pos, i; + __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; + if (unlikely(!code_line)) { + return; + } + if (unlikely(!entries)) { + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); + if (likely(entries)) { + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = 64; + __pyx_code_cache.count = 1; + entries[0].code_line = code_line; + entries[0].code_object = code_object; + Py_INCREF(code_object); + } + return; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { + PyCodeObject* tmp = entries[pos].code_object; + entries[pos].code_object = code_object; + Py_DECREF(tmp); + return; + } + if (__pyx_code_cache.count == __pyx_code_cache.max_count) { + int new_max = __pyx_code_cache.max_count + 64; + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( + __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry)); + if (unlikely(!entries)) { + return; + } + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = new_max; + } + for (i=__pyx_code_cache.count; i>pos; i--) { + entries[i] = entries[i-1]; + } + entries[pos].code_line = code_line; + entries[pos].code_object = code_object; + __pyx_code_cache.count++; + Py_INCREF(code_object); +} +#endif + +/* AddTraceback */ +#include "compile.h" +#include "frameobject.h" +#include "traceback.h" +#if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API + #ifndef Py_BUILD_CORE + #define Py_BUILD_CORE 1 + #endif + #include "internal/pycore_frame.h" +#endif +#if CYTHON_COMPILING_IN_LIMITED_API +static PyObject *__Pyx_PyCode_Replace_For_AddTraceback(PyObject *code, PyObject *scratch_dict, + PyObject *firstlineno, PyObject *name) { + PyObject *replace = NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "co_firstlineno", firstlineno))) return NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "co_name", name))) return NULL; + replace = PyObject_GetAttrString(code, "replace"); + if (likely(replace)) { + PyObject *result; + result = PyObject_Call(replace, __pyx_empty_tuple, scratch_dict); + Py_DECREF(replace); + return result; + } + PyErr_Clear(); + #if __PYX_LIMITED_VERSION_HEX < 0x030780000 + { + PyObject *compiled = NULL, *result = NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "code", code))) return NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "type", (PyObject*)(&PyType_Type)))) return NULL; + compiled = Py_CompileString( + "out = type(code)(\n" + " code.co_argcount, code.co_kwonlyargcount, code.co_nlocals, code.co_stacksize,\n" + " code.co_flags, code.co_code, code.co_consts, code.co_names,\n" + " code.co_varnames, code.co_filename, co_name, co_firstlineno,\n" + " code.co_lnotab)\n", "", Py_file_input); + if (!compiled) return NULL; + result = PyEval_EvalCode(compiled, scratch_dict, scratch_dict); + Py_DECREF(compiled); + if (!result) PyErr_Print(); + Py_DECREF(result); + result = PyDict_GetItemString(scratch_dict, "out"); + if (result) Py_INCREF(result); + return result; + } + #else + return NULL; + #endif +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyObject *code_object = NULL, *py_py_line = NULL, *py_funcname = NULL, *dict = NULL; + PyObject *replace = NULL, *getframe = NULL, *frame = NULL; + PyObject *exc_type, *exc_value, *exc_traceback; + int success = 0; + if (c_line) { + (void) __pyx_cfilenm; + (void) __Pyx_CLineForTraceback(__Pyx_PyThreadState_Current, c_line); + } + PyErr_Fetch(&exc_type, &exc_value, &exc_traceback); + code_object = Py_CompileString("_getframe()", filename, Py_eval_input); + if (unlikely(!code_object)) goto bad; + py_py_line = PyLong_FromLong(py_line); + if (unlikely(!py_py_line)) goto bad; + py_funcname = PyUnicode_FromString(funcname); + if (unlikely(!py_funcname)) goto bad; + dict = PyDict_New(); + if (unlikely(!dict)) goto bad; + { + PyObject *old_code_object = code_object; + code_object = __Pyx_PyCode_Replace_For_AddTraceback(code_object, dict, py_py_line, py_funcname); + Py_DECREF(old_code_object); + } + if (unlikely(!code_object)) goto bad; + getframe = PySys_GetObject("_getframe"); + if (unlikely(!getframe)) goto bad; + if (unlikely(PyDict_SetItemString(dict, "_getframe", getframe))) goto bad; + frame = PyEval_EvalCode(code_object, dict, dict); + if (unlikely(!frame) || frame == Py_None) goto bad; + success = 1; + bad: + PyErr_Restore(exc_type, exc_value, exc_traceback); + Py_XDECREF(code_object); + Py_XDECREF(py_py_line); + Py_XDECREF(py_funcname); + Py_XDECREF(dict); + Py_XDECREF(replace); + if (success) { + PyTraceBack_Here( + (struct _frame*)frame); + } + Py_XDECREF(frame); +} +#else +static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( + const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = NULL; + PyObject *py_funcname = NULL; + #if PY_MAJOR_VERSION < 3 + PyObject *py_srcfile = NULL; + py_srcfile = PyString_FromString(filename); + if (!py_srcfile) goto bad; + #endif + if (c_line) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + if (!py_funcname) goto bad; + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + if (!py_funcname) goto bad; + funcname = PyUnicode_AsUTF8(py_funcname); + if (!funcname) goto bad; + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + if (!py_funcname) goto bad; + #endif + } + #if PY_MAJOR_VERSION < 3 + py_code = __Pyx_PyCode_New( + 0, + 0, + 0, + 0, + 0, + 0, + __pyx_empty_bytes, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + py_line, + __pyx_empty_bytes /*PyObject *lnotab*/ + ); + Py_DECREF(py_srcfile); + #else + py_code = PyCode_NewEmpty(filename, funcname, py_line); + #endif + Py_XDECREF(py_funcname); + return py_code; +bad: + Py_XDECREF(py_funcname); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(py_srcfile); + #endif + return NULL; +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject *ptype, *pvalue, *ptraceback; + if (c_line) { + c_line = __Pyx_CLineForTraceback(tstate, c_line); + } + py_code = __pyx_find_code_object(c_line ? -c_line : py_line); + if (!py_code) { + __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); + py_code = __Pyx_CreateCodeObjectForTraceback( + funcname, c_line, py_line, filename); + if (!py_code) { + /* If the code object creation fails, then we should clear the + fetched exception references and propagate the new exception */ + Py_XDECREF(ptype); + Py_XDECREF(pvalue); + Py_XDECREF(ptraceback); + goto bad; + } + __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); + __pyx_insert_code_object(c_line ? -c_line : py_line, py_code); + } + py_frame = PyFrame_New( + tstate, /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + __pyx_d, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + __Pyx_PyFrame_SetLineNumber(py_frame, py_line); + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} +#endif + +/* ExtTypeTest */ +static CYTHON_INLINE int __Pyx_TypeTest(PyObject *obj, PyTypeObject *type) { + __Pyx_TypeName obj_type_name; + __Pyx_TypeName type_name; + if (unlikely(!type)) { + PyErr_SetString(PyExc_SystemError, "Missing type object"); + return 0; + } + if (likely(__Pyx_TypeCheck(obj, type))) + return 1; + obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj)); + type_name = __Pyx_PyType_GetName(type); + PyErr_Format(PyExc_TypeError, + "Cannot convert " __Pyx_FMT_TYPENAME " to " __Pyx_FMT_TYPENAME, + obj_type_name, type_name); + __Pyx_DECREF_TypeName(obj_type_name); + __Pyx_DECREF_TypeName(type_name); + return 0; +} + +/* CIntFromPyVerify */ +#define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) +#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) +#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ + {\ + func_type value = func_value;\ + if (sizeof(target_type) < sizeof(func_type)) {\ + if (unlikely(value != (func_type) (target_type) value)) {\ + func_type zero = 0;\ + if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ + return (target_type) -1;\ + if (is_unsigned && unlikely(value < zero))\ + goto raise_neg_overflow;\ + else\ + goto raise_overflow;\ + }\ + }\ + return (target_type) value;\ + } + +/* CIntFromPy */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const int neg_one = (int) -1, const_zero = (int) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if ((sizeof(int) < sizeof(long))) { + __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (int) val; + } + } +#endif + if (unlikely(!PyLong_Check(x))) { + int val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (int) -1; + val = __Pyx_PyInt_As_int(tmp); + Py_DECREF(tmp); + return val; + } + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + if (unlikely(__Pyx_PyLong_IsNeg(x))) { + goto raise_neg_overflow; + } else if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_DigitCount(x)) { + case 2: + if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) >= 2 * PyLong_SHIFT)) { + return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 3: + if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) >= 3 * PyLong_SHIFT)) { + return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 4: + if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) >= 4 * PyLong_SHIFT)) { + return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + } + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7 + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (int) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if ((sizeof(int) <= sizeof(unsigned long))) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(int) <= sizeof(unsigned PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_SignedDigitCount(x)) { + case -2: + if ((8 * sizeof(int) - 1 > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) { + return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 2: + if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) { + return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -3: + if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) { + return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 3: + if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) { + return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -4: + if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) { + return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 4: + if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) { + return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + } + } +#endif + if ((sizeof(int) <= sizeof(long))) { + __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(int) <= sizeof(PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { + int val; + int ret = -1; +#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API + Py_ssize_t bytes_copied = PyLong_AsNativeBytes( + x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0)); + if (unlikely(bytes_copied == -1)) { + } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) { + goto raise_overflow; + } else { + ret = 0; + } +#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray) + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + ret = _PyLong_AsByteArray((PyLongObject *)x, + bytes, sizeof(val), + is_little, !is_unsigned); +#else + PyObject *v; + PyObject *stepval = NULL, *mask = NULL, *shift = NULL; + int bits, remaining_bits, is_negative = 0; + int chunk_size = (sizeof(long) < 8) ? 30 : 62; + if (likely(PyLong_CheckExact(x))) { + v = __Pyx_NewRef(x); + } else { + v = PyNumber_Long(x); + if (unlikely(!v)) return (int) -1; + assert(PyLong_CheckExact(v)); + } + { + int result = PyObject_RichCompareBool(v, Py_False, Py_LT); + if (unlikely(result < 0)) { + Py_DECREF(v); + return (int) -1; + } + is_negative = result == 1; + } + if (is_unsigned && unlikely(is_negative)) { + Py_DECREF(v); + goto raise_neg_overflow; + } else if (is_negative) { + stepval = PyNumber_Invert(v); + Py_DECREF(v); + if (unlikely(!stepval)) + return (int) -1; + } else { + stepval = v; + } + v = NULL; + val = (int) 0; + mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done; + shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done; + for (bits = 0; bits < (int) sizeof(int) * 8 - chunk_size; bits += chunk_size) { + PyObject *tmp, *digit; + long idigit; + digit = PyNumber_And(stepval, mask); + if (unlikely(!digit)) goto done; + idigit = PyLong_AsLong(digit); + Py_DECREF(digit); + if (unlikely(idigit < 0)) goto done; + val |= ((int) idigit) << bits; + tmp = PyNumber_Rshift(stepval, shift); + if (unlikely(!tmp)) goto done; + Py_DECREF(stepval); stepval = tmp; + } + Py_DECREF(shift); shift = NULL; + Py_DECREF(mask); mask = NULL; + { + long idigit = PyLong_AsLong(stepval); + if (unlikely(idigit < 0)) goto done; + remaining_bits = ((int) sizeof(int) * 8) - bits - (is_unsigned ? 0 : 1); + if (unlikely(idigit >= (1L << remaining_bits))) + goto raise_overflow; + val |= ((int) idigit) << bits; + } + if (!is_unsigned) { + if (unlikely(val & (((int) 1) << (sizeof(int) * 8 - 1)))) + goto raise_overflow; + if (is_negative) + val = ~val; + } + ret = 0; + done: + Py_XDECREF(shift); + Py_XDECREF(mask); + Py_XDECREF(stepval); +#endif + if (unlikely(ret)) + return (int) -1; + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to int"); + return (int) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int"); + return (int) -1; +} + +/* CIntFromPy */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if ((sizeof(long) < sizeof(long))) { + __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (long) val; + } + } +#endif + if (unlikely(!PyLong_Check(x))) { + long val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (long) -1; + val = __Pyx_PyInt_As_long(tmp); + Py_DECREF(tmp); + return val; + } + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + if (unlikely(__Pyx_PyLong_IsNeg(x))) { + goto raise_neg_overflow; + } else if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_DigitCount(x)) { + case 2: + if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) >= 2 * PyLong_SHIFT)) { + return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 3: + if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) >= 3 * PyLong_SHIFT)) { + return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 4: + if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) >= 4 * PyLong_SHIFT)) { + return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + } + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7 + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (long) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if ((sizeof(long) <= sizeof(unsigned long))) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(long) <= sizeof(unsigned PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_SignedDigitCount(x)) { + case -2: + if ((8 * sizeof(long) - 1 > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) { + return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 2: + if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) { + return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -3: + if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) { + return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 3: + if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) { + return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -4: + if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) { + return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 4: + if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) { + return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + } + } +#endif + if ((sizeof(long) <= sizeof(long))) { + __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(long) <= sizeof(PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { + long val; + int ret = -1; +#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API + Py_ssize_t bytes_copied = PyLong_AsNativeBytes( + x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0)); + if (unlikely(bytes_copied == -1)) { + } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) { + goto raise_overflow; + } else { + ret = 0; + } +#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray) + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + ret = _PyLong_AsByteArray((PyLongObject *)x, + bytes, sizeof(val), + is_little, !is_unsigned); +#else + PyObject *v; + PyObject *stepval = NULL, *mask = NULL, *shift = NULL; + int bits, remaining_bits, is_negative = 0; + int chunk_size = (sizeof(long) < 8) ? 30 : 62; + if (likely(PyLong_CheckExact(x))) { + v = __Pyx_NewRef(x); + } else { + v = PyNumber_Long(x); + if (unlikely(!v)) return (long) -1; + assert(PyLong_CheckExact(v)); + } + { + int result = PyObject_RichCompareBool(v, Py_False, Py_LT); + if (unlikely(result < 0)) { + Py_DECREF(v); + return (long) -1; + } + is_negative = result == 1; + } + if (is_unsigned && unlikely(is_negative)) { + Py_DECREF(v); + goto raise_neg_overflow; + } else if (is_negative) { + stepval = PyNumber_Invert(v); + Py_DECREF(v); + if (unlikely(!stepval)) + return (long) -1; + } else { + stepval = v; + } + v = NULL; + val = (long) 0; + mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done; + shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done; + for (bits = 0; bits < (int) sizeof(long) * 8 - chunk_size; bits += chunk_size) { + PyObject *tmp, *digit; + long idigit; + digit = PyNumber_And(stepval, mask); + if (unlikely(!digit)) goto done; + idigit = PyLong_AsLong(digit); + Py_DECREF(digit); + if (unlikely(idigit < 0)) goto done; + val |= ((long) idigit) << bits; + tmp = PyNumber_Rshift(stepval, shift); + if (unlikely(!tmp)) goto done; + Py_DECREF(stepval); stepval = tmp; + } + Py_DECREF(shift); shift = NULL; + Py_DECREF(mask); mask = NULL; + { + long idigit = PyLong_AsLong(stepval); + if (unlikely(idigit < 0)) goto done; + remaining_bits = ((int) sizeof(long) * 8) - bits - (is_unsigned ? 0 : 1); + if (unlikely(idigit >= (1L << remaining_bits))) + goto raise_overflow; + val |= ((long) idigit) << bits; + } + if (!is_unsigned) { + if (unlikely(val & (((long) 1) << (sizeof(long) * 8 - 1)))) + goto raise_overflow; + if (is_negative) + val = ~val; + } + ret = 0; + done: + Py_XDECREF(shift); + Py_XDECREF(mask); + Py_XDECREF(stepval); +#endif + if (unlikely(ret)) + return (long) -1; + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to long"); + return (long) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long) -1; +} + +/* CIntToPy */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_int(int value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const int neg_one = (int) -1, const_zero = (int) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(int) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(int) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(int) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(int) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + unsigned char *bytes = (unsigned char *)&value; +#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4 + if (is_unsigned) { + return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1); + } else { + return PyLong_FromNativeBytes(bytes, sizeof(value), -1); + } +#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000 + int one = 1; int little = (int)*(unsigned char *)&one; + return _PyLong_FromByteArray(bytes, sizeof(int), + little, !is_unsigned); +#else + int one = 1; int little = (int)*(unsigned char *)&one; + PyObject *from_bytes, *result = NULL; + PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL; + from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes"); + if (!from_bytes) return NULL; + py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(int)); + if (!py_bytes) goto limited_bad; + order_str = PyUnicode_FromString(little ? "little" : "big"); + if (!order_str) goto limited_bad; + arg_tuple = PyTuple_Pack(2, py_bytes, order_str); + if (!arg_tuple) goto limited_bad; + if (!is_unsigned) { + kwds = PyDict_New(); + if (!kwds) goto limited_bad; + if (PyDict_SetItemString(kwds, "signed", __Pyx_NewRef(Py_True))) goto limited_bad; + } + result = PyObject_Call(from_bytes, arg_tuple, kwds); + limited_bad: + Py_XDECREF(kwds); + Py_XDECREF(arg_tuple); + Py_XDECREF(order_str); + Py_XDECREF(py_bytes); + Py_XDECREF(from_bytes); + return result; +#endif + } +} + +/* CIntToPy */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(long) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(long) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + unsigned char *bytes = (unsigned char *)&value; +#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4 + if (is_unsigned) { + return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1); + } else { + return PyLong_FromNativeBytes(bytes, sizeof(value), -1); + } +#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000 + int one = 1; int little = (int)*(unsigned char *)&one; + return _PyLong_FromByteArray(bytes, sizeof(long), + little, !is_unsigned); +#else + int one = 1; int little = (int)*(unsigned char *)&one; + PyObject *from_bytes, *result = NULL; + PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL; + from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes"); + if (!from_bytes) return NULL; + py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(long)); + if (!py_bytes) goto limited_bad; + order_str = PyUnicode_FromString(little ? "little" : "big"); + if (!order_str) goto limited_bad; + arg_tuple = PyTuple_Pack(2, py_bytes, order_str); + if (!arg_tuple) goto limited_bad; + if (!is_unsigned) { + kwds = PyDict_New(); + if (!kwds) goto limited_bad; + if (PyDict_SetItemString(kwds, "signed", __Pyx_NewRef(Py_True))) goto limited_bad; + } + result = PyObject_Call(from_bytes, arg_tuple, kwds); + limited_bad: + Py_XDECREF(kwds); + Py_XDECREF(arg_tuple); + Py_XDECREF(order_str); + Py_XDECREF(py_bytes); + Py_XDECREF(from_bytes); + return result; +#endif + } +} + +/* FormatTypeName */ +#if CYTHON_COMPILING_IN_LIMITED_API +static __Pyx_TypeName +__Pyx_PyType_GetName(PyTypeObject* tp) +{ + PyObject *name = __Pyx_PyObject_GetAttrStr((PyObject *)tp, + __pyx_n_s_name); + if (unlikely(name == NULL) || unlikely(!PyUnicode_Check(name))) { + PyErr_Clear(); + Py_XDECREF(name); + name = __Pyx_NewRef(__pyx_n_s__24); + } + return name; +} +#endif + +/* CStringEquals */ +static CYTHON_INLINE int __Pyx_StrEq(const char *s1, const char *s2) { + while (*s1 != '\0' && *s1 == *s2) { s1++; s2++; } + return *s1 == *s2; +} + +/* CheckBinaryVersion */ +static unsigned long __Pyx_get_runtime_version(void) { +#if __PYX_LIMITED_VERSION_HEX >= 0x030B00A4 + return Py_Version & ~0xFFUL; +#else + const char* rt_version = Py_GetVersion(); + unsigned long version = 0; + unsigned long factor = 0x01000000UL; + unsigned int digit = 0; + int i = 0; + while (factor) { + while ('0' <= rt_version[i] && rt_version[i] <= '9') { + digit = digit * 10 + (unsigned int) (rt_version[i] - '0'); + ++i; + } + version += factor * digit; + if (rt_version[i] != '.') + break; + digit = 0; + factor >>= 8; + ++i; + } + return version; +#endif +} +static int __Pyx_check_binary_version(unsigned long ct_version, unsigned long rt_version, int allow_newer) { + const unsigned long MAJOR_MINOR = 0xFFFF0000UL; + if ((rt_version & MAJOR_MINOR) == (ct_version & MAJOR_MINOR)) + return 0; + if (likely(allow_newer && (rt_version & MAJOR_MINOR) > (ct_version & MAJOR_MINOR))) + return 1; + { + char message[200]; + PyOS_snprintf(message, sizeof(message), + "compile time Python version %d.%d " + "of module '%.100s' " + "%s " + "runtime version %d.%d", + (int) (ct_version >> 24), (int) ((ct_version >> 16) & 0xFF), + __Pyx_MODULE_NAME, + (allow_newer) ? "was newer than" : "does not match", + (int) (rt_version >> 24), (int) ((rt_version >> 16) & 0xFF) + ); + return PyErr_WarnEx(NULL, message, 1); + } +} + +/* InitStrings */ +#if PY_MAJOR_VERSION >= 3 +static int __Pyx_InitString(__Pyx_StringTabEntry t, PyObject **str) { + if (t.is_unicode | t.is_str) { + if (t.intern) { + *str = PyUnicode_InternFromString(t.s); + } else if (t.encoding) { + *str = PyUnicode_Decode(t.s, t.n - 1, t.encoding, NULL); + } else { + *str = PyUnicode_FromStringAndSize(t.s, t.n - 1); + } + } else { + *str = PyBytes_FromStringAndSize(t.s, t.n - 1); + } + if (!*str) + return -1; + if (PyObject_Hash(*str) == -1) + return -1; + return 0; +} +#endif +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + #if PY_MAJOR_VERSION >= 3 + __Pyx_InitString(*t, t->p); + #else + if (t->is_unicode) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + if (!*t->p) + return -1; + if (PyObject_Hash(*t->p) == -1) + return -1; + #endif + ++t; + } + return 0; +} + +#include +static CYTHON_INLINE Py_ssize_t __Pyx_ssize_strlen(const char *s) { + size_t len = strlen(s); + if (unlikely(len > (size_t) PY_SSIZE_T_MAX)) { + PyErr_SetString(PyExc_OverflowError, "byte string is too long"); + return -1; + } + return (Py_ssize_t) len; +} +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { + Py_ssize_t len = __Pyx_ssize_strlen(c_str); + if (unlikely(len < 0)) return NULL; + return __Pyx_PyUnicode_FromStringAndSize(c_str, len); +} +static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char* c_str) { + Py_ssize_t len = __Pyx_ssize_strlen(c_str); + if (unlikely(len < 0)) return NULL; + return PyByteArray_FromStringAndSize(c_str, len); +} +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) { + Py_ssize_t ignore; + return __Pyx_PyObject_AsStringAndSize(o, &ignore); +} +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +#if !CYTHON_PEP393_ENABLED +static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + char* defenc_c; + PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); + if (!defenc) return NULL; + defenc_c = PyBytes_AS_STRING(defenc); +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + { + char* end = defenc_c + PyBytes_GET_SIZE(defenc); + char* c; + for (c = defenc_c; c < end; c++) { + if ((unsigned char) (*c) >= 128) { + PyUnicode_AsASCIIString(o); + return NULL; + } + } + } +#endif + *length = PyBytes_GET_SIZE(defenc); + return defenc_c; +} +#else +static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL; +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + if (likely(PyUnicode_IS_ASCII(o))) { + *length = PyUnicode_GET_LENGTH(o); + return PyUnicode_AsUTF8(o); + } else { + PyUnicode_AsASCIIString(o); + return NULL; + } +#else + return PyUnicode_AsUTF8AndSize(o, length); +#endif +} +#endif +#endif +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT + if ( +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + __Pyx_sys_getdefaultencoding_not_ascii && +#endif + PyUnicode_Check(o)) { + return __Pyx_PyUnicode_AsStringAndSize(o, length); + } else +#endif +#if (!CYTHON_COMPILING_IN_PYPY && !CYTHON_COMPILING_IN_LIMITED_API) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) + if (PyByteArray_Check(o)) { + *length = PyByteArray_GET_SIZE(o); + return PyByteArray_AS_STRING(o); + } else +#endif + { + char* result; + int r = PyBytes_AsStringAndSize(o, &result, length); + if (unlikely(r < 0)) { + return NULL; + } else { + return result; + } + } +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + int is_true = x == Py_True; + if (is_true | (x == Py_False) | (x == Py_None)) return is_true; + else return PyObject_IsTrue(x); +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { + int retval; + if (unlikely(!x)) return -1; + retval = __Pyx_PyObject_IsTrue(x); + Py_DECREF(x); + return retval; +} +static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) { + __Pyx_TypeName result_type_name = __Pyx_PyType_GetName(Py_TYPE(result)); +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(result)) { + if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + "__int__ returned non-int (type " __Pyx_FMT_TYPENAME "). " + "The ability to return an instance of a strict subclass of int is deprecated, " + "and may be removed in a future version of Python.", + result_type_name)) { + __Pyx_DECREF_TypeName(result_type_name); + Py_DECREF(result); + return NULL; + } + __Pyx_DECREF_TypeName(result_type_name); + return result; + } +#endif + PyErr_Format(PyExc_TypeError, + "__%.4s__ returned non-%.4s (type " __Pyx_FMT_TYPENAME ")", + type_name, type_name, result_type_name); + __Pyx_DECREF_TypeName(result_type_name); + Py_DECREF(result); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { +#if CYTHON_USE_TYPE_SLOTS + PyNumberMethods *m; +#endif + const char *name = NULL; + PyObject *res = NULL; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x) || PyLong_Check(x))) +#else + if (likely(PyLong_Check(x))) +#endif + return __Pyx_NewRef(x); +#if CYTHON_USE_TYPE_SLOTS + m = Py_TYPE(x)->tp_as_number; + #if PY_MAJOR_VERSION < 3 + if (m && m->nb_int) { + name = "int"; + res = m->nb_int(x); + } + else if (m && m->nb_long) { + name = "long"; + res = m->nb_long(x); + } + #else + if (likely(m && m->nb_int)) { + name = "int"; + res = m->nb_int(x); + } + #endif +#else + if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) { + res = PyNumber_Int(x); + } +#endif + if (likely(res)) { +#if PY_MAJOR_VERSION < 3 + if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) { +#else + if (unlikely(!PyLong_CheckExact(res))) { +#endif + return __Pyx_PyNumber_IntOrLongWrongResultType(res, name); + } + } + else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); + } + return res; +} +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject *x; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(b))) { + if (sizeof(Py_ssize_t) >= sizeof(long)) + return PyInt_AS_LONG(b); + else + return PyInt_AsSsize_t(b); + } +#endif + if (likely(PyLong_CheckExact(b))) { + #if CYTHON_USE_PYLONG_INTERNALS + if (likely(__Pyx_PyLong_IsCompact(b))) { + return __Pyx_PyLong_CompactValue(b); + } else { + const digit* digits = __Pyx_PyLong_Digits(b); + const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount(b); + switch (size) { + case 2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + } + } + #endif + return PyLong_AsSsize_t(b); + } + x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} +static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject* o) { + if (sizeof(Py_hash_t) == sizeof(Py_ssize_t)) { + return (Py_hash_t) __Pyx_PyIndex_AsSsize_t(o); +#if PY_MAJOR_VERSION < 3 + } else if (likely(PyInt_CheckExact(o))) { + return PyInt_AS_LONG(o); +#endif + } else { + Py_ssize_t ival; + PyObject *x; + x = PyNumber_Index(o); + if (!x) return -1; + ival = PyInt_AsLong(x); + Py_DECREF(x); + return ival; + } +} +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) { + return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False); +} +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { + return PyInt_FromSize_t(ival); +} + + +/* #### Code section: utility_code_pragmas_end ### */ +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + + + +/* #### Code section: end ### */ +#endif /* Py_PYTHON_H */ diff --git a/bot/build/cython_code/throttling_middleware.c b/bot/build/cython_code/throttling_middleware.c new file mode 100644 index 0000000..64e4c16 --- /dev/null +++ b/bot/build/cython_code/throttling_middleware.c @@ -0,0 +1,12190 @@ +/* Generated by Cython 3.0.11 */ + +/* BEGIN: Cython Metadata +{ + "distutils": { + "name": "cython_code.throttling_middleware", + "sources": [ + "cython_code/throttling_middleware.pyx" + ] + }, + "module_name": "cython_code.throttling_middleware" +} +END: Cython Metadata */ + +#ifndef PY_SSIZE_T_CLEAN +#define PY_SSIZE_T_CLEAN +#endif /* PY_SSIZE_T_CLEAN */ +#if defined(CYTHON_LIMITED_API) && 0 + #ifndef Py_LIMITED_API + #if CYTHON_LIMITED_API+0 > 0x03030000 + #define Py_LIMITED_API CYTHON_LIMITED_API + #else + #define Py_LIMITED_API 0x03030000 + #endif + #endif +#endif + +#include "Python.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#elif PY_VERSION_HEX < 0x02070000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) + #error Cython requires Python 2.7+ or Python 3.3+. +#else +#if defined(CYTHON_LIMITED_API) && CYTHON_LIMITED_API +#define __PYX_EXTRA_ABI_MODULE_NAME "limited" +#else +#define __PYX_EXTRA_ABI_MODULE_NAME "" +#endif +#define CYTHON_ABI "3_0_11" __PYX_EXTRA_ABI_MODULE_NAME +#define __PYX_ABI_MODULE_NAME "_cython_" CYTHON_ABI +#define __PYX_TYPE_MODULE_PREFIX __PYX_ABI_MODULE_NAME "." +#define CYTHON_HEX_VERSION 0x03000BF0 +#define CYTHON_FUTURE_DIVISION 1 +#include +#ifndef offsetof + #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) +#endif +#if !defined(_WIN32) && !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#endif +#ifndef DL_IMPORT + #define DL_IMPORT(t) t +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif +#define __PYX_COMMA , +#ifndef HAVE_LONG_LONG + #define HAVE_LONG_LONG +#endif +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifndef Py_HUGE_VAL + #define Py_HUGE_VAL HUGE_VAL +#endif +#define __PYX_LIMITED_VERSION_HEX PY_VERSION_HEX +#if defined(GRAALVM_PYTHON) + /* For very preliminary testing purposes. Most variables are set the same as PyPy. + The existence of this section does not imply that anything works or is even tested */ + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 1 + #define CYTHON_COMPILING_IN_NOGIL 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #undef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS (PY_MAJOR_VERSION >= 3) + #endif + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #undef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #endif + #undef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 +#elif defined(PYPY_VERSION) + #define CYTHON_COMPILING_IN_PYPY 1 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #ifndef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #undef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS (PY_MAJOR_VERSION >= 3) + #endif + #if PY_VERSION_HEX < 0x03090000 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #elif !defined(CYTHON_PEP489_MULTI_PHASE_INIT) + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #undef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1 && PYPY_VERSION_NUM >= 0x07030C00) + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #endif + #undef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 +#elif defined(CYTHON_LIMITED_API) + #ifdef Py_LIMITED_API + #undef __PYX_LIMITED_VERSION_HEX + #define __PYX_LIMITED_VERSION_HEX Py_LIMITED_API + #endif + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 1 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 0 + #undef CYTHON_CLINE_IN_TRACEBACK + #define CYTHON_CLINE_IN_TRACEBACK 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 1 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #endif + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #undef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS 1 + #endif + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #undef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 1 + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #endif + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #endif + #undef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 +#elif defined(Py_GIL_DISABLED) || defined(Py_NOGIL) + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 1 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #ifndef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #ifndef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #ifndef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #ifndef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 1 + #endif + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS 1 + #endif + #ifndef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #ifndef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #endif + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 1 + #endif + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 1 + #endif + #ifndef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 + #endif +#else + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 1 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 0 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #ifndef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #endif + #ifndef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 1 + #endif + #if PY_MAJOR_VERSION < 3 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #ifndef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 1 + #endif + #ifndef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 1 + #endif + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #if PY_VERSION_HEX < 0x030300F0 || PY_VERSION_HEX >= 0x030B00A2 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #elif !defined(CYTHON_USE_UNICODE_WRITER) + #define CYTHON_USE_UNICODE_WRITER 1 + #endif + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #ifndef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 1 + #endif + #ifndef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL (PY_MAJOR_VERSION < 3 || PY_VERSION_HEX >= 0x03060000 && PY_VERSION_HEX < 0x030C00A6) + #endif + #ifndef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL (PY_VERSION_HEX >= 0x030700A1) + #endif + #ifndef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 1 + #endif + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS 1 + #endif + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #elif !defined(CYTHON_PEP489_MULTI_PHASE_INIT) + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #ifndef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #endif + #if PY_VERSION_HEX < 0x030400a1 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #elif !defined(CYTHON_USE_TP_FINALIZE) + #define CYTHON_USE_TP_FINALIZE 1 + #endif + #if PY_VERSION_HEX < 0x030600B1 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #elif !defined(CYTHON_USE_DICT_VERSIONS) + #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX < 0x030C00A5) + #endif + #if PY_VERSION_HEX < 0x030700A3 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #elif !defined(CYTHON_USE_EXC_INFO_STACK) + #define CYTHON_USE_EXC_INFO_STACK 1 + #endif + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 1 + #endif + #ifndef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 1 + #endif +#endif +#if !defined(CYTHON_FAST_PYCCALL) +#define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) +#endif +#if !defined(CYTHON_VECTORCALL) +#define CYTHON_VECTORCALL (CYTHON_FAST_PYCCALL && PY_VERSION_HEX >= 0x030800B1) +#endif +#define CYTHON_BACKPORT_VECTORCALL (CYTHON_METH_FASTCALL && PY_VERSION_HEX < 0x030800B1) +#if CYTHON_USE_PYLONG_INTERNALS + #if PY_MAJOR_VERSION < 3 + #include "longintrepr.h" + #endif + #undef SHIFT + #undef BASE + #undef MASK + #ifdef SIZEOF_VOID_P + enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; + #endif +#endif +#ifndef __has_attribute + #define __has_attribute(x) 0 +#endif +#ifndef __has_cpp_attribute + #define __has_cpp_attribute(x) 0 +#endif +#ifndef CYTHON_RESTRICT + #if defined(__GNUC__) + #define CYTHON_RESTRICT __restrict__ + #elif defined(_MSC_VER) && _MSC_VER >= 1400 + #define CYTHON_RESTRICT __restrict + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_RESTRICT restrict + #else + #define CYTHON_RESTRICT + #endif +#endif +#ifndef CYTHON_UNUSED + #if defined(__cplusplus) + /* for clang __has_cpp_attribute(maybe_unused) is true even before C++17 + * but leads to warnings with -pedantic, since it is a C++17 feature */ + #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) + #if __has_cpp_attribute(maybe_unused) + #define CYTHON_UNUSED [[maybe_unused]] + #endif + #endif + #endif +#endif +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_UNUSED_VAR +# if defined(__cplusplus) + template void CYTHON_UNUSED_VAR( const T& ) { } +# else +# define CYTHON_UNUSED_VAR(x) (void)(x) +# endif +#endif +#ifndef CYTHON_MAYBE_UNUSED_VAR + #define CYTHON_MAYBE_UNUSED_VAR(x) CYTHON_UNUSED_VAR(x) +#endif +#ifndef CYTHON_NCP_UNUSED +# if CYTHON_COMPILING_IN_CPYTHON +# define CYTHON_NCP_UNUSED +# else +# define CYTHON_NCP_UNUSED CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_USE_CPP_STD_MOVE + #if defined(__cplusplus) && (\ + __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600)) + #define CYTHON_USE_CPP_STD_MOVE 1 + #else + #define CYTHON_USE_CPP_STD_MOVE 0 + #endif +#endif +#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) +#ifdef _MSC_VER + #ifndef _MSC_STDINT_H_ + #if _MSC_VER < 1300 + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + typedef unsigned int uint32_t; + #else + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; + #endif + #endif + #if _MSC_VER < 1300 + #ifdef _WIN64 + typedef unsigned long long __pyx_uintptr_t; + #else + typedef unsigned int __pyx_uintptr_t; + #endif + #else + #ifdef _WIN64 + typedef unsigned __int64 __pyx_uintptr_t; + #else + typedef unsigned __int32 __pyx_uintptr_t; + #endif + #endif +#else + #include + typedef uintptr_t __pyx_uintptr_t; +#endif +#ifndef CYTHON_FALLTHROUGH + #if defined(__cplusplus) + /* for clang __has_cpp_attribute(fallthrough) is true even before C++17 + * but leads to warnings with -pedantic, since it is a C++17 feature */ + #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) + #if __has_cpp_attribute(fallthrough) + #define CYTHON_FALLTHROUGH [[fallthrough]] + #endif + #endif + #ifndef CYTHON_FALLTHROUGH + #if __has_cpp_attribute(clang::fallthrough) + #define CYTHON_FALLTHROUGH [[clang::fallthrough]] + #elif __has_cpp_attribute(gnu::fallthrough) + #define CYTHON_FALLTHROUGH [[gnu::fallthrough]] + #endif + #endif + #endif + #ifndef CYTHON_FALLTHROUGH + #if __has_attribute(fallthrough) + #define CYTHON_FALLTHROUGH __attribute__((fallthrough)) + #else + #define CYTHON_FALLTHROUGH + #endif + #endif + #if defined(__clang__) && defined(__apple_build_version__) + #if __apple_build_version__ < 7000000 + #undef CYTHON_FALLTHROUGH + #define CYTHON_FALLTHROUGH + #endif + #endif +#endif +#ifdef __cplusplus + template + struct __PYX_IS_UNSIGNED_IMPL {static const bool value = T(0) < T(-1);}; + #define __PYX_IS_UNSIGNED(type) (__PYX_IS_UNSIGNED_IMPL::value) +#else + #define __PYX_IS_UNSIGNED(type) (((type)-1) > 0) +#endif +#if CYTHON_COMPILING_IN_PYPY == 1 + #define __PYX_NEED_TP_PRINT_SLOT (PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x030A0000) +#else + #define __PYX_NEED_TP_PRINT_SLOT (PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000) +#endif +#define __PYX_REINTERPRET_FUNCION(func_pointer, other_pointer) ((func_pointer)(void(*)(void))(other_pointer)) + +#ifndef CYTHON_INLINE + #if defined(__clang__) + #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) + #elif defined(__GNUC__) + #define CYTHON_INLINE __inline__ + #elif defined(_MSC_VER) + #define CYTHON_INLINE __inline + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_INLINE inline + #else + #define CYTHON_INLINE + #endif +#endif + +#define __PYX_BUILD_PY_SSIZE_T "n" +#define CYTHON_FORMAT_SSIZE_T "z" +#if PY_MAJOR_VERSION < 3 + #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" + #define __Pyx_DefaultClassType PyClass_Type + #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #define __Pyx_BUILTIN_MODULE_NAME "builtins" + #define __Pyx_DefaultClassType PyType_Type +#if CYTHON_COMPILING_IN_LIMITED_API + static CYTHON_INLINE PyObject* __Pyx_PyCode_New(int a, int p, int k, int l, int s, int f, + PyObject *code, PyObject *c, PyObject* n, PyObject *v, + PyObject *fv, PyObject *cell, PyObject* fn, + PyObject *name, int fline, PyObject *lnos) { + PyObject *exception_table = NULL; + PyObject *types_module=NULL, *code_type=NULL, *result=NULL; + #if __PYX_LIMITED_VERSION_HEX < 0x030B0000 + PyObject *version_info; + PyObject *py_minor_version = NULL; + #endif + long minor_version = 0; + PyObject *type, *value, *traceback; + PyErr_Fetch(&type, &value, &traceback); + #if __PYX_LIMITED_VERSION_HEX >= 0x030B0000 + minor_version = 11; + #else + if (!(version_info = PySys_GetObject("version_info"))) goto end; + if (!(py_minor_version = PySequence_GetItem(version_info, 1))) goto end; + minor_version = PyLong_AsLong(py_minor_version); + Py_DECREF(py_minor_version); + if (minor_version == -1 && PyErr_Occurred()) goto end; + #endif + if (!(types_module = PyImport_ImportModule("types"))) goto end; + if (!(code_type = PyObject_GetAttrString(types_module, "CodeType"))) goto end; + if (minor_version <= 7) { + (void)p; + result = PyObject_CallFunction(code_type, "iiiiiOOOOOOiOO", a, k, l, s, f, code, + c, n, v, fn, name, fline, lnos, fv, cell); + } else if (minor_version <= 10) { + result = PyObject_CallFunction(code_type, "iiiiiiOOOOOOiOO", a,p, k, l, s, f, code, + c, n, v, fn, name, fline, lnos, fv, cell); + } else { + if (!(exception_table = PyBytes_FromStringAndSize(NULL, 0))) goto end; + result = PyObject_CallFunction(code_type, "iiiiiiOOOOOOOiOO", a,p, k, l, s, f, code, + c, n, v, fn, name, name, fline, lnos, exception_table, fv, cell); + } + end: + Py_XDECREF(code_type); + Py_XDECREF(exception_table); + Py_XDECREF(types_module); + if (type) { + PyErr_Restore(type, value, traceback); + } + return result; + } + #ifndef CO_OPTIMIZED + #define CO_OPTIMIZED 0x0001 + #endif + #ifndef CO_NEWLOCALS + #define CO_NEWLOCALS 0x0002 + #endif + #ifndef CO_VARARGS + #define CO_VARARGS 0x0004 + #endif + #ifndef CO_VARKEYWORDS + #define CO_VARKEYWORDS 0x0008 + #endif + #ifndef CO_ASYNC_GENERATOR + #define CO_ASYNC_GENERATOR 0x0200 + #endif + #ifndef CO_GENERATOR + #define CO_GENERATOR 0x0020 + #endif + #ifndef CO_COROUTINE + #define CO_COROUTINE 0x0080 + #endif +#elif PY_VERSION_HEX >= 0x030B0000 + static CYTHON_INLINE PyCodeObject* __Pyx_PyCode_New(int a, int p, int k, int l, int s, int f, + PyObject *code, PyObject *c, PyObject* n, PyObject *v, + PyObject *fv, PyObject *cell, PyObject* fn, + PyObject *name, int fline, PyObject *lnos) { + PyCodeObject *result; + PyObject *empty_bytes = PyBytes_FromStringAndSize("", 0); + if (!empty_bytes) return NULL; + result = + #if PY_VERSION_HEX >= 0x030C0000 + PyUnstable_Code_NewWithPosOnlyArgs + #else + PyCode_NewWithPosOnlyArgs + #endif + (a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, name, fline, lnos, empty_bytes); + Py_DECREF(empty_bytes); + return result; + } +#elif PY_VERSION_HEX >= 0x030800B2 && !CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_NewWithPosOnlyArgs(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#endif +#endif +#if PY_VERSION_HEX >= 0x030900A4 || defined(Py_IS_TYPE) + #define __Pyx_IS_TYPE(ob, type) Py_IS_TYPE(ob, type) +#else + #define __Pyx_IS_TYPE(ob, type) (((const PyObject*)ob)->ob_type == (type)) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_Is) + #define __Pyx_Py_Is(x, y) Py_Is(x, y) +#else + #define __Pyx_Py_Is(x, y) ((x) == (y)) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsNone) + #define __Pyx_Py_IsNone(ob) Py_IsNone(ob) +#else + #define __Pyx_Py_IsNone(ob) __Pyx_Py_Is((ob), Py_None) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsTrue) + #define __Pyx_Py_IsTrue(ob) Py_IsTrue(ob) +#else + #define __Pyx_Py_IsTrue(ob) __Pyx_Py_Is((ob), Py_True) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsFalse) + #define __Pyx_Py_IsFalse(ob) Py_IsFalse(ob) +#else + #define __Pyx_Py_IsFalse(ob) __Pyx_Py_Is((ob), Py_False) +#endif +#define __Pyx_NoneAsNull(obj) (__Pyx_Py_IsNone(obj) ? NULL : (obj)) +#if PY_VERSION_HEX >= 0x030900F0 && !CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyObject_GC_IsFinalized(o) PyObject_GC_IsFinalized(o) +#else + #define __Pyx_PyObject_GC_IsFinalized(o) _PyGC_FINALIZED(o) +#endif +#ifndef CO_COROUTINE + #define CO_COROUTINE 0x80 +#endif +#ifndef CO_ASYNC_GENERATOR + #define CO_ASYNC_GENERATOR 0x200 +#endif +#ifndef Py_TPFLAGS_CHECKTYPES + #define Py_TPFLAGS_CHECKTYPES 0 +#endif +#ifndef Py_TPFLAGS_HAVE_INDEX + #define Py_TPFLAGS_HAVE_INDEX 0 +#endif +#ifndef Py_TPFLAGS_HAVE_NEWBUFFER + #define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif +#ifndef Py_TPFLAGS_HAVE_FINALIZE + #define Py_TPFLAGS_HAVE_FINALIZE 0 +#endif +#ifndef Py_TPFLAGS_SEQUENCE + #define Py_TPFLAGS_SEQUENCE 0 +#endif +#ifndef Py_TPFLAGS_MAPPING + #define Py_TPFLAGS_MAPPING 0 +#endif +#ifndef METH_STACKLESS + #define METH_STACKLESS 0 +#endif +#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL) + #ifndef METH_FASTCALL + #define METH_FASTCALL 0x80 + #endif + typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs); + typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args, + Py_ssize_t nargs, PyObject *kwnames); +#else + #if PY_VERSION_HEX >= 0x030d00A4 + # define __Pyx_PyCFunctionFast PyCFunctionFast + # define __Pyx_PyCFunctionFastWithKeywords PyCFunctionFastWithKeywords + #else + # define __Pyx_PyCFunctionFast _PyCFunctionFast + # define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords + #endif +#endif +#if CYTHON_METH_FASTCALL + #define __Pyx_METH_FASTCALL METH_FASTCALL + #define __Pyx_PyCFunction_FastCall __Pyx_PyCFunctionFast + #define __Pyx_PyCFunction_FastCallWithKeywords __Pyx_PyCFunctionFastWithKeywords +#else + #define __Pyx_METH_FASTCALL METH_VARARGS + #define __Pyx_PyCFunction_FastCall PyCFunction + #define __Pyx_PyCFunction_FastCallWithKeywords PyCFunctionWithKeywords +#endif +#if CYTHON_VECTORCALL + #define __pyx_vectorcallfunc vectorcallfunc + #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET PY_VECTORCALL_ARGUMENTS_OFFSET + #define __Pyx_PyVectorcall_NARGS(n) PyVectorcall_NARGS((size_t)(n)) +#elif CYTHON_BACKPORT_VECTORCALL + typedef PyObject *(*__pyx_vectorcallfunc)(PyObject *callable, PyObject *const *args, + size_t nargsf, PyObject *kwnames); + #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET ((size_t)1 << (8 * sizeof(size_t) - 1)) + #define __Pyx_PyVectorcall_NARGS(n) ((Py_ssize_t)(((size_t)(n)) & ~__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)) +#else + #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET 0 + #define __Pyx_PyVectorcall_NARGS(n) ((Py_ssize_t)(n)) +#endif +#if PY_MAJOR_VERSION >= 0x030900B1 +#define __Pyx_PyCFunction_CheckExact(func) PyCFunction_CheckExact(func) +#else +#define __Pyx_PyCFunction_CheckExact(func) PyCFunction_Check(func) +#endif +#define __Pyx_CyOrPyCFunction_Check(func) PyCFunction_Check(func) +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_CyOrPyCFunction_GET_FUNCTION(func) (((PyCFunctionObject*)(func))->m_ml->ml_meth) +#elif !CYTHON_COMPILING_IN_LIMITED_API +#define __Pyx_CyOrPyCFunction_GET_FUNCTION(func) PyCFunction_GET_FUNCTION(func) +#endif +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_CyOrPyCFunction_GET_FLAGS(func) (((PyCFunctionObject*)(func))->m_ml->ml_flags) +static CYTHON_INLINE PyObject* __Pyx_CyOrPyCFunction_GET_SELF(PyObject *func) { + return (__Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_STATIC) ? NULL : ((PyCFunctionObject*)func)->m_self; +} +#endif +static CYTHON_INLINE int __Pyx__IsSameCFunction(PyObject *func, void *cfunc) { +#if CYTHON_COMPILING_IN_LIMITED_API + return PyCFunction_Check(func) && PyCFunction_GetFunction(func) == (PyCFunction) cfunc; +#else + return PyCFunction_Check(func) && PyCFunction_GET_FUNCTION(func) == (PyCFunction) cfunc; +#endif +} +#define __Pyx_IsSameCFunction(func, cfunc) __Pyx__IsSameCFunction(func, cfunc) +#if __PYX_LIMITED_VERSION_HEX < 0x030900B1 + #define __Pyx_PyType_FromModuleAndSpec(m, s, b) ((void)m, PyType_FromSpecWithBases(s, b)) + typedef PyObject *(*__Pyx_PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *, size_t, PyObject *); +#else + #define __Pyx_PyType_FromModuleAndSpec(m, s, b) PyType_FromModuleAndSpec(m, s, b) + #define __Pyx_PyCMethod PyCMethod +#endif +#ifndef METH_METHOD + #define METH_METHOD 0x200 +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) + #define PyObject_Malloc(s) PyMem_Malloc(s) + #define PyObject_Free(p) PyMem_Free(p) + #define PyObject_Realloc(p) PyMem_Realloc(p) +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) +#else + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_PyThreadState_Current PyThreadState_Get() +#elif !CYTHON_FAST_THREAD_STATE + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#elif PY_VERSION_HEX >= 0x030d00A1 + #define __Pyx_PyThreadState_Current PyThreadState_GetUnchecked() +#elif PY_VERSION_HEX >= 0x03060000 + #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet() +#elif PY_VERSION_HEX >= 0x03000000 + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#else + #define __Pyx_PyThreadState_Current _PyThreadState_Current +#endif +#if CYTHON_COMPILING_IN_LIMITED_API +static CYTHON_INLINE void *__Pyx_PyModule_GetState(PyObject *op) +{ + void *result; + result = PyModule_GetState(op); + if (!result) + Py_FatalError("Couldn't find the module state"); + return result; +} +#endif +#define __Pyx_PyObject_GetSlot(obj, name, func_ctype) __Pyx_PyType_GetSlot(Py_TYPE(obj), name, func_ctype) +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_PyType_GetSlot(type, name, func_ctype) ((func_ctype) PyType_GetSlot((type), Py_##name)) +#else + #define __Pyx_PyType_GetSlot(type, name, func_ctype) ((type)->name) +#endif +#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT) +#include "pythread.h" +#define Py_tss_NEEDS_INIT 0 +typedef int Py_tss_t; +static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) { + *key = PyThread_create_key(); + return 0; +} +static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) { + Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t)); + *key = Py_tss_NEEDS_INIT; + return key; +} +static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) { + PyObject_Free(key); +} +static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) { + return *key != Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) { + PyThread_delete_key(*key); + *key = Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) { + return PyThread_set_key_value(*key, value); +} +static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { + return PyThread_get_key_value(*key); +} +#endif +#if PY_MAJOR_VERSION < 3 + #if CYTHON_COMPILING_IN_PYPY + #if PYPY_VERSION_NUM < 0x07030600 + #if defined(__cplusplus) && __cplusplus >= 201402L + [[deprecated("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6")]] + #elif defined(__GNUC__) || defined(__clang__) + __attribute__ ((__deprecated__("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6"))) + #elif defined(_MSC_VER) + __declspec(deprecated("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6")) + #endif + static CYTHON_INLINE int PyGILState_Check(void) { + return 0; + } + #else // PYPY_VERSION_NUM < 0x07030600 + #endif // PYPY_VERSION_NUM < 0x07030600 + #else + static CYTHON_INLINE int PyGILState_Check(void) { + PyThreadState * tstate = _PyThreadState_Current; + return tstate && (tstate == PyGILState_GetThisThreadState()); + } + #endif +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000 || defined(_PyDict_NewPresized) +#define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n)) +#else +#define __Pyx_PyDict_NewPresized(n) PyDict_New() +#endif +#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX > 0x030600B4 && PY_VERSION_HEX < 0x030d0000 && CYTHON_USE_UNICODE_INTERNALS +#define __Pyx_PyDict_GetItemStrWithError(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash) +static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStr(PyObject *dict, PyObject *name) { + PyObject *res = __Pyx_PyDict_GetItemStrWithError(dict, name); + if (res == NULL) PyErr_Clear(); + return res; +} +#elif PY_MAJOR_VERSION >= 3 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07020000) +#define __Pyx_PyDict_GetItemStrWithError PyDict_GetItemWithError +#define __Pyx_PyDict_GetItemStr PyDict_GetItem +#else +static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict, PyObject *name) { +#if CYTHON_COMPILING_IN_PYPY + return PyDict_GetItem(dict, name); +#else + PyDictEntry *ep; + PyDictObject *mp = (PyDictObject*) dict; + long hash = ((PyStringObject *) name)->ob_shash; + assert(hash != -1); + ep = (mp->ma_lookup)(mp, name, hash); + if (ep == NULL) { + return NULL; + } + return ep->me_value; +#endif +} +#define __Pyx_PyDict_GetItemStr PyDict_GetItem +#endif +#if CYTHON_USE_TYPE_SLOTS + #define __Pyx_PyType_GetFlags(tp) (((PyTypeObject *)tp)->tp_flags) + #define __Pyx_PyType_HasFeature(type, feature) ((__Pyx_PyType_GetFlags(type) & (feature)) != 0) + #define __Pyx_PyObject_GetIterNextFunc(obj) (Py_TYPE(obj)->tp_iternext) +#else + #define __Pyx_PyType_GetFlags(tp) (PyType_GetFlags((PyTypeObject *)tp)) + #define __Pyx_PyType_HasFeature(type, feature) PyType_HasFeature(type, feature) + #define __Pyx_PyObject_GetIterNextFunc(obj) PyIter_Next +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_SetItemOnTypeDict(tp, k, v) PyObject_GenericSetAttr((PyObject*)tp, k, v) +#else + #define __Pyx_SetItemOnTypeDict(tp, k, v) PyDict_SetItem(tp->tp_dict, k, v) +#endif +#if CYTHON_USE_TYPE_SPECS && PY_VERSION_HEX >= 0x03080000 +#define __Pyx_PyHeapTypeObject_GC_Del(obj) {\ + PyTypeObject *type = Py_TYPE((PyObject*)obj);\ + assert(__Pyx_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE));\ + PyObject_GC_Del(obj);\ + Py_DECREF(type);\ +} +#else +#define __Pyx_PyHeapTypeObject_GC_Del(obj) PyObject_GC_Del(obj) +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define CYTHON_PEP393_ENABLED 1 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GetLength(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_ReadChar(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((void)u, 1114111U) + #define __Pyx_PyUnicode_KIND(u) ((void)u, (0)) + #define __Pyx_PyUnicode_DATA(u) ((void*)u) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)k, PyUnicode_ReadChar((PyObject*)(d), i)) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GetLength(u)) +#elif PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) + #define CYTHON_PEP393_ENABLED 1 + #if PY_VERSION_HEX >= 0x030C0000 + #define __Pyx_PyUnicode_READY(op) (0) + #else + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ + 0 : _PyUnicode_Ready((PyObject *)(op))) + #endif + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) + #define __Pyx_PyUnicode_KIND(u) ((int)PyUnicode_KIND(u)) + #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) + #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, (Py_UCS4) ch) + #if PY_VERSION_HEX >= 0x030C0000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) + #else + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length)) + #else + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) + #endif + #endif +#else + #define CYTHON_PEP393_ENABLED 0 + #define PyUnicode_1BYTE_KIND 1 + #define PyUnicode_2BYTE_KIND 2 + #define PyUnicode_4BYTE_KIND 4 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535U : 1114111U) + #define __Pyx_PyUnicode_KIND(u) ((int)sizeof(Py_UNICODE)) + #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = (Py_UNICODE) ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) +#endif +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) +#else + #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ + PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) +#endif +#if CYTHON_COMPILING_IN_PYPY + #if !defined(PyUnicode_DecodeUnicodeEscape) + #define PyUnicode_DecodeUnicodeEscape(s, size, errors) PyUnicode_Decode(s, size, "unicode_escape", errors) + #endif + #if !defined(PyUnicode_Contains) || (PY_MAJOR_VERSION == 2 && PYPY_VERSION_NUM < 0x07030500) + #undef PyUnicode_Contains + #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) + #endif + #if !defined(PyByteArray_Check) + #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) + #endif + #if !defined(PyObject_Format) + #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) + #endif +#endif +#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) +#else + #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) +#endif +#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) + #define PyObject_ASCII(o) PyObject_Repr(o) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBaseString_Type PyUnicode_Type + #define PyStringObject PyUnicodeObject + #define PyString_Type PyUnicode_Type + #define PyString_Check PyUnicode_Check + #define PyString_CheckExact PyUnicode_CheckExact +#ifndef PyObject_Unicode + #define PyObject_Unicode PyObject_Str +#endif +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) + #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) +#else + #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) + #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) +#endif +#if CYTHON_COMPILING_IN_CPYTHON + #define __Pyx_PySequence_ListKeepNew(obj)\ + (likely(PyList_CheckExact(obj) && Py_REFCNT(obj) == 1) ? __Pyx_NewRef(obj) : PySequence_List(obj)) +#else + #define __Pyx_PySequence_ListKeepNew(obj) PySequence_List(obj) +#endif +#ifndef PySet_CheckExact + #define PySet_CheckExact(obj) __Pyx_IS_TYPE(obj, &PySet_Type) +#endif +#if PY_VERSION_HEX >= 0x030900A4 + #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) +#else + #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) +#endif +#if CYTHON_ASSUME_SAFE_MACROS + #define __Pyx_PySequence_ITEM(o, i) PySequence_ITEM(o, i) + #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq) + #define __Pyx_PyTuple_SET_ITEM(o, i, v) (PyTuple_SET_ITEM(o, i, v), (0)) + #define __Pyx_PyList_SET_ITEM(o, i, v) (PyList_SET_ITEM(o, i, v), (0)) + #define __Pyx_PyTuple_GET_SIZE(o) PyTuple_GET_SIZE(o) + #define __Pyx_PyList_GET_SIZE(o) PyList_GET_SIZE(o) + #define __Pyx_PySet_GET_SIZE(o) PySet_GET_SIZE(o) + #define __Pyx_PyBytes_GET_SIZE(o) PyBytes_GET_SIZE(o) + #define __Pyx_PyByteArray_GET_SIZE(o) PyByteArray_GET_SIZE(o) +#else + #define __Pyx_PySequence_ITEM(o, i) PySequence_GetItem(o, i) + #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq) + #define __Pyx_PyTuple_SET_ITEM(o, i, v) PyTuple_SetItem(o, i, v) + #define __Pyx_PyList_SET_ITEM(o, i, v) PyList_SetItem(o, i, v) + #define __Pyx_PyTuple_GET_SIZE(o) PyTuple_Size(o) + #define __Pyx_PyList_GET_SIZE(o) PyList_Size(o) + #define __Pyx_PySet_GET_SIZE(o) PySet_Size(o) + #define __Pyx_PyBytes_GET_SIZE(o) PyBytes_Size(o) + #define __Pyx_PyByteArray_GET_SIZE(o) PyByteArray_Size(o) +#endif +#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1 + #define __Pyx_PyImport_AddModuleRef(name) PyImport_AddModuleRef(name) +#else + static CYTHON_INLINE PyObject *__Pyx_PyImport_AddModuleRef(const char *name) { + PyObject *module = PyImport_AddModule(name); + Py_XINCREF(module); + return module; + } +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyIntObject PyLongObject + #define PyInt_Type PyLong_Type + #define PyInt_Check(op) PyLong_Check(op) + #define PyInt_CheckExact(op) PyLong_CheckExact(op) + #define __Pyx_Py3Int_Check(op) PyLong_Check(op) + #define __Pyx_Py3Int_CheckExact(op) PyLong_CheckExact(op) + #define PyInt_FromString PyLong_FromString + #define PyInt_FromUnicode PyLong_FromUnicode + #define PyInt_FromLong PyLong_FromLong + #define PyInt_FromSize_t PyLong_FromSize_t + #define PyInt_FromSsize_t PyLong_FromSsize_t + #define PyInt_AsLong PyLong_AsLong + #define PyInt_AS_LONG PyLong_AS_LONG + #define PyInt_AsSsize_t PyLong_AsSsize_t + #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask + #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask + #define PyNumber_Int PyNumber_Long +#else + #define __Pyx_Py3Int_Check(op) (PyLong_Check(op) || PyInt_Check(op)) + #define __Pyx_Py3Int_CheckExact(op) (PyLong_CheckExact(op) || PyInt_CheckExact(op)) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBoolObject PyLongObject +#endif +#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY + #ifndef PyUnicode_InternFromString + #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) + #endif +#endif +#if PY_VERSION_HEX < 0x030200A4 + typedef long Py_hash_t; + #define __Pyx_PyInt_FromHash_t PyInt_FromLong + #define __Pyx_PyInt_AsHash_t __Pyx_PyIndex_AsHash_t +#else + #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t + #define __Pyx_PyInt_AsHash_t __Pyx_PyIndex_AsSsize_t +#endif +#if CYTHON_USE_ASYNC_SLOTS + #if PY_VERSION_HEX >= 0x030500B1 + #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods + #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) + #else + #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) + #endif +#else + #define __Pyx_PyType_AsAsync(obj) NULL +#endif +#ifndef __Pyx_PyAsyncMethodsStruct + typedef struct { + unaryfunc am_await; + unaryfunc am_aiter; + unaryfunc am_anext; + } __Pyx_PyAsyncMethodsStruct; +#endif + +#if defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS) + #if !defined(_USE_MATH_DEFINES) + #define _USE_MATH_DEFINES + #endif +#endif +#include +#ifdef NAN +#define __PYX_NAN() ((float) NAN) +#else +static CYTHON_INLINE float __PYX_NAN() { + float value; + memset(&value, 0xFF, sizeof(value)); + return value; +} +#endif +#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) +#define __Pyx_truncl trunc +#else +#define __Pyx_truncl truncl +#endif + +#define __PYX_MARK_ERR_POS(f_index, lineno) \ + { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } +#define __PYX_ERR(f_index, lineno, Ln_error) \ + { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; } + +#ifdef CYTHON_EXTERN_C + #undef __PYX_EXTERN_C + #define __PYX_EXTERN_C CYTHON_EXTERN_C +#elif defined(__PYX_EXTERN_C) + #ifdef _MSC_VER + #pragma message ("Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.") + #else + #warning Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead. + #endif +#else + #ifdef __cplusplus + #define __PYX_EXTERN_C extern "C" + #else + #define __PYX_EXTERN_C extern + #endif +#endif + +#define __PYX_HAVE__cython_code__throttling_middleware +#define __PYX_HAVE_API__cython_code__throttling_middleware +/* Early includes */ +#ifdef _OPENMP +#include +#endif /* _OPENMP */ + +#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS) +#define CYTHON_WITHOUT_ASSERTIONS +#endif + +typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; + const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; + +#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) +#define __PYX_DEFAULT_STRING_ENCODING "" +#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString +#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#define __Pyx_uchar_cast(c) ((unsigned char)c) +#define __Pyx_long_cast(x) ((long)x) +#define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ + (sizeof(type) < sizeof(Py_ssize_t)) ||\ + (sizeof(type) > sizeof(Py_ssize_t) &&\ + likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX) &&\ + (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ + v == (type)PY_SSIZE_T_MIN))) ||\ + (sizeof(type) == sizeof(Py_ssize_t) &&\ + (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX))) ) +static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { + return (size_t) i < (size_t) limit; +} +#if defined (__cplusplus) && __cplusplus >= 201103L + #include + #define __Pyx_sst_abs(value) std::abs(value) +#elif SIZEOF_INT >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) abs(value) +#elif SIZEOF_LONG >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) labs(value) +#elif defined (_MSC_VER) + #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value)) +#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define __Pyx_sst_abs(value) llabs(value) +#elif defined (__GNUC__) + #define __Pyx_sst_abs(value) __builtin_llabs(value) +#else + #define __Pyx_sst_abs(value) ((value<0) ? -value : value) +#endif +static CYTHON_INLINE Py_ssize_t __Pyx_ssize_strlen(const char *s); +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*); +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); +static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char*); +#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) +#define __Pyx_PyBytes_FromString PyBytes_FromString +#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); +#if PY_MAJOR_VERSION < 3 + #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#else + #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize +#endif +#define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyObject_AsWritableString(s) ((char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableSString(s) ((signed char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) +#define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) +#define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) +#define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) +#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) +#define __Pyx_PyUnicode_FromOrdinal(o) PyUnicode_FromOrdinal((int)o) +#define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode +#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) +#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b); +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*); +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); +#define __Pyx_PySequence_Tuple(obj)\ + (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj)) +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*); +#if CYTHON_ASSUME_SAFE_MACROS +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) +#else +#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) +#endif +#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) +#else +#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) +#endif +#if CYTHON_USE_PYLONG_INTERNALS + #if PY_VERSION_HEX >= 0x030C00A7 + #ifndef _PyLong_SIGN_MASK + #define _PyLong_SIGN_MASK 3 + #endif + #ifndef _PyLong_NON_SIZE_BITS + #define _PyLong_NON_SIZE_BITS 3 + #endif + #define __Pyx_PyLong_Sign(x) (((PyLongObject*)x)->long_value.lv_tag & _PyLong_SIGN_MASK) + #define __Pyx_PyLong_IsNeg(x) ((__Pyx_PyLong_Sign(x) & 2) != 0) + #define __Pyx_PyLong_IsNonNeg(x) (!__Pyx_PyLong_IsNeg(x)) + #define __Pyx_PyLong_IsZero(x) (__Pyx_PyLong_Sign(x) & 1) + #define __Pyx_PyLong_IsPos(x) (__Pyx_PyLong_Sign(x) == 0) + #define __Pyx_PyLong_CompactValueUnsigned(x) (__Pyx_PyLong_Digits(x)[0]) + #define __Pyx_PyLong_DigitCount(x) ((Py_ssize_t) (((PyLongObject*)x)->long_value.lv_tag >> _PyLong_NON_SIZE_BITS)) + #define __Pyx_PyLong_SignedDigitCount(x)\ + ((1 - (Py_ssize_t) __Pyx_PyLong_Sign(x)) * __Pyx_PyLong_DigitCount(x)) + #if defined(PyUnstable_Long_IsCompact) && defined(PyUnstable_Long_CompactValue) + #define __Pyx_PyLong_IsCompact(x) PyUnstable_Long_IsCompact((PyLongObject*) x) + #define __Pyx_PyLong_CompactValue(x) PyUnstable_Long_CompactValue((PyLongObject*) x) + #else + #define __Pyx_PyLong_IsCompact(x) (((PyLongObject*)x)->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS)) + #define __Pyx_PyLong_CompactValue(x) ((1 - (Py_ssize_t) __Pyx_PyLong_Sign(x)) * (Py_ssize_t) __Pyx_PyLong_Digits(x)[0]) + #endif + typedef Py_ssize_t __Pyx_compact_pylong; + typedef size_t __Pyx_compact_upylong; + #else + #define __Pyx_PyLong_IsNeg(x) (Py_SIZE(x) < 0) + #define __Pyx_PyLong_IsNonNeg(x) (Py_SIZE(x) >= 0) + #define __Pyx_PyLong_IsZero(x) (Py_SIZE(x) == 0) + #define __Pyx_PyLong_IsPos(x) (Py_SIZE(x) > 0) + #define __Pyx_PyLong_CompactValueUnsigned(x) ((Py_SIZE(x) == 0) ? 0 : __Pyx_PyLong_Digits(x)[0]) + #define __Pyx_PyLong_DigitCount(x) __Pyx_sst_abs(Py_SIZE(x)) + #define __Pyx_PyLong_SignedDigitCount(x) Py_SIZE(x) + #define __Pyx_PyLong_IsCompact(x) (Py_SIZE(x) == 0 || Py_SIZE(x) == 1 || Py_SIZE(x) == -1) + #define __Pyx_PyLong_CompactValue(x)\ + ((Py_SIZE(x) == 0) ? (sdigit) 0 : ((Py_SIZE(x) < 0) ? -(sdigit)__Pyx_PyLong_Digits(x)[0] : (sdigit)__Pyx_PyLong_Digits(x)[0])) + typedef sdigit __Pyx_compact_pylong; + typedef digit __Pyx_compact_upylong; + #endif + #if PY_VERSION_HEX >= 0x030C00A5 + #define __Pyx_PyLong_Digits(x) (((PyLongObject*)x)->long_value.ob_digit) + #else + #define __Pyx_PyLong_Digits(x) (((PyLongObject*)x)->ob_digit) + #endif +#endif +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII +#include +static int __Pyx_sys_getdefaultencoding_not_ascii; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + PyObject* ascii_chars_u = NULL; + PyObject* ascii_chars_b = NULL; + const char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + if (strcmp(default_encoding_c, "ascii") == 0) { + __Pyx_sys_getdefaultencoding_not_ascii = 0; + } else { + char ascii_chars[128]; + int c; + for (c = 0; c < 128; c++) { + ascii_chars[c] = (char) c; + } + __Pyx_sys_getdefaultencoding_not_ascii = 1; + ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); + if (!ascii_chars_u) goto bad; + ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); + if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { + PyErr_Format( + PyExc_ValueError, + "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", + default_encoding_c); + goto bad; + } + Py_DECREF(ascii_chars_u); + Py_DECREF(ascii_chars_b); + } + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + Py_XDECREF(ascii_chars_u); + Py_XDECREF(ascii_chars_b); + return -1; +} +#endif +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) +#else +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +#include +static char* __PYX_DEFAULT_STRING_ENCODING; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1); + if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; + strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + return -1; +} +#endif +#endif + + +/* Test for GCC > 2.95 */ +#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) +#else /* !__GNUC__ or GCC < 2.95 */ + #define likely(x) (x) + #define unlikely(x) (x) +#endif /* __GNUC__ */ +static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; } + +#if !CYTHON_USE_MODULE_STATE +static PyObject *__pyx_m = NULL; +#endif +static int __pyx_lineno; +static int __pyx_clineno = 0; +static const char * __pyx_cfilenm = __FILE__; +static const char *__pyx_filename; + +/* #### Code section: filename_table ### */ + +static const char *__pyx_f[] = { + "cython_code/throttling_middleware.pyx", +}; +/* #### Code section: utility_code_proto_before_types ### */ +/* ForceInitThreads.proto */ +#ifndef __PYX_FORCE_INIT_THREADS + #define __PYX_FORCE_INIT_THREADS 0 +#endif + +/* #### Code section: numeric_typedefs ### */ +/* #### Code section: complex_type_declarations ### */ +/* #### Code section: type_declarations ### */ + +/*--- Type declarations ---*/ +struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__; + +/* "cython_code/throttling_middleware.pyx":31 + * self.last_throttled = 0 + * + * async def __call__(self, handler, event: types.Message, data): # <<<<<<<<<<<<<< + * """ + * Processes incoming messages and enforces throttling rules. + */ +struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__ { + PyObject_HEAD + PyObject *__pyx_v_data; + PyObject *__pyx_v_err; + PyObject *__pyx_v_event; + PyObject *__pyx_v_handler; + PyObject *__pyx_v_lang; + PyObject *__pyx_v_real_handler; + PyObject *__pyx_v_self; + PyObject *__pyx_v_skip_pass; + PyObject *__pyx_v_tx; + PyObject *__pyx_v_user_id; + PyObject *__pyx_t_0; + PyObject *__pyx_t_1; + PyObject *__pyx_t_2; + PyObject *__pyx_t_3; + PyObject *__pyx_t_4; + PyObject *__pyx_t_5; + PyObject *__pyx_t_6; + PyObject *__pyx_t_7; + PyObject *__pyx_t_8; +}; + +/* #### Code section: utility_code_proto ### */ + +/* --- Runtime support code (head) --- */ +/* Refnanny.proto */ +#ifndef CYTHON_REFNANNY + #define CYTHON_REFNANNY 0 +#endif +#if CYTHON_REFNANNY + typedef struct { + void (*INCREF)(void*, PyObject*, Py_ssize_t); + void (*DECREF)(void*, PyObject*, Py_ssize_t); + void (*GOTREF)(void*, PyObject*, Py_ssize_t); + void (*GIVEREF)(void*, PyObject*, Py_ssize_t); + void* (*SetupContext)(const char*, Py_ssize_t, const char*); + void (*FinishContext)(void**); + } __Pyx_RefNannyAPIStruct; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); + #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; +#ifdef WITH_THREAD + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + if (acquire_gil) {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__));\ + PyGILState_Release(__pyx_gilstate_save);\ + } else {\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__));\ + } + #define __Pyx_RefNannyFinishContextNogil() {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __Pyx_RefNannyFinishContext();\ + PyGILState_Release(__pyx_gilstate_save);\ + } +#else + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__)) + #define __Pyx_RefNannyFinishContextNogil() __Pyx_RefNannyFinishContext() +#endif + #define __Pyx_RefNannyFinishContextNogil() {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __Pyx_RefNannyFinishContext();\ + PyGILState_Release(__pyx_gilstate_save);\ + } + #define __Pyx_RefNannyFinishContext()\ + __Pyx_RefNanny->FinishContext(&__pyx_refnanny) + #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_XINCREF(r) do { if((r) == NULL); else {__Pyx_INCREF(r); }} while(0) + #define __Pyx_XDECREF(r) do { if((r) == NULL); else {__Pyx_DECREF(r); }} while(0) + #define __Pyx_XGOTREF(r) do { if((r) == NULL); else {__Pyx_GOTREF(r); }} while(0) + #define __Pyx_XGIVEREF(r) do { if((r) == NULL); else {__Pyx_GIVEREF(r);}} while(0) +#else + #define __Pyx_RefNannyDeclarations + #define __Pyx_RefNannySetupContext(name, acquire_gil) + #define __Pyx_RefNannyFinishContextNogil() + #define __Pyx_RefNannyFinishContext() + #define __Pyx_INCREF(r) Py_INCREF(r) + #define __Pyx_DECREF(r) Py_DECREF(r) + #define __Pyx_GOTREF(r) + #define __Pyx_GIVEREF(r) + #define __Pyx_XINCREF(r) Py_XINCREF(r) + #define __Pyx_XDECREF(r) Py_XDECREF(r) + #define __Pyx_XGOTREF(r) + #define __Pyx_XGIVEREF(r) +#endif +#define __Pyx_Py_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; Py_XDECREF(tmp);\ + } while (0) +#define __Pyx_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_XDECREF(tmp);\ + } while (0) +#define __Pyx_DECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_DECREF(tmp);\ + } while (0) +#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) +#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) + +/* TupleAndListFromArray.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n); +static CYTHON_INLINE PyObject* __Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n); +#endif + +/* IncludeStringH.proto */ +#include + +/* BytesEquals.proto */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); + +/* UnicodeEquals.proto */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); + +/* fastcall.proto */ +#if CYTHON_AVOID_BORROWED_REFS + #define __Pyx_Arg_VARARGS(args, i) PySequence_GetItem(args, i) +#elif CYTHON_ASSUME_SAFE_MACROS + #define __Pyx_Arg_VARARGS(args, i) PyTuple_GET_ITEM(args, i) +#else + #define __Pyx_Arg_VARARGS(args, i) PyTuple_GetItem(args, i) +#endif +#if CYTHON_AVOID_BORROWED_REFS + #define __Pyx_Arg_NewRef_VARARGS(arg) __Pyx_NewRef(arg) + #define __Pyx_Arg_XDECREF_VARARGS(arg) Py_XDECREF(arg) +#else + #define __Pyx_Arg_NewRef_VARARGS(arg) arg + #define __Pyx_Arg_XDECREF_VARARGS(arg) +#endif +#define __Pyx_NumKwargs_VARARGS(kwds) PyDict_Size(kwds) +#define __Pyx_KwValues_VARARGS(args, nargs) NULL +#define __Pyx_GetKwValue_VARARGS(kw, kwvalues, s) __Pyx_PyDict_GetItemStrWithError(kw, s) +#define __Pyx_KwargsAsDict_VARARGS(kw, kwvalues) PyDict_Copy(kw) +#if CYTHON_METH_FASTCALL + #define __Pyx_Arg_FASTCALL(args, i) args[i] + #define __Pyx_NumKwargs_FASTCALL(kwds) PyTuple_GET_SIZE(kwds) + #define __Pyx_KwValues_FASTCALL(args, nargs) ((args) + (nargs)) + static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s); +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000 + CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues); + #else + #define __Pyx_KwargsAsDict_FASTCALL(kw, kwvalues) _PyStack_AsDict(kwvalues, kw) + #endif + #define __Pyx_Arg_NewRef_FASTCALL(arg) arg /* no-op, __Pyx_Arg_FASTCALL is direct and this needs + to have the same reference counting */ + #define __Pyx_Arg_XDECREF_FASTCALL(arg) +#else + #define __Pyx_Arg_FASTCALL __Pyx_Arg_VARARGS + #define __Pyx_NumKwargs_FASTCALL __Pyx_NumKwargs_VARARGS + #define __Pyx_KwValues_FASTCALL __Pyx_KwValues_VARARGS + #define __Pyx_GetKwValue_FASTCALL __Pyx_GetKwValue_VARARGS + #define __Pyx_KwargsAsDict_FASTCALL __Pyx_KwargsAsDict_VARARGS + #define __Pyx_Arg_NewRef_FASTCALL(arg) __Pyx_Arg_NewRef_VARARGS(arg) + #define __Pyx_Arg_XDECREF_FASTCALL(arg) __Pyx_Arg_XDECREF_VARARGS(arg) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS +#define __Pyx_ArgsSlice_VARARGS(args, start, stop) __Pyx_PyTuple_FromArray(&__Pyx_Arg_VARARGS(args, start), stop - start) +#define __Pyx_ArgsSlice_FASTCALL(args, start, stop) __Pyx_PyTuple_FromArray(&__Pyx_Arg_FASTCALL(args, start), stop - start) +#else +#define __Pyx_ArgsSlice_VARARGS(args, start, stop) PyTuple_GetSlice(args, start, stop) +#define __Pyx_ArgsSlice_FASTCALL(args, start, stop) PyTuple_GetSlice(args, start, stop) +#endif + +/* RaiseDoubleKeywords.proto */ +static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); + +/* ParseKeywords.proto */ +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject *const *kwvalues, + PyObject **argnames[], + PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, + const char* function_name); + +/* RaiseArgTupleInvalid.proto */ +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); + +/* PyObjectSetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL) +static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value); +#else +#define __Pyx_PyObject_DelAttrStr(o,n) PyObject_DelAttr(o,n) +#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v) +#endif + +/* DictGetItem.proto */ +#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY +static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key); +#define __Pyx_PyObject_Dict_GetItem(obj, name)\ + (likely(PyDict_CheckExact(obj)) ?\ + __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name)) +#else +#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key) +#define __Pyx_PyObject_Dict_GetItem(obj, name) PyObject_GetItem(obj, name) +#endif + +/* PyObjectGetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) +#endif + +/* PyFunctionFastCall.proto */ +#if CYTHON_FAST_PYCALL +#if !CYTHON_VECTORCALL +#define __Pyx_PyFunction_FastCall(func, args, nargs)\ + __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL) +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs); +#endif +#define __Pyx_BUILD_ASSERT_EXPR(cond)\ + (sizeof(char [1 - 2*!(cond)]) - 1) +#ifndef Py_MEMBER_SIZE +#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) +#endif +#if !CYTHON_VECTORCALL +#if PY_VERSION_HEX >= 0x03080000 + #include "frameobject.h" +#if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API + #ifndef Py_BUILD_CORE + #define Py_BUILD_CORE 1 + #endif + #include "internal/pycore_frame.h" +#endif + #define __Pxy_PyFrame_Initialize_Offsets() + #define __Pyx_PyFrame_GetLocalsplus(frame) ((frame)->f_localsplus) +#else + static size_t __pyx_pyframe_localsplus_offset = 0; + #include "frameobject.h" + #define __Pxy_PyFrame_Initialize_Offsets()\ + ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ + (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) + #define __Pyx_PyFrame_GetLocalsplus(frame)\ + (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) +#endif +#endif +#endif + +/* PyObjectCall.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); +#else +#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) +#endif + +/* PyObjectCallMethO.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); +#endif + +/* PyObjectFastCall.proto */ +#define __Pyx_PyObject_FastCall(func, args, nargs) __Pyx_PyObject_FastCallDict(func, args, (size_t)(nargs), NULL) +static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject **args, size_t nargs, PyObject *kwargs); + +/* PyErrExceptionMatches.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err) +static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err); +#else +#define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(err) +#endif + +/* PyThreadStateGet.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; +#define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current; +#if PY_VERSION_HEX >= 0x030C00A6 +#define __Pyx_PyErr_Occurred() (__pyx_tstate->current_exception != NULL) +#define __Pyx_PyErr_CurrentExceptionType() (__pyx_tstate->current_exception ? (PyObject*) Py_TYPE(__pyx_tstate->current_exception) : (PyObject*) NULL) +#else +#define __Pyx_PyErr_Occurred() (__pyx_tstate->curexc_type != NULL) +#define __Pyx_PyErr_CurrentExceptionType() (__pyx_tstate->curexc_type) +#endif +#else +#define __Pyx_PyThreadState_declare +#define __Pyx_PyThreadState_assign +#define __Pyx_PyErr_Occurred() (PyErr_Occurred() != NULL) +#define __Pyx_PyErr_CurrentExceptionType() PyErr_Occurred() +#endif + +/* PyErrFetchRestore.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL) +#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A6 +#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL)) +#else +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#endif +#else +#define __Pyx_PyErr_Clear() PyErr_Clear() +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) +#endif + +/* PyObjectGetAttrStrNoError.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name); + +/* GetBuiltinName.proto */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name); + +/* PyDictVersioning.proto */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) +#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ + (version_var) = __PYX_GET_DICT_VERSION(dict);\ + (cache_var) = (value); +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ + (VAR) = __pyx_dict_cached_value;\ + } else {\ + (VAR) = __pyx_dict_cached_value = (LOOKUP);\ + __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ + }\ +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); +#else +#define __PYX_GET_DICT_VERSION(dict) (0) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); +#endif + +/* GetModuleGlobalName.proto */ +#if CYTHON_USE_DICT_VERSIONS +#define __Pyx_GetModuleGlobalName(var, name) do {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ + (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ + __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} while(0) +#define __Pyx_GetModuleGlobalNameUncached(var, name) do {\ + PY_UINT64_T __pyx_dict_version;\ + PyObject *__pyx_dict_cached_value;\ + (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} while(0) +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); +#else +#define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) +#define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); +#endif + +/* IncludeStructmemberH.proto */ +#include + +/* FixUpExtensionType.proto */ +#if CYTHON_USE_TYPE_SPECS +static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type); +#endif + +/* FetchSharedCythonModule.proto */ +static PyObject *__Pyx_FetchSharedCythonABIModule(void); + +/* FetchCommonType.proto */ +#if !CYTHON_USE_TYPE_SPECS +static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type); +#else +static PyTypeObject* __Pyx_FetchCommonTypeFromSpec(PyObject *module, PyType_Spec *spec, PyObject *bases); +#endif + +/* RaiseException.proto */ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); + +/* GetTopmostException.proto */ +#if CYTHON_USE_EXC_INFO_STACK && CYTHON_FAST_THREAD_STATE +static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate); +#endif + +/* SaveResetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#define __Pyx_ExceptionReset(type, value, tb) __Pyx__ExceptionReset(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +#else +#define __Pyx_ExceptionSave(type, value, tb) PyErr_GetExcInfo(type, value, tb) +#define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb) +#endif + +/* SwapException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* PyObjectCall2Args.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); + +/* PyObjectCallOneArg.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); + +/* PyObjectGetMethod.proto */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); + +/* PyObjectCallMethod1.proto */ +static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); + +/* PyObjectCallNoArg.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); + +/* CoroutineBase.proto */ +struct __pyx_CoroutineObject; +typedef PyObject *(*__pyx_coroutine_body_t)(struct __pyx_CoroutineObject *, PyThreadState *, PyObject *); +#if CYTHON_USE_EXC_INFO_STACK +#define __Pyx_ExcInfoStruct _PyErr_StackItem +#else +typedef struct { + PyObject *exc_type; + PyObject *exc_value; + PyObject *exc_traceback; +} __Pyx_ExcInfoStruct; +#endif +typedef struct __pyx_CoroutineObject { + PyObject_HEAD + __pyx_coroutine_body_t body; + PyObject *closure; + __Pyx_ExcInfoStruct gi_exc_state; + PyObject *gi_weakreflist; + PyObject *classobj; + PyObject *yieldfrom; + PyObject *gi_name; + PyObject *gi_qualname; + PyObject *gi_modulename; + PyObject *gi_code; + PyObject *gi_frame; + int resume_label; + char is_running; +} __pyx_CoroutineObject; +static __pyx_CoroutineObject *__Pyx__Coroutine_New( + PyTypeObject *type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, + PyObject *name, PyObject *qualname, PyObject *module_name); +static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit( + __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, + PyObject *name, PyObject *qualname, PyObject *module_name); +static CYTHON_INLINE void __Pyx_Coroutine_ExceptionClear(__Pyx_ExcInfoStruct *self); +static int __Pyx_Coroutine_clear(PyObject *self); +static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value); +static PyObject *__Pyx_Coroutine_Close(PyObject *self); +static PyObject *__Pyx_Coroutine_Throw(PyObject *gen, PyObject *args); +#if CYTHON_USE_EXC_INFO_STACK +#define __Pyx_Coroutine_SwapException(self) +#define __Pyx_Coroutine_ResetAndClearException(self) __Pyx_Coroutine_ExceptionClear(&(self)->gi_exc_state) +#else +#define __Pyx_Coroutine_SwapException(self) {\ + __Pyx_ExceptionSwap(&(self)->gi_exc_state.exc_type, &(self)->gi_exc_state.exc_value, &(self)->gi_exc_state.exc_traceback);\ + __Pyx_Coroutine_ResetFrameBackpointer(&(self)->gi_exc_state);\ + } +#define __Pyx_Coroutine_ResetAndClearException(self) {\ + __Pyx_ExceptionReset((self)->gi_exc_state.exc_type, (self)->gi_exc_state.exc_value, (self)->gi_exc_state.exc_traceback);\ + (self)->gi_exc_state.exc_type = (self)->gi_exc_state.exc_value = (self)->gi_exc_state.exc_traceback = NULL;\ + } +#endif +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyGen_FetchStopIterationValue(pvalue)\ + __Pyx_PyGen__FetchStopIterationValue(__pyx_tstate, pvalue) +#else +#define __Pyx_PyGen_FetchStopIterationValue(pvalue)\ + __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, pvalue) +#endif +static int __Pyx_PyGen__FetchStopIterationValue(PyThreadState *tstate, PyObject **pvalue); +static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__Pyx_ExcInfoStruct *exc_state); + +/* PyObject_GenericGetAttrNoDict.proto */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr +#endif + +/* PatchModuleWithCoroutine.proto */ +static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code); + +/* PatchGeneratorABC.proto */ +static int __Pyx_patch_abc(void); + +/* Coroutine.proto */ +#define __Pyx_Coroutine_USED +#define __Pyx_Coroutine_CheckExact(obj) __Pyx_IS_TYPE(obj, __pyx_CoroutineType) +#define __Pyx_Coroutine_Check(obj) __Pyx_Coroutine_CheckExact(obj) +#define __Pyx_CoroutineAwait_CheckExact(obj) __Pyx_IS_TYPE(obj, __pyx_CoroutineAwaitType) +#define __Pyx_Coroutine_New(body, code, closure, name, qualname, module_name)\ + __Pyx__Coroutine_New(__pyx_CoroutineType, body, code, closure, name, qualname, module_name) +static int __pyx_Coroutine_init(PyObject *module); +static PyObject *__Pyx__Coroutine_await(PyObject *coroutine); +typedef struct { + PyObject_HEAD + PyObject *coroutine; +} __pyx_CoroutineAwaitObject; +static PyObject *__Pyx_CoroutineAwait_Close(__pyx_CoroutineAwaitObject *self, PyObject *arg); +static PyObject *__Pyx_CoroutineAwait_Throw(__pyx_CoroutineAwaitObject *self, PyObject *args); + +/* GetAwaitIter.proto */ +static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAwaitableIter(PyObject *o); +static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *o); + +/* CoroutineYieldFrom.proto */ +static CYTHON_INLINE PyObject* __Pyx_Coroutine_Yield_From(__pyx_CoroutineObject *gen, PyObject *source); + +/* ReturnWithStopIteration.proto */ +#define __Pyx_ReturnWithStopIteration(value)\ + if (value == Py_None) PyErr_SetNone(PyExc_StopIteration); else __Pyx__ReturnWithStopIteration(value) +static void __Pyx__ReturnWithStopIteration(PyObject* value); + +/* PyIntBinop.proto */ +#if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check); +#else +#define __Pyx_PyInt_AddObjC(op1, op2, intval, inplace, zerodivision_check)\ + (inplace ? PyNumber_InPlaceAdd(op1, op2) : PyNumber_Add(op1, op2)) +#endif + +/* GetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_GetException(type, value, tb) __Pyx__GetException(__pyx_tstate, type, value, tb) +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* RaiseUnboundLocalError.proto */ +static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname); + +/* pep479.proto */ +static void __Pyx_Generator_Replace_StopIteration(int in_async_gen); + +/* PyObjectCallMethod0.proto */ +static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); + +/* ValidateBasesTuple.proto */ +#if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS +static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases); +#endif + +/* PyType_Ready.proto */ +CYTHON_UNUSED static int __Pyx_PyType_Ready(PyTypeObject *t); + +/* Import.proto */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); + +/* ImportDottedModule.proto */ +static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple); +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple); +#endif + +/* ImportFrom.proto */ +static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); + +/* Py3UpdateBases.proto */ +static PyObject* __Pyx_PEP560_update_bases(PyObject *bases); + +/* CalculateMetaclass.proto */ +static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases); + +/* PyMethodNew.proto */ +#if CYTHON_COMPILING_IN_LIMITED_API +static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) { + PyObject *typesModule=NULL, *methodType=NULL, *result=NULL; + CYTHON_UNUSED_VAR(typ); + if (!self) + return __Pyx_NewRef(func); + typesModule = PyImport_ImportModule("types"); + if (!typesModule) return NULL; + methodType = PyObject_GetAttrString(typesModule, "MethodType"); + Py_DECREF(typesModule); + if (!methodType) return NULL; + result = PyObject_CallFunctionObjArgs(methodType, func, self, NULL); + Py_DECREF(methodType); + return result; +} +#elif PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) { + CYTHON_UNUSED_VAR(typ); + if (!self) + return __Pyx_NewRef(func); + return PyMethod_New(func, self); +} +#else + #define __Pyx_PyMethod_New PyMethod_New +#endif + +/* PyVectorcallFastCallDict.proto */ +#if CYTHON_METH_FASTCALL +static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw); +#endif + +/* CythonFunctionShared.proto */ +#define __Pyx_CyFunction_USED +#define __Pyx_CYFUNCTION_STATICMETHOD 0x01 +#define __Pyx_CYFUNCTION_CLASSMETHOD 0x02 +#define __Pyx_CYFUNCTION_CCLASS 0x04 +#define __Pyx_CYFUNCTION_COROUTINE 0x08 +#define __Pyx_CyFunction_GetClosure(f)\ + (((__pyx_CyFunctionObject *) (f))->func_closure) +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_CyFunction_GetClassObj(f)\ + (((__pyx_CyFunctionObject *) (f))->func_classobj) +#else + #define __Pyx_CyFunction_GetClassObj(f)\ + ((PyObject*) ((PyCMethodObject *) (f))->mm_class) +#endif +#define __Pyx_CyFunction_SetClassObj(f, classobj)\ + __Pyx__CyFunction_SetClassObj((__pyx_CyFunctionObject *) (f), (classobj)) +#define __Pyx_CyFunction_Defaults(type, f)\ + ((type *)(((__pyx_CyFunctionObject *) (f))->defaults)) +#define __Pyx_CyFunction_SetDefaultsGetter(f, g)\ + ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g) +typedef struct { +#if CYTHON_COMPILING_IN_LIMITED_API + PyObject_HEAD + PyObject *func; +#elif PY_VERSION_HEX < 0x030900B1 + PyCFunctionObject func; +#else + PyCMethodObject func; +#endif +#if CYTHON_BACKPORT_VECTORCALL + __pyx_vectorcallfunc func_vectorcall; +#endif +#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API + PyObject *func_weakreflist; +#endif + PyObject *func_dict; + PyObject *func_name; + PyObject *func_qualname; + PyObject *func_doc; + PyObject *func_globals; + PyObject *func_code; + PyObject *func_closure; +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + PyObject *func_classobj; +#endif + void *defaults; + int defaults_pyobjects; + size_t defaults_size; + int flags; + PyObject *defaults_tuple; + PyObject *defaults_kwdict; + PyObject *(*defaults_getter)(PyObject *); + PyObject *func_annotations; + PyObject *func_is_coroutine; +} __pyx_CyFunctionObject; +#undef __Pyx_CyOrPyCFunction_Check +#define __Pyx_CyFunction_Check(obj) __Pyx_TypeCheck(obj, __pyx_CyFunctionType) +#define __Pyx_CyOrPyCFunction_Check(obj) __Pyx_TypeCheck2(obj, __pyx_CyFunctionType, &PyCFunction_Type) +#define __Pyx_CyFunction_CheckExact(obj) __Pyx_IS_TYPE(obj, __pyx_CyFunctionType) +static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc); +#undef __Pyx_IsSameCFunction +#define __Pyx_IsSameCFunction(func, cfunc) __Pyx__IsSameCyOrCFunction(func, cfunc) +static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject* op, PyMethodDef *ml, + int flags, PyObject* qualname, + PyObject *closure, + PyObject *module, PyObject *globals, + PyObject* code); +static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj); +static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m, + size_t size, + int pyobjects); +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m, + PyObject *tuple); +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m, + PyObject *dict); +static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m, + PyObject *dict); +static int __pyx_CyFunction_init(PyObject *module); +#if CYTHON_METH_FASTCALL +static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +#if CYTHON_BACKPORT_VECTORCALL +#define __Pyx_CyFunction_func_vectorcall(f) (((__pyx_CyFunctionObject*)f)->func_vectorcall) +#else +#define __Pyx_CyFunction_func_vectorcall(f) (((PyCFunctionObject*)f)->vectorcall) +#endif +#endif + +/* CythonFunction.proto */ +static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, + int flags, PyObject* qualname, + PyObject *closure, + PyObject *module, PyObject *globals, + PyObject* code); + +/* SetNameInClass.proto */ +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && PY_VERSION_HEX < 0x030d0000 +#define __Pyx_SetNameInClass(ns, name, value)\ + (likely(PyDict_CheckExact(ns)) ? _PyDict_SetItem_KnownHash(ns, name, value, ((PyASCIIObject *) name)->hash) : PyObject_SetItem(ns, name, value)) +#elif CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_SetNameInClass(ns, name, value)\ + (likely(PyDict_CheckExact(ns)) ? PyDict_SetItem(ns, name, value) : PyObject_SetItem(ns, name, value)) +#else +#define __Pyx_SetNameInClass(ns, name, value) PyObject_SetItem(ns, name, value) +#endif + +/* PyObjectLookupSpecial.proto */ +#if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS +#define __Pyx_PyObject_LookupSpecialNoError(obj, attr_name) __Pyx__PyObject_LookupSpecial(obj, attr_name, 0) +#define __Pyx_PyObject_LookupSpecial(obj, attr_name) __Pyx__PyObject_LookupSpecial(obj, attr_name, 1) +static CYTHON_INLINE PyObject* __Pyx__PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name, int with_error); +#else +#define __Pyx_PyObject_LookupSpecialNoError(o,n) __Pyx_PyObject_GetAttrStrNoError(o,n) +#define __Pyx_PyObject_LookupSpecial(o,n) __Pyx_PyObject_GetAttrStr(o,n) +#endif + +/* Py3ClassCreate.proto */ +static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname, + PyObject *mkw, PyObject *modname, PyObject *doc); +static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict, + PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass); + +/* CLineInTraceback.proto */ +#ifdef CYTHON_CLINE_IN_TRACEBACK +#define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0) +#else +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line); +#endif + +/* CodeObjectCache.proto */ +#if !CYTHON_COMPILING_IN_LIMITED_API +typedef struct { + PyCodeObject* code_object; + int code_line; +} __Pyx_CodeObjectCacheEntry; +struct __Pyx_CodeObjectCache { + int count; + int max_count; + __Pyx_CodeObjectCacheEntry* entries; +}; +static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); +static PyCodeObject *__pyx_find_code_object(int code_line); +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); +#endif + +/* AddTraceback.proto */ +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename); + +/* FormatTypeName.proto */ +#if CYTHON_COMPILING_IN_LIMITED_API +typedef PyObject *__Pyx_TypeName; +#define __Pyx_FMT_TYPENAME "%U" +static __Pyx_TypeName __Pyx_PyType_GetName(PyTypeObject* tp); +#define __Pyx_DECREF_TypeName(obj) Py_XDECREF(obj) +#else +typedef const char *__Pyx_TypeName; +#define __Pyx_FMT_TYPENAME "%.200s" +#define __Pyx_PyType_GetName(tp) ((tp)->tp_name) +#define __Pyx_DECREF_TypeName(obj) +#endif + +/* GCCDiagnostics.proto */ +#if !defined(__INTEL_COMPILER) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +#define __Pyx_HAS_GCC_DIAGNOSTIC +#endif + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + +/* CIntFromPy.proto */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); + +/* CIntFromPy.proto */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); + +/* FastTypeChecks.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type) +#define __Pyx_TypeCheck2(obj, type1, type2) __Pyx_IsAnySubtype2(Py_TYPE(obj), (PyTypeObject *)type1, (PyTypeObject *)type2) +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b); +static CYTHON_INLINE int __Pyx_IsAnySubtype2(PyTypeObject *cls, PyTypeObject *a, PyTypeObject *b); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2); +#else +#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) +#define __Pyx_TypeCheck2(obj, type1, type2) (PyObject_TypeCheck(obj, (PyTypeObject *)type1) || PyObject_TypeCheck(obj, (PyTypeObject *)type2)) +#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type) +#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2)) +#endif +#define __Pyx_PyErr_ExceptionMatches2(err1, err2) __Pyx_PyErr_GivenExceptionMatches2(__Pyx_PyErr_CurrentExceptionType(), err1, err2) +#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) + +/* CheckBinaryVersion.proto */ +static unsigned long __Pyx_get_runtime_version(void); +static int __Pyx_check_binary_version(unsigned long ct_version, unsigned long rt_version, int allow_newer); + +/* InitStrings.proto */ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); + +/* #### Code section: module_declarations ### */ + +/* Module declarations from "cython_code.throttling_middleware" */ +/* #### Code section: typeinfo ### */ +/* #### Code section: before_global_var ### */ +#define __Pyx_MODULE_NAME "cython_code.throttling_middleware" +extern int __pyx_module_is_main_cython_code__throttling_middleware; +int __pyx_module_is_main_cython_code__throttling_middleware = 0; + +/* Implementation of "cython_code.throttling_middleware" */ +/* #### Code section: global_var ### */ +/* #### Code section: string_decls ### */ +static const char __pyx_k__2[] = "*"; +static const char __pyx_k__3[] = "."; +static const char __pyx_k__7[] = "?"; +static const char __pyx_k_en[] = "en"; +static const char __pyx_k_gc[] = "gc"; +static const char __pyx_k_id[] = "id"; +static const char __pyx_k_tx[] = "tx"; +static const char __pyx_k_bot[] = "bot"; +static const char __pyx_k_doc[] = "__doc__"; +static const char __pyx_k_err[] = "err"; +static const char __pyx_k_get[] = "get"; +static const char __pyx_k_None[] = "None"; +static const char __pyx_k_args[] = "args"; +static const char __pyx_k_call[] = "__call__"; +static const char __pyx_k_data[] = "data"; +static const char __pyx_k_dest[] = "dest"; +static const char __pyx_k_dict[] = "__dict__"; +static const char __pyx_k_init[] = "__init__"; +static const char __pyx_k_lang[] = "lang"; +static const char __pyx_k_main[] = "__main__"; +static const char __pyx_k_name[] = "__name__"; +static const char __pyx_k_self[] = "self"; +static const char __pyx_k_send[] = "send"; +static const char __pyx_k_spec[] = "__spec__"; +static const char __pyx_k_test[] = "__test__"; +static const char __pyx_k_text[] = "text"; +static const char __pyx_k_time[] = "time"; +static const char __pyx_k_await[] = "__await__"; +static const char __pyx_k_close[] = "close"; +static const char __pyx_k_error[] = "error"; +static const char __pyx_k_event[] = "event"; +static const char __pyx_k_flags[] = "flags"; +static const char __pyx_k_float[] = "float"; +static const char __pyx_k_super[] = "super"; +static const char __pyx_k_throw[] = "throw"; +static const char __pyx_k_types[] = "types"; +static const char __pyx_k_answer[] = "answer"; +static const char __pyx_k_enable[] = "enable"; +static const char __pyx_k_import[] = "__import__"; +static const char __pyx_k_loader[] = "loader"; +static const char __pyx_k_module[] = "__module__"; +static const char __pyx_k_return[] = "return"; +static const char __pyx_k_aiogram[] = "aiogram"; +static const char __pyx_k_chat_id[] = "chat_id"; +static const char __pyx_k_disable[] = "disable"; +static const char __pyx_k_handler[] = "handler"; +static const char __pyx_k_logging[] = "logging"; +static const char __pyx_k_message[] = "message"; +static const char __pyx_k_prepare[] = "__prepare__"; +static const char __pyx_k_user_id[] = "user_id"; +static const char __pyx_k_limiters[] = "limiters"; +static const char __pyx_k_qualname[] = "__qualname__"; +static const char __pyx_k_set_name[] = "__set_name__"; +static const char __pyx_k_close_btn[] = "close_btn"; +static const char __pyx_k_from_user[] = "from_user"; +static const char __pyx_k_isenabled[] = "isenabled"; +static const char __pyx_k_metaclass[] = "__metaclass__"; +static const char __pyx_k_skip_pass[] = "skip_pass"; +static const char __pyx_k_translator[] = "translator"; +static const char __pyx_k_mro_entries[] = "__mro_entries__"; +static const char __pyx_k_default_rate[] = "default_rate"; +static const char __pyx_k_initializing[] = "_initializing"; +static const char __pyx_k_is_coroutine[] = "_is_coroutine"; +static const char __pyx_k_real_handler[] = "real_handler"; +static const char __pyx_k_reply_markup[] = "reply_markup"; +static const char __pyx_k_send_message[] = "send_message"; +static const char __pyx_k_HandlerObject[] = "HandlerObject"; +static const char __pyx_k_init_subclass[] = "__init_subclass__"; +static const char __pyx_k_language_code[] = "language_code"; +static const char __pyx_k_types_Message[] = "types.Message"; +static const char __pyx_k_BaseMiddleware[] = "BaseMiddleware"; +static const char __pyx_k_callback_query[] = "callback_query"; +static const char __pyx_k_last_throttled[] = "last_throttled"; +static const char __pyx_k_count_throttled[] = "count_throttled"; +static const char __pyx_k_asyncio_coroutines[] = "asyncio.coroutines"; +static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; +static const char __pyx_k_function_translator[] = "function.translator"; +static const char __pyx_k_ThrottlingMiddleware[] = "ThrottlingMiddleware"; +static const char __pyx_k_keyboards_inline_close_btn[] = "keyboards.inline.close_btn"; +static const char __pyx_k_ThrottlingMiddleware___call[] = "ThrottlingMiddleware.__call__"; +static const char __pyx_k_ThrottlingMiddleware___init[] = "ThrottlingMiddleware.__init__"; +static const char __pyx_k_Many_requests_have_been_made[] = "Many requests have been made"; +static const char __pyx_k_Middleware_class_to_manage_thro[] = "\n Middleware class to manage throttling of requests to prevent overloading.\n\n This middleware limits the rate of incoming requests from users. If a user exceeds the allowed\n request rate, they will receive a message indicating that they are making too many requests.\n "; +static const char __pyx_k_aiogram_dispatcher_event_handler[] = "aiogram.dispatcher.event.handler"; +static const char __pyx_k_cython_code_throttling_middlewar[] = "cython_code.throttling_middleware"; +static const char __pyx_k_cython_code_throttling_middlewar_2[] = "cython_code/throttling_middleware.pyx"; +/* #### Code section: decls ### */ +static PyObject *__pyx_pf_11cython_code_21throttling_middleware_20ThrottlingMiddleware___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, double __pyx_v_default_rate); /* proto */ +static PyObject *__pyx_pf_11cython_code_21throttling_middleware_20ThrottlingMiddleware_2__call__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_handler, PyObject *__pyx_v_event, PyObject *__pyx_v_data); /* proto */ +static PyObject *__pyx_tp_new_11cython_code_21throttling_middleware___pyx_scope_struct____call__(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +/* #### Code section: late_includes ### */ +/* #### Code section: module_state ### */ +typedef struct { + PyObject *__pyx_d; + PyObject *__pyx_b; + PyObject *__pyx_cython_runtime; + PyObject *__pyx_empty_tuple; + PyObject *__pyx_empty_bytes; + PyObject *__pyx_empty_unicode; + #ifdef __Pyx_CyFunction_USED + PyTypeObject *__pyx_CyFunctionType; + #endif + #ifdef __Pyx_FusedFunction_USED + PyTypeObject *__pyx_FusedFunctionType; + #endif + #ifdef __Pyx_Generator_USED + PyTypeObject *__pyx_GeneratorType; + #endif + #ifdef __Pyx_IterableCoroutine_USED + PyTypeObject *__pyx_IterableCoroutineType; + #endif + #ifdef __Pyx_Coroutine_USED + PyTypeObject *__pyx_CoroutineAwaitType; + #endif + #ifdef __Pyx_Coroutine_USED + PyTypeObject *__pyx_CoroutineType; + #endif + #if CYTHON_USE_MODULE_STATE + PyObject *__pyx_type_11cython_code_21throttling_middleware___pyx_scope_struct____call__; + #endif + PyTypeObject *__pyx_ptype_11cython_code_21throttling_middleware___pyx_scope_struct____call__; + PyObject *__pyx_n_s_BaseMiddleware; + PyObject *__pyx_n_s_HandlerObject; + PyObject *__pyx_kp_u_Many_requests_have_been_made; + PyObject *__pyx_kp_s_Middleware_class_to_manage_thro; + PyObject *__pyx_n_s_None; + PyObject *__pyx_n_s_ThrottlingMiddleware; + PyObject *__pyx_n_s_ThrottlingMiddleware___call; + PyObject *__pyx_n_s_ThrottlingMiddleware___init; + PyObject *__pyx_n_s__2; + PyObject *__pyx_kp_u__3; + PyObject *__pyx_n_s__7; + PyObject *__pyx_n_s_aiogram; + PyObject *__pyx_n_s_aiogram_dispatcher_event_handler; + PyObject *__pyx_n_s_answer; + PyObject *__pyx_n_s_args; + PyObject *__pyx_n_s_asyncio_coroutines; + PyObject *__pyx_n_s_await; + PyObject *__pyx_n_s_bot; + PyObject *__pyx_n_s_call; + PyObject *__pyx_n_s_callback_query; + PyObject *__pyx_n_s_chat_id; + PyObject *__pyx_n_s_cline_in_traceback; + PyObject *__pyx_n_s_close; + PyObject *__pyx_n_s_close_btn; + PyObject *__pyx_n_s_count_throttled; + PyObject *__pyx_n_s_cython_code_throttling_middlewar; + PyObject *__pyx_kp_s_cython_code_throttling_middlewar_2; + PyObject *__pyx_n_s_data; + PyObject *__pyx_n_s_default_rate; + PyObject *__pyx_n_s_dest; + PyObject *__pyx_n_s_dict; + PyObject *__pyx_kp_u_disable; + PyObject *__pyx_n_s_doc; + PyObject *__pyx_n_u_en; + PyObject *__pyx_kp_u_enable; + PyObject *__pyx_n_s_err; + PyObject *__pyx_n_s_error; + PyObject *__pyx_n_s_event; + PyObject *__pyx_n_s_flags; + PyObject *__pyx_n_s_float; + PyObject *__pyx_n_s_from_user; + PyObject *__pyx_n_s_function_translator; + PyObject *__pyx_kp_u_gc; + PyObject *__pyx_n_s_get; + PyObject *__pyx_n_s_handler; + PyObject *__pyx_n_u_handler; + PyObject *__pyx_n_s_id; + PyObject *__pyx_n_s_import; + PyObject *__pyx_n_s_init; + PyObject *__pyx_n_s_init_subclass; + PyObject *__pyx_n_s_initializing; + PyObject *__pyx_n_s_is_coroutine; + PyObject *__pyx_kp_u_isenabled; + PyObject *__pyx_n_s_keyboards_inline_close_btn; + PyObject *__pyx_n_s_lang; + PyObject *__pyx_n_s_language_code; + PyObject *__pyx_n_s_last_throttled; + PyObject *__pyx_n_s_limiters; + PyObject *__pyx_n_s_loader; + PyObject *__pyx_n_s_logging; + PyObject *__pyx_n_s_main; + PyObject *__pyx_n_s_message; + PyObject *__pyx_n_s_metaclass; + PyObject *__pyx_n_s_module; + PyObject *__pyx_n_s_mro_entries; + PyObject *__pyx_n_s_name; + PyObject *__pyx_n_s_prepare; + PyObject *__pyx_n_s_qualname; + PyObject *__pyx_n_s_real_handler; + PyObject *__pyx_n_s_reply_markup; + PyObject *__pyx_n_s_return; + PyObject *__pyx_n_s_self; + PyObject *__pyx_n_s_send; + PyObject *__pyx_n_s_send_message; + PyObject *__pyx_n_s_set_name; + PyObject *__pyx_n_s_skip_pass; + PyObject *__pyx_n_u_skip_pass; + PyObject *__pyx_n_s_spec; + PyObject *__pyx_n_s_super; + PyObject *__pyx_n_s_test; + PyObject *__pyx_n_s_text; + PyObject *__pyx_n_s_throw; + PyObject *__pyx_n_s_time; + PyObject *__pyx_n_s_translator; + PyObject *__pyx_n_s_tx; + PyObject *__pyx_n_s_types; + PyObject *__pyx_kp_s_types_Message; + PyObject *__pyx_n_s_user_id; + PyObject *__pyx_float_0_5; + PyObject *__pyx_int_0; + PyObject *__pyx_int_1; + PyObject *__pyx_int_2; + PyObject *__pyx_int_3; + PyObject *__pyx_codeobj_; + PyObject *__pyx_tuple__4; + PyObject *__pyx_tuple__6; + PyObject *__pyx_codeobj__5; +} __pyx_mstate; + +#if CYTHON_USE_MODULE_STATE +#ifdef __cplusplus +namespace { + extern struct PyModuleDef __pyx_moduledef; +} /* anonymous namespace */ +#else +static struct PyModuleDef __pyx_moduledef; +#endif + +#define __pyx_mstate(o) ((__pyx_mstate *)__Pyx_PyModule_GetState(o)) + +#define __pyx_mstate_global (__pyx_mstate(PyState_FindModule(&__pyx_moduledef))) + +#define __pyx_m (PyState_FindModule(&__pyx_moduledef)) +#else +static __pyx_mstate __pyx_mstate_global_static = +#ifdef __cplusplus + {}; +#else + {0}; +#endif +static __pyx_mstate *__pyx_mstate_global = &__pyx_mstate_global_static; +#endif +/* #### Code section: module_state_clear ### */ +#if CYTHON_USE_MODULE_STATE +static int __pyx_m_clear(PyObject *m) { + __pyx_mstate *clear_module_state = __pyx_mstate(m); + if (!clear_module_state) return 0; + Py_CLEAR(clear_module_state->__pyx_d); + Py_CLEAR(clear_module_state->__pyx_b); + Py_CLEAR(clear_module_state->__pyx_cython_runtime); + Py_CLEAR(clear_module_state->__pyx_empty_tuple); + Py_CLEAR(clear_module_state->__pyx_empty_bytes); + Py_CLEAR(clear_module_state->__pyx_empty_unicode); + #ifdef __Pyx_CyFunction_USED + Py_CLEAR(clear_module_state->__pyx_CyFunctionType); + #endif + #ifdef __Pyx_FusedFunction_USED + Py_CLEAR(clear_module_state->__pyx_FusedFunctionType); + #endif + Py_CLEAR(clear_module_state->__pyx_ptype_11cython_code_21throttling_middleware___pyx_scope_struct____call__); + Py_CLEAR(clear_module_state->__pyx_type_11cython_code_21throttling_middleware___pyx_scope_struct____call__); + Py_CLEAR(clear_module_state->__pyx_n_s_BaseMiddleware); + Py_CLEAR(clear_module_state->__pyx_n_s_HandlerObject); + Py_CLEAR(clear_module_state->__pyx_kp_u_Many_requests_have_been_made); + Py_CLEAR(clear_module_state->__pyx_kp_s_Middleware_class_to_manage_thro); + Py_CLEAR(clear_module_state->__pyx_n_s_None); + Py_CLEAR(clear_module_state->__pyx_n_s_ThrottlingMiddleware); + Py_CLEAR(clear_module_state->__pyx_n_s_ThrottlingMiddleware___call); + Py_CLEAR(clear_module_state->__pyx_n_s_ThrottlingMiddleware___init); + Py_CLEAR(clear_module_state->__pyx_n_s__2); + Py_CLEAR(clear_module_state->__pyx_kp_u__3); + Py_CLEAR(clear_module_state->__pyx_n_s__7); + Py_CLEAR(clear_module_state->__pyx_n_s_aiogram); + Py_CLEAR(clear_module_state->__pyx_n_s_aiogram_dispatcher_event_handler); + Py_CLEAR(clear_module_state->__pyx_n_s_answer); + Py_CLEAR(clear_module_state->__pyx_n_s_args); + Py_CLEAR(clear_module_state->__pyx_n_s_asyncio_coroutines); + Py_CLEAR(clear_module_state->__pyx_n_s_await); + Py_CLEAR(clear_module_state->__pyx_n_s_bot); + Py_CLEAR(clear_module_state->__pyx_n_s_call); + Py_CLEAR(clear_module_state->__pyx_n_s_callback_query); + Py_CLEAR(clear_module_state->__pyx_n_s_chat_id); + Py_CLEAR(clear_module_state->__pyx_n_s_cline_in_traceback); + Py_CLEAR(clear_module_state->__pyx_n_s_close); + Py_CLEAR(clear_module_state->__pyx_n_s_close_btn); + Py_CLEAR(clear_module_state->__pyx_n_s_count_throttled); + Py_CLEAR(clear_module_state->__pyx_n_s_cython_code_throttling_middlewar); + Py_CLEAR(clear_module_state->__pyx_kp_s_cython_code_throttling_middlewar_2); + Py_CLEAR(clear_module_state->__pyx_n_s_data); + Py_CLEAR(clear_module_state->__pyx_n_s_default_rate); + Py_CLEAR(clear_module_state->__pyx_n_s_dest); + Py_CLEAR(clear_module_state->__pyx_n_s_dict); + Py_CLEAR(clear_module_state->__pyx_kp_u_disable); + Py_CLEAR(clear_module_state->__pyx_n_s_doc); + Py_CLEAR(clear_module_state->__pyx_n_u_en); + Py_CLEAR(clear_module_state->__pyx_kp_u_enable); + Py_CLEAR(clear_module_state->__pyx_n_s_err); + Py_CLEAR(clear_module_state->__pyx_n_s_error); + Py_CLEAR(clear_module_state->__pyx_n_s_event); + Py_CLEAR(clear_module_state->__pyx_n_s_flags); + Py_CLEAR(clear_module_state->__pyx_n_s_float); + Py_CLEAR(clear_module_state->__pyx_n_s_from_user); + Py_CLEAR(clear_module_state->__pyx_n_s_function_translator); + Py_CLEAR(clear_module_state->__pyx_kp_u_gc); + Py_CLEAR(clear_module_state->__pyx_n_s_get); + Py_CLEAR(clear_module_state->__pyx_n_s_handler); + Py_CLEAR(clear_module_state->__pyx_n_u_handler); + Py_CLEAR(clear_module_state->__pyx_n_s_id); + Py_CLEAR(clear_module_state->__pyx_n_s_import); + Py_CLEAR(clear_module_state->__pyx_n_s_init); + Py_CLEAR(clear_module_state->__pyx_n_s_init_subclass); + Py_CLEAR(clear_module_state->__pyx_n_s_initializing); + Py_CLEAR(clear_module_state->__pyx_n_s_is_coroutine); + Py_CLEAR(clear_module_state->__pyx_kp_u_isenabled); + Py_CLEAR(clear_module_state->__pyx_n_s_keyboards_inline_close_btn); + Py_CLEAR(clear_module_state->__pyx_n_s_lang); + Py_CLEAR(clear_module_state->__pyx_n_s_language_code); + Py_CLEAR(clear_module_state->__pyx_n_s_last_throttled); + Py_CLEAR(clear_module_state->__pyx_n_s_limiters); + Py_CLEAR(clear_module_state->__pyx_n_s_loader); + Py_CLEAR(clear_module_state->__pyx_n_s_logging); + Py_CLEAR(clear_module_state->__pyx_n_s_main); + Py_CLEAR(clear_module_state->__pyx_n_s_message); + Py_CLEAR(clear_module_state->__pyx_n_s_metaclass); + Py_CLEAR(clear_module_state->__pyx_n_s_module); + Py_CLEAR(clear_module_state->__pyx_n_s_mro_entries); + Py_CLEAR(clear_module_state->__pyx_n_s_name); + Py_CLEAR(clear_module_state->__pyx_n_s_prepare); + Py_CLEAR(clear_module_state->__pyx_n_s_qualname); + Py_CLEAR(clear_module_state->__pyx_n_s_real_handler); + Py_CLEAR(clear_module_state->__pyx_n_s_reply_markup); + Py_CLEAR(clear_module_state->__pyx_n_s_return); + Py_CLEAR(clear_module_state->__pyx_n_s_self); + Py_CLEAR(clear_module_state->__pyx_n_s_send); + Py_CLEAR(clear_module_state->__pyx_n_s_send_message); + Py_CLEAR(clear_module_state->__pyx_n_s_set_name); + Py_CLEAR(clear_module_state->__pyx_n_s_skip_pass); + Py_CLEAR(clear_module_state->__pyx_n_u_skip_pass); + Py_CLEAR(clear_module_state->__pyx_n_s_spec); + Py_CLEAR(clear_module_state->__pyx_n_s_super); + Py_CLEAR(clear_module_state->__pyx_n_s_test); + Py_CLEAR(clear_module_state->__pyx_n_s_text); + Py_CLEAR(clear_module_state->__pyx_n_s_throw); + Py_CLEAR(clear_module_state->__pyx_n_s_time); + Py_CLEAR(clear_module_state->__pyx_n_s_translator); + Py_CLEAR(clear_module_state->__pyx_n_s_tx); + Py_CLEAR(clear_module_state->__pyx_n_s_types); + Py_CLEAR(clear_module_state->__pyx_kp_s_types_Message); + Py_CLEAR(clear_module_state->__pyx_n_s_user_id); + Py_CLEAR(clear_module_state->__pyx_float_0_5); + Py_CLEAR(clear_module_state->__pyx_int_0); + Py_CLEAR(clear_module_state->__pyx_int_1); + Py_CLEAR(clear_module_state->__pyx_int_2); + Py_CLEAR(clear_module_state->__pyx_int_3); + Py_CLEAR(clear_module_state->__pyx_codeobj_); + Py_CLEAR(clear_module_state->__pyx_tuple__4); + Py_CLEAR(clear_module_state->__pyx_tuple__6); + Py_CLEAR(clear_module_state->__pyx_codeobj__5); + return 0; +} +#endif +/* #### Code section: module_state_traverse ### */ +#if CYTHON_USE_MODULE_STATE +static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { + __pyx_mstate *traverse_module_state = __pyx_mstate(m); + if (!traverse_module_state) return 0; + Py_VISIT(traverse_module_state->__pyx_d); + Py_VISIT(traverse_module_state->__pyx_b); + Py_VISIT(traverse_module_state->__pyx_cython_runtime); + Py_VISIT(traverse_module_state->__pyx_empty_tuple); + Py_VISIT(traverse_module_state->__pyx_empty_bytes); + Py_VISIT(traverse_module_state->__pyx_empty_unicode); + #ifdef __Pyx_CyFunction_USED + Py_VISIT(traverse_module_state->__pyx_CyFunctionType); + #endif + #ifdef __Pyx_FusedFunction_USED + Py_VISIT(traverse_module_state->__pyx_FusedFunctionType); + #endif + Py_VISIT(traverse_module_state->__pyx_ptype_11cython_code_21throttling_middleware___pyx_scope_struct____call__); + Py_VISIT(traverse_module_state->__pyx_type_11cython_code_21throttling_middleware___pyx_scope_struct____call__); + Py_VISIT(traverse_module_state->__pyx_n_s_BaseMiddleware); + Py_VISIT(traverse_module_state->__pyx_n_s_HandlerObject); + Py_VISIT(traverse_module_state->__pyx_kp_u_Many_requests_have_been_made); + Py_VISIT(traverse_module_state->__pyx_kp_s_Middleware_class_to_manage_thro); + Py_VISIT(traverse_module_state->__pyx_n_s_None); + Py_VISIT(traverse_module_state->__pyx_n_s_ThrottlingMiddleware); + Py_VISIT(traverse_module_state->__pyx_n_s_ThrottlingMiddleware___call); + Py_VISIT(traverse_module_state->__pyx_n_s_ThrottlingMiddleware___init); + Py_VISIT(traverse_module_state->__pyx_n_s__2); + Py_VISIT(traverse_module_state->__pyx_kp_u__3); + Py_VISIT(traverse_module_state->__pyx_n_s__7); + Py_VISIT(traverse_module_state->__pyx_n_s_aiogram); + Py_VISIT(traverse_module_state->__pyx_n_s_aiogram_dispatcher_event_handler); + Py_VISIT(traverse_module_state->__pyx_n_s_answer); + Py_VISIT(traverse_module_state->__pyx_n_s_args); + Py_VISIT(traverse_module_state->__pyx_n_s_asyncio_coroutines); + Py_VISIT(traverse_module_state->__pyx_n_s_await); + Py_VISIT(traverse_module_state->__pyx_n_s_bot); + Py_VISIT(traverse_module_state->__pyx_n_s_call); + Py_VISIT(traverse_module_state->__pyx_n_s_callback_query); + Py_VISIT(traverse_module_state->__pyx_n_s_chat_id); + Py_VISIT(traverse_module_state->__pyx_n_s_cline_in_traceback); + Py_VISIT(traverse_module_state->__pyx_n_s_close); + Py_VISIT(traverse_module_state->__pyx_n_s_close_btn); + Py_VISIT(traverse_module_state->__pyx_n_s_count_throttled); + Py_VISIT(traverse_module_state->__pyx_n_s_cython_code_throttling_middlewar); + Py_VISIT(traverse_module_state->__pyx_kp_s_cython_code_throttling_middlewar_2); + Py_VISIT(traverse_module_state->__pyx_n_s_data); + Py_VISIT(traverse_module_state->__pyx_n_s_default_rate); + Py_VISIT(traverse_module_state->__pyx_n_s_dest); + Py_VISIT(traverse_module_state->__pyx_n_s_dict); + Py_VISIT(traverse_module_state->__pyx_kp_u_disable); + Py_VISIT(traverse_module_state->__pyx_n_s_doc); + Py_VISIT(traverse_module_state->__pyx_n_u_en); + Py_VISIT(traverse_module_state->__pyx_kp_u_enable); + Py_VISIT(traverse_module_state->__pyx_n_s_err); + Py_VISIT(traverse_module_state->__pyx_n_s_error); + Py_VISIT(traverse_module_state->__pyx_n_s_event); + Py_VISIT(traverse_module_state->__pyx_n_s_flags); + Py_VISIT(traverse_module_state->__pyx_n_s_float); + Py_VISIT(traverse_module_state->__pyx_n_s_from_user); + Py_VISIT(traverse_module_state->__pyx_n_s_function_translator); + Py_VISIT(traverse_module_state->__pyx_kp_u_gc); + Py_VISIT(traverse_module_state->__pyx_n_s_get); + Py_VISIT(traverse_module_state->__pyx_n_s_handler); + Py_VISIT(traverse_module_state->__pyx_n_u_handler); + Py_VISIT(traverse_module_state->__pyx_n_s_id); + Py_VISIT(traverse_module_state->__pyx_n_s_import); + Py_VISIT(traverse_module_state->__pyx_n_s_init); + Py_VISIT(traverse_module_state->__pyx_n_s_init_subclass); + Py_VISIT(traverse_module_state->__pyx_n_s_initializing); + Py_VISIT(traverse_module_state->__pyx_n_s_is_coroutine); + Py_VISIT(traverse_module_state->__pyx_kp_u_isenabled); + Py_VISIT(traverse_module_state->__pyx_n_s_keyboards_inline_close_btn); + Py_VISIT(traverse_module_state->__pyx_n_s_lang); + Py_VISIT(traverse_module_state->__pyx_n_s_language_code); + Py_VISIT(traverse_module_state->__pyx_n_s_last_throttled); + Py_VISIT(traverse_module_state->__pyx_n_s_limiters); + Py_VISIT(traverse_module_state->__pyx_n_s_loader); + Py_VISIT(traverse_module_state->__pyx_n_s_logging); + Py_VISIT(traverse_module_state->__pyx_n_s_main); + Py_VISIT(traverse_module_state->__pyx_n_s_message); + Py_VISIT(traverse_module_state->__pyx_n_s_metaclass); + Py_VISIT(traverse_module_state->__pyx_n_s_module); + Py_VISIT(traverse_module_state->__pyx_n_s_mro_entries); + Py_VISIT(traverse_module_state->__pyx_n_s_name); + Py_VISIT(traverse_module_state->__pyx_n_s_prepare); + Py_VISIT(traverse_module_state->__pyx_n_s_qualname); + Py_VISIT(traverse_module_state->__pyx_n_s_real_handler); + Py_VISIT(traverse_module_state->__pyx_n_s_reply_markup); + Py_VISIT(traverse_module_state->__pyx_n_s_return); + Py_VISIT(traverse_module_state->__pyx_n_s_self); + Py_VISIT(traverse_module_state->__pyx_n_s_send); + Py_VISIT(traverse_module_state->__pyx_n_s_send_message); + Py_VISIT(traverse_module_state->__pyx_n_s_set_name); + Py_VISIT(traverse_module_state->__pyx_n_s_skip_pass); + Py_VISIT(traverse_module_state->__pyx_n_u_skip_pass); + Py_VISIT(traverse_module_state->__pyx_n_s_spec); + Py_VISIT(traverse_module_state->__pyx_n_s_super); + Py_VISIT(traverse_module_state->__pyx_n_s_test); + Py_VISIT(traverse_module_state->__pyx_n_s_text); + Py_VISIT(traverse_module_state->__pyx_n_s_throw); + Py_VISIT(traverse_module_state->__pyx_n_s_time); + Py_VISIT(traverse_module_state->__pyx_n_s_translator); + Py_VISIT(traverse_module_state->__pyx_n_s_tx); + Py_VISIT(traverse_module_state->__pyx_n_s_types); + Py_VISIT(traverse_module_state->__pyx_kp_s_types_Message); + Py_VISIT(traverse_module_state->__pyx_n_s_user_id); + Py_VISIT(traverse_module_state->__pyx_float_0_5); + Py_VISIT(traverse_module_state->__pyx_int_0); + Py_VISIT(traverse_module_state->__pyx_int_1); + Py_VISIT(traverse_module_state->__pyx_int_2); + Py_VISIT(traverse_module_state->__pyx_int_3); + Py_VISIT(traverse_module_state->__pyx_codeobj_); + Py_VISIT(traverse_module_state->__pyx_tuple__4); + Py_VISIT(traverse_module_state->__pyx_tuple__6); + Py_VISIT(traverse_module_state->__pyx_codeobj__5); + return 0; +} +#endif +/* #### Code section: module_state_defines ### */ +#define __pyx_d __pyx_mstate_global->__pyx_d +#define __pyx_b __pyx_mstate_global->__pyx_b +#define __pyx_cython_runtime __pyx_mstate_global->__pyx_cython_runtime +#define __pyx_empty_tuple __pyx_mstate_global->__pyx_empty_tuple +#define __pyx_empty_bytes __pyx_mstate_global->__pyx_empty_bytes +#define __pyx_empty_unicode __pyx_mstate_global->__pyx_empty_unicode +#ifdef __Pyx_CyFunction_USED +#define __pyx_CyFunctionType __pyx_mstate_global->__pyx_CyFunctionType +#endif +#ifdef __Pyx_FusedFunction_USED +#define __pyx_FusedFunctionType __pyx_mstate_global->__pyx_FusedFunctionType +#endif +#ifdef __Pyx_Generator_USED +#define __pyx_GeneratorType __pyx_mstate_global->__pyx_GeneratorType +#endif +#ifdef __Pyx_IterableCoroutine_USED +#define __pyx_IterableCoroutineType __pyx_mstate_global->__pyx_IterableCoroutineType +#endif +#ifdef __Pyx_Coroutine_USED +#define __pyx_CoroutineAwaitType __pyx_mstate_global->__pyx_CoroutineAwaitType +#endif +#ifdef __Pyx_Coroutine_USED +#define __pyx_CoroutineType __pyx_mstate_global->__pyx_CoroutineType +#endif +#if CYTHON_USE_MODULE_STATE +#define __pyx_type_11cython_code_21throttling_middleware___pyx_scope_struct____call__ __pyx_mstate_global->__pyx_type_11cython_code_21throttling_middleware___pyx_scope_struct____call__ +#endif +#define __pyx_ptype_11cython_code_21throttling_middleware___pyx_scope_struct____call__ __pyx_mstate_global->__pyx_ptype_11cython_code_21throttling_middleware___pyx_scope_struct____call__ +#define __pyx_n_s_BaseMiddleware __pyx_mstate_global->__pyx_n_s_BaseMiddleware +#define __pyx_n_s_HandlerObject __pyx_mstate_global->__pyx_n_s_HandlerObject +#define __pyx_kp_u_Many_requests_have_been_made __pyx_mstate_global->__pyx_kp_u_Many_requests_have_been_made +#define __pyx_kp_s_Middleware_class_to_manage_thro __pyx_mstate_global->__pyx_kp_s_Middleware_class_to_manage_thro +#define __pyx_n_s_None __pyx_mstate_global->__pyx_n_s_None +#define __pyx_n_s_ThrottlingMiddleware __pyx_mstate_global->__pyx_n_s_ThrottlingMiddleware +#define __pyx_n_s_ThrottlingMiddleware___call __pyx_mstate_global->__pyx_n_s_ThrottlingMiddleware___call +#define __pyx_n_s_ThrottlingMiddleware___init __pyx_mstate_global->__pyx_n_s_ThrottlingMiddleware___init +#define __pyx_n_s__2 __pyx_mstate_global->__pyx_n_s__2 +#define __pyx_kp_u__3 __pyx_mstate_global->__pyx_kp_u__3 +#define __pyx_n_s__7 __pyx_mstate_global->__pyx_n_s__7 +#define __pyx_n_s_aiogram __pyx_mstate_global->__pyx_n_s_aiogram +#define __pyx_n_s_aiogram_dispatcher_event_handler __pyx_mstate_global->__pyx_n_s_aiogram_dispatcher_event_handler +#define __pyx_n_s_answer __pyx_mstate_global->__pyx_n_s_answer +#define __pyx_n_s_args __pyx_mstate_global->__pyx_n_s_args +#define __pyx_n_s_asyncio_coroutines __pyx_mstate_global->__pyx_n_s_asyncio_coroutines +#define __pyx_n_s_await __pyx_mstate_global->__pyx_n_s_await +#define __pyx_n_s_bot __pyx_mstate_global->__pyx_n_s_bot +#define __pyx_n_s_call __pyx_mstate_global->__pyx_n_s_call +#define __pyx_n_s_callback_query __pyx_mstate_global->__pyx_n_s_callback_query +#define __pyx_n_s_chat_id __pyx_mstate_global->__pyx_n_s_chat_id +#define __pyx_n_s_cline_in_traceback __pyx_mstate_global->__pyx_n_s_cline_in_traceback +#define __pyx_n_s_close __pyx_mstate_global->__pyx_n_s_close +#define __pyx_n_s_close_btn __pyx_mstate_global->__pyx_n_s_close_btn +#define __pyx_n_s_count_throttled __pyx_mstate_global->__pyx_n_s_count_throttled +#define __pyx_n_s_cython_code_throttling_middlewar __pyx_mstate_global->__pyx_n_s_cython_code_throttling_middlewar +#define __pyx_kp_s_cython_code_throttling_middlewar_2 __pyx_mstate_global->__pyx_kp_s_cython_code_throttling_middlewar_2 +#define __pyx_n_s_data __pyx_mstate_global->__pyx_n_s_data +#define __pyx_n_s_default_rate __pyx_mstate_global->__pyx_n_s_default_rate +#define __pyx_n_s_dest __pyx_mstate_global->__pyx_n_s_dest +#define __pyx_n_s_dict __pyx_mstate_global->__pyx_n_s_dict +#define __pyx_kp_u_disable __pyx_mstate_global->__pyx_kp_u_disable +#define __pyx_n_s_doc __pyx_mstate_global->__pyx_n_s_doc +#define __pyx_n_u_en __pyx_mstate_global->__pyx_n_u_en +#define __pyx_kp_u_enable __pyx_mstate_global->__pyx_kp_u_enable +#define __pyx_n_s_err __pyx_mstate_global->__pyx_n_s_err +#define __pyx_n_s_error __pyx_mstate_global->__pyx_n_s_error +#define __pyx_n_s_event __pyx_mstate_global->__pyx_n_s_event +#define __pyx_n_s_flags __pyx_mstate_global->__pyx_n_s_flags +#define __pyx_n_s_float __pyx_mstate_global->__pyx_n_s_float +#define __pyx_n_s_from_user __pyx_mstate_global->__pyx_n_s_from_user +#define __pyx_n_s_function_translator __pyx_mstate_global->__pyx_n_s_function_translator +#define __pyx_kp_u_gc __pyx_mstate_global->__pyx_kp_u_gc +#define __pyx_n_s_get __pyx_mstate_global->__pyx_n_s_get +#define __pyx_n_s_handler __pyx_mstate_global->__pyx_n_s_handler +#define __pyx_n_u_handler __pyx_mstate_global->__pyx_n_u_handler +#define __pyx_n_s_id __pyx_mstate_global->__pyx_n_s_id +#define __pyx_n_s_import __pyx_mstate_global->__pyx_n_s_import +#define __pyx_n_s_init __pyx_mstate_global->__pyx_n_s_init +#define __pyx_n_s_init_subclass __pyx_mstate_global->__pyx_n_s_init_subclass +#define __pyx_n_s_initializing __pyx_mstate_global->__pyx_n_s_initializing +#define __pyx_n_s_is_coroutine __pyx_mstate_global->__pyx_n_s_is_coroutine +#define __pyx_kp_u_isenabled __pyx_mstate_global->__pyx_kp_u_isenabled +#define __pyx_n_s_keyboards_inline_close_btn __pyx_mstate_global->__pyx_n_s_keyboards_inline_close_btn +#define __pyx_n_s_lang __pyx_mstate_global->__pyx_n_s_lang +#define __pyx_n_s_language_code __pyx_mstate_global->__pyx_n_s_language_code +#define __pyx_n_s_last_throttled __pyx_mstate_global->__pyx_n_s_last_throttled +#define __pyx_n_s_limiters __pyx_mstate_global->__pyx_n_s_limiters +#define __pyx_n_s_loader __pyx_mstate_global->__pyx_n_s_loader +#define __pyx_n_s_logging __pyx_mstate_global->__pyx_n_s_logging +#define __pyx_n_s_main __pyx_mstate_global->__pyx_n_s_main +#define __pyx_n_s_message __pyx_mstate_global->__pyx_n_s_message +#define __pyx_n_s_metaclass __pyx_mstate_global->__pyx_n_s_metaclass +#define __pyx_n_s_module __pyx_mstate_global->__pyx_n_s_module +#define __pyx_n_s_mro_entries __pyx_mstate_global->__pyx_n_s_mro_entries +#define __pyx_n_s_name __pyx_mstate_global->__pyx_n_s_name +#define __pyx_n_s_prepare __pyx_mstate_global->__pyx_n_s_prepare +#define __pyx_n_s_qualname __pyx_mstate_global->__pyx_n_s_qualname +#define __pyx_n_s_real_handler __pyx_mstate_global->__pyx_n_s_real_handler +#define __pyx_n_s_reply_markup __pyx_mstate_global->__pyx_n_s_reply_markup +#define __pyx_n_s_return __pyx_mstate_global->__pyx_n_s_return +#define __pyx_n_s_self __pyx_mstate_global->__pyx_n_s_self +#define __pyx_n_s_send __pyx_mstate_global->__pyx_n_s_send +#define __pyx_n_s_send_message __pyx_mstate_global->__pyx_n_s_send_message +#define __pyx_n_s_set_name __pyx_mstate_global->__pyx_n_s_set_name +#define __pyx_n_s_skip_pass __pyx_mstate_global->__pyx_n_s_skip_pass +#define __pyx_n_u_skip_pass __pyx_mstate_global->__pyx_n_u_skip_pass +#define __pyx_n_s_spec __pyx_mstate_global->__pyx_n_s_spec +#define __pyx_n_s_super __pyx_mstate_global->__pyx_n_s_super +#define __pyx_n_s_test __pyx_mstate_global->__pyx_n_s_test +#define __pyx_n_s_text __pyx_mstate_global->__pyx_n_s_text +#define __pyx_n_s_throw __pyx_mstate_global->__pyx_n_s_throw +#define __pyx_n_s_time __pyx_mstate_global->__pyx_n_s_time +#define __pyx_n_s_translator __pyx_mstate_global->__pyx_n_s_translator +#define __pyx_n_s_tx __pyx_mstate_global->__pyx_n_s_tx +#define __pyx_n_s_types __pyx_mstate_global->__pyx_n_s_types +#define __pyx_kp_s_types_Message __pyx_mstate_global->__pyx_kp_s_types_Message +#define __pyx_n_s_user_id __pyx_mstate_global->__pyx_n_s_user_id +#define __pyx_float_0_5 __pyx_mstate_global->__pyx_float_0_5 +#define __pyx_int_0 __pyx_mstate_global->__pyx_int_0 +#define __pyx_int_1 __pyx_mstate_global->__pyx_int_1 +#define __pyx_int_2 __pyx_mstate_global->__pyx_int_2 +#define __pyx_int_3 __pyx_mstate_global->__pyx_int_3 +#define __pyx_codeobj_ __pyx_mstate_global->__pyx_codeobj_ +#define __pyx_tuple__4 __pyx_mstate_global->__pyx_tuple__4 +#define __pyx_tuple__6 __pyx_mstate_global->__pyx_tuple__6 +#define __pyx_codeobj__5 __pyx_mstate_global->__pyx_codeobj__5 +/* #### Code section: module_code ### */ + +/* "cython_code/throttling_middleware.pyx":17 + * """ + * + * def __init__(self, default_rate: float = 0.5) -> None: # <<<<<<<<<<<<<< + * """ + * Initializes the ThrottlingMiddleware instance. + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_21throttling_middleware_20ThrottlingMiddleware_1__init__(PyObject *__pyx_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +PyDoc_STRVAR(__pyx_doc_11cython_code_21throttling_middleware_20ThrottlingMiddleware___init__, "\n Initializes the ThrottlingMiddleware instance.\n\n Parameters:\n - default_rate (float): The initial rate limit in seconds (default is 0.5 seconds).\n\n This constructor sets up the initial rate limit and other throttling parameters.\n "); +static PyMethodDef __pyx_mdef_11cython_code_21throttling_middleware_20ThrottlingMiddleware_1__init__ = {"__init__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_21throttling_middleware_20ThrottlingMiddleware_1__init__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_11cython_code_21throttling_middleware_20ThrottlingMiddleware___init__}; +static PyObject *__pyx_pw_11cython_code_21throttling_middleware_20ThrottlingMiddleware_1__init__(PyObject *__pyx_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + PyObject *__pyx_v_self = 0; + double __pyx_v_default_rate; + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[2] = {0,0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_default_rate,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_self)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 17, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (kw_args > 0) { + PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_default_rate); + if (value) { values[1] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 17, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 17, __pyx_L3_error) + } + } else { + switch (__pyx_nargs) { + case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_self = values[0]; + if (values[1]) { + __pyx_v_default_rate = __pyx_PyFloat_AsDouble(values[1]); if (unlikely((__pyx_v_default_rate == (double)-1) && PyErr_Occurred())) __PYX_ERR(0, 17, __pyx_L3_error) + } else { + __pyx_v_default_rate = ((double)((double)0.5)); + } + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 0, 1, 2, __pyx_nargs); __PYX_ERR(0, 17, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.throttling_middleware.ThrottlingMiddleware.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_11cython_code_21throttling_middleware_20ThrottlingMiddleware___init__(__pyx_self, __pyx_v_self, __pyx_v_default_rate); + + /* function exit code */ + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_21throttling_middleware_20ThrottlingMiddleware___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, double __pyx_v_default_rate) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__init__", 1); + + /* "cython_code/throttling_middleware.pyx":26 + * This constructor sets up the initial rate limit and other throttling parameters. + * """ + * self.limiters = {} # <<<<<<<<<<<<<< + * self.default_rate = default_rate + * self.count_throttled = 1 + */ + __pyx_t_1 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_limiters, __pyx_t_1) < 0) __PYX_ERR(0, 26, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "cython_code/throttling_middleware.pyx":27 + * """ + * self.limiters = {} + * self.default_rate = default_rate # <<<<<<<<<<<<<< + * self.count_throttled = 1 + * self.last_throttled = 0 + */ + __pyx_t_1 = PyFloat_FromDouble(__pyx_v_default_rate); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 27, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_default_rate, __pyx_t_1) < 0) __PYX_ERR(0, 27, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "cython_code/throttling_middleware.pyx":28 + * self.limiters = {} + * self.default_rate = default_rate + * self.count_throttled = 1 # <<<<<<<<<<<<<< + * self.last_throttled = 0 + * + */ + if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_count_throttled, __pyx_int_1) < 0) __PYX_ERR(0, 28, __pyx_L1_error) + + /* "cython_code/throttling_middleware.pyx":29 + * self.default_rate = default_rate + * self.count_throttled = 1 + * self.last_throttled = 0 # <<<<<<<<<<<<<< + * + * async def __call__(self, handler, event: types.Message, data): + */ + if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_last_throttled, __pyx_int_0) < 0) __PYX_ERR(0, 29, __pyx_L1_error) + + /* "cython_code/throttling_middleware.pyx":17 + * """ + * + * def __init__(self, default_rate: float = 0.5) -> None: # <<<<<<<<<<<<<< + * """ + * Initializes the ThrottlingMiddleware instance. + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("cython_code.throttling_middleware.ThrottlingMiddleware.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_11cython_code_21throttling_middleware_20ThrottlingMiddleware_4generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ + +/* "cython_code/throttling_middleware.pyx":31 + * self.last_throttled = 0 + * + * async def __call__(self, handler, event: types.Message, data): # <<<<<<<<<<<<<< + * """ + * Processes incoming messages and enforces throttling rules. + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_21throttling_middleware_20ThrottlingMiddleware_3__call__(PyObject *__pyx_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +PyDoc_STRVAR(__pyx_doc_11cython_code_21throttling_middleware_20ThrottlingMiddleware_2__call__, "\n Processes incoming messages and enforces throttling rules.\n\n Parameters:\n - handler (HandlerObject): The handler to call if throttling rules are not violated.\n - event (types.Message): The incoming message or callback query.\n - data (dict): Additional data associated with the event.\n\n This method checks if the incoming request exceeds the allowed rate limit. If the rate limit\n is exceeded, the user will receive a message informing them of the throttling. If not, the\n handler is called to process the request.\n\n Returns:\n - None: The method does not return a value. It either processes the handler or sends a throttling message.\n "); +static PyMethodDef __pyx_mdef_11cython_code_21throttling_middleware_20ThrottlingMiddleware_3__call__ = {"__call__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_21throttling_middleware_20ThrottlingMiddleware_3__call__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_11cython_code_21throttling_middleware_20ThrottlingMiddleware_2__call__}; +static PyObject *__pyx_pw_11cython_code_21throttling_middleware_20ThrottlingMiddleware_3__call__(PyObject *__pyx_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + PyObject *__pyx_v_self = 0; + PyObject *__pyx_v_handler = 0; + PyObject *__pyx_v_event = 0; + PyObject *__pyx_v_data = 0; + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[4] = {0,0,0,0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__call__ (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_handler,&__pyx_n_s_event,&__pyx_n_s_data,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 4: values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3); + CYTHON_FALLTHROUGH; + case 3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_self)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 31, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_handler)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[1]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 31, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("__call__", 1, 4, 4, 1); __PYX_ERR(0, 31, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (likely((values[2] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_event)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[2]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 31, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("__call__", 1, 4, 4, 2); __PYX_ERR(0, 31, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 3: + if (likely((values[3] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_data)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[3]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 31, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("__call__", 1, 4, 4, 3); __PYX_ERR(0, 31, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__call__") < 0)) __PYX_ERR(0, 31, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 4)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); + values[3] = __Pyx_Arg_FASTCALL(__pyx_args, 3); + } + __pyx_v_self = values[0]; + __pyx_v_handler = values[1]; + __pyx_v_event = values[2]; + __pyx_v_data = values[3]; + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__call__", 1, 4, 4, __pyx_nargs); __PYX_ERR(0, 31, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.throttling_middleware.ThrottlingMiddleware.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_11cython_code_21throttling_middleware_20ThrottlingMiddleware_2__call__(__pyx_self, __pyx_v_self, __pyx_v_handler, __pyx_v_event, __pyx_v_data); + + /* function exit code */ + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_21throttling_middleware_20ThrottlingMiddleware_2__call__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_handler, PyObject *__pyx_v_event, PyObject *__pyx_v_data) { + struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__ *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__call__", 0); + __pyx_cur_scope = (struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__ *)__pyx_tp_new_11cython_code_21throttling_middleware___pyx_scope_struct____call__(__pyx_ptype_11cython_code_21throttling_middleware___pyx_scope_struct____call__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__ *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(0, 31, __pyx_L1_error) + } else { + __Pyx_GOTREF((PyObject *)__pyx_cur_scope); + } + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self); + __pyx_cur_scope->__pyx_v_handler = __pyx_v_handler; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_handler); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_handler); + __pyx_cur_scope->__pyx_v_event = __pyx_v_event; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_event); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_event); + __pyx_cur_scope->__pyx_v_data = __pyx_v_data; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_data); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_data); + { + __pyx_CoroutineObject *gen = __Pyx_Coroutine_New((__pyx_coroutine_body_t) __pyx_gb_11cython_code_21throttling_middleware_20ThrottlingMiddleware_4generator, __pyx_codeobj_, (PyObject *) __pyx_cur_scope, __pyx_n_s_call, __pyx_n_s_ThrottlingMiddleware___call, __pyx_n_s_cython_code_throttling_middlewar); if (unlikely(!gen)) __PYX_ERR(0, 31, __pyx_L1_error) + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("cython_code.throttling_middleware.ThrottlingMiddleware.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_DECREF((PyObject *)__pyx_cur_scope); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_11cython_code_21throttling_middleware_20ThrottlingMiddleware_4generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__ *__pyx_cur_scope = ((struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + int __pyx_t_2; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + unsigned int __pyx_t_5; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + PyObject *__pyx_t_8 = NULL; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + PyObject *__pyx_t_12 = NULL; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + PyObject *__pyx_t_16 = NULL; + int __pyx_t_17; + int __pyx_t_18; + char const *__pyx_t_19; + PyObject *__pyx_t_20 = NULL; + PyObject *__pyx_t_21 = NULL; + PyObject *__pyx_t_22 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__call__", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L8_resume_from_await; + case 2: goto __pyx_L22_resume_from_await; + case 3: goto __pyx_L25_resume_from_await; + case 4: goto __pyx_L37_resume_from_await; + default: /* CPython raises the right error here */ + __Pyx_RefNannyFinishContext(); + return NULL; + } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 31, __pyx_L1_error) + + /* "cython_code/throttling_middleware.pyx":47 + * - None: The method does not return a value. It either processes the handler or sends a throttling message. + * """ + * real_handler: HandlerObject = data["handler"] # <<<<<<<<<<<<<< + * skip_pass = True + * + */ + __pyx_t_1 = __Pyx_PyObject_Dict_GetItem(__pyx_cur_scope->__pyx_v_data, __pyx_n_u_handler); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 47, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_real_handler = __pyx_t_1; + __pyx_t_1 = 0; + + /* "cython_code/throttling_middleware.pyx":48 + * """ + * real_handler: HandlerObject = data["handler"] + * skip_pass = True # <<<<<<<<<<<<<< + * + * if event.message: + */ + __Pyx_INCREF(Py_True); + __Pyx_GIVEREF(Py_True); + __pyx_cur_scope->__pyx_v_skip_pass = Py_True; + + /* "cython_code/throttling_middleware.pyx":50 + * skip_pass = True + * + * if event.message: # <<<<<<<<<<<<<< + * user_id = event.message.from_user.id + * lang = event.message.from_user.language_code + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_event, __pyx_n_s_message); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 50, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "cython_code/throttling_middleware.pyx":51 + * + * if event.message: + * user_id = event.message.from_user.id # <<<<<<<<<<<<<< + * lang = event.message.from_user.language_code + * elif event.callback_query: + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_event, __pyx_n_s_message); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 51, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_from_user); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 51, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 51, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_user_id = __pyx_t_1; + __pyx_t_1 = 0; + + /* "cython_code/throttling_middleware.pyx":52 + * if event.message: + * user_id = event.message.from_user.id + * lang = event.message.from_user.language_code # <<<<<<<<<<<<<< + * elif event.callback_query: + * user_id = event.callback_query.from_user.id + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_event, __pyx_n_s_message); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 52, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_from_user); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 52, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_language_code); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 52, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_lang = __pyx_t_1; + __pyx_t_1 = 0; + + /* "cython_code/throttling_middleware.pyx":50 + * skip_pass = True + * + * if event.message: # <<<<<<<<<<<<<< + * user_id = event.message.from_user.id + * lang = event.message.from_user.language_code + */ + goto __pyx_L4; + } + + /* "cython_code/throttling_middleware.pyx":53 + * user_id = event.message.from_user.id + * lang = event.message.from_user.language_code + * elif event.callback_query: # <<<<<<<<<<<<<< + * user_id = event.callback_query.from_user.id + * lang = event.callback_query.from_user.language_code + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_event, __pyx_n_s_callback_query); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 53, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_1); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 53, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "cython_code/throttling_middleware.pyx":54 + * lang = event.message.from_user.language_code + * elif event.callback_query: + * user_id = event.callback_query.from_user.id # <<<<<<<<<<<<<< + * lang = event.callback_query.from_user.language_code + * else: + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_event, __pyx_n_s_callback_query); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_from_user); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 54, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_id); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 54, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_user_id = __pyx_t_1; + __pyx_t_1 = 0; + + /* "cython_code/throttling_middleware.pyx":55 + * elif event.callback_query: + * user_id = event.callback_query.from_user.id + * lang = event.callback_query.from_user.language_code # <<<<<<<<<<<<<< + * else: + * lang = 'en' + */ + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_event, __pyx_n_s_callback_query); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 55, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_from_user); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 55, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_language_code); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 55, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_lang = __pyx_t_1; + __pyx_t_1 = 0; + + /* "cython_code/throttling_middleware.pyx":53 + * user_id = event.message.from_user.id + * lang = event.message.from_user.language_code + * elif event.callback_query: # <<<<<<<<<<<<<< + * user_id = event.callback_query.from_user.id + * lang = event.callback_query.from_user.language_code + */ + goto __pyx_L4; + } + + /* "cython_code/throttling_middleware.pyx":57 + * lang = event.callback_query.from_user.language_code + * else: + * lang = 'en' # <<<<<<<<<<<<<< + * + * if real_handler.flags.get("skip_pass") is not None: + */ + /*else*/ { + __Pyx_INCREF(__pyx_n_u_en); + __Pyx_GIVEREF(__pyx_n_u_en); + __pyx_cur_scope->__pyx_v_lang = __pyx_n_u_en; + } + __pyx_L4:; + + /* "cython_code/throttling_middleware.pyx":59 + * lang = 'en' + * + * if real_handler.flags.get("skip_pass") is not None: # <<<<<<<<<<<<<< + * skip_pass = real_handler.flags.get("skip_pass") + * + */ + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_real_handler, __pyx_n_s_flags); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 59, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_get); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 59, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + __pyx_t_5 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_5 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_3, __pyx_n_u_skip_pass}; + __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 59, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __pyx_t_2 = (__pyx_t_1 != Py_None); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__pyx_t_2) { + + /* "cython_code/throttling_middleware.pyx":60 + * + * if real_handler.flags.get("skip_pass") is not None: + * skip_pass = real_handler.flags.get("skip_pass") # <<<<<<<<<<<<<< + * + * if skip_pass: + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_real_handler, __pyx_n_s_flags); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_get); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + __pyx_t_5 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_5 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_n_u_skip_pass}; + __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 60, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_skip_pass); + __Pyx_DECREF_SET(__pyx_cur_scope->__pyx_v_skip_pass, __pyx_t_1); + __Pyx_GIVEREF(__pyx_t_1); + __pyx_t_1 = 0; + + /* "cython_code/throttling_middleware.pyx":59 + * lang = 'en' + * + * if real_handler.flags.get("skip_pass") is not None: # <<<<<<<<<<<<<< + * skip_pass = real_handler.flags.get("skip_pass") + * + */ + } + + /* "cython_code/throttling_middleware.pyx":62 + * skip_pass = real_handler.flags.get("skip_pass") + * + * if skip_pass: # <<<<<<<<<<<<<< + * if int(time.time()) - self.last_throttled >= self.default_rate: + * self.last_throttled = int(time.time()) + */ + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_cur_scope->__pyx_v_skip_pass); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 62, __pyx_L1_error) + if (__pyx_t_2) { + + /* "cython_code/throttling_middleware.pyx":63 + * + * if skip_pass: + * if int(time.time()) - self.last_throttled >= self.default_rate: # <<<<<<<<<<<<<< + * self.last_throttled = int(time.time()) + * self.default_rate = 0.5 + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 63, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 63, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + __pyx_t_5 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_5 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; + __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 63, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __pyx_t_4 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 63, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_last_throttled); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 63, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = PyNumber_Subtract(__pyx_t_4, __pyx_t_1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 63, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_default_rate); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 63, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_t_1, Py_GE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 63, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 63, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_2) { + + /* "cython_code/throttling_middleware.pyx":64 + * if skip_pass: + * if int(time.time()) - self.last_throttled >= self.default_rate: + * self.last_throttled = int(time.time()) # <<<<<<<<<<<<<< + * self.default_rate = 0.5 + * self.count_throttled = 0 + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 64, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_1, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 64, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __pyx_t_1 = NULL; + __pyx_t_5 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_5 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_1, NULL}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 64, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_t_3 = __Pyx_PyNumber_Int(__pyx_t_4); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 64, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__Pyx_PyObject_SetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_last_throttled, __pyx_t_3) < 0) __PYX_ERR(0, 64, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "cython_code/throttling_middleware.pyx":65 + * if int(time.time()) - self.last_throttled >= self.default_rate: + * self.last_throttled = int(time.time()) + * self.default_rate = 0.5 # <<<<<<<<<<<<<< + * self.count_throttled = 0 + * return await handler(event, data) + */ + if (__Pyx_PyObject_SetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_default_rate, __pyx_float_0_5) < 0) __PYX_ERR(0, 65, __pyx_L1_error) + + /* "cython_code/throttling_middleware.pyx":66 + * self.last_throttled = int(time.time()) + * self.default_rate = 0.5 + * self.count_throttled = 0 # <<<<<<<<<<<<<< + * return await handler(event, data) + * else: + */ + if (__Pyx_PyObject_SetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_count_throttled, __pyx_int_0) < 0) __PYX_ERR(0, 66, __pyx_L1_error) + + /* "cython_code/throttling_middleware.pyx":67 + * self.default_rate = 0.5 + * self.count_throttled = 0 + * return await handler(event, data) # <<<<<<<<<<<<<< + * else: + * if self.count_throttled >= 2: + */ + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_handler); + __pyx_t_4 = __pyx_cur_scope->__pyx_v_handler; __pyx_t_1 = NULL; + __pyx_t_5 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_1 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_1)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_1); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_5 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[3] = {__pyx_t_1, __pyx_cur_scope->__pyx_v_event, __pyx_cur_scope->__pyx_v_data}; + __pyx_t_3 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_5, 2+__pyx_t_5); + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 67, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_r); + if (likely(__pyx_r)) { + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, awaiting value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L8_resume_from_await:; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 67, __pyx_L1_error) + __pyx_t_3 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_3); + } else { + __pyx_t_3 = NULL; + if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_3) < 0) __PYX_ERR(0, 67, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + } + __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_3); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + goto __pyx_L0; + + /* "cython_code/throttling_middleware.pyx":63 + * + * if skip_pass: + * if int(time.time()) - self.last_throttled >= self.default_rate: # <<<<<<<<<<<<<< + * self.last_throttled = int(time.time()) + * self.default_rate = 0.5 + */ + } + + /* "cython_code/throttling_middleware.pyx":69 + * return await handler(event, data) + * else: + * if self.count_throttled >= 2: # <<<<<<<<<<<<<< + * self.default_rate = 3 + * else: + */ + /*else*/ { + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_count_throttled); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 69, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = PyObject_RichCompare(__pyx_t_3, __pyx_int_2, Py_GE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 69, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_2 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_2 < 0))) __PYX_ERR(0, 69, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_2) { + + /* "cython_code/throttling_middleware.pyx":70 + * else: + * if self.count_throttled >= 2: + * self.default_rate = 3 # <<<<<<<<<<<<<< + * else: + * try: + */ + if (__Pyx_PyObject_SetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_default_rate, __pyx_int_3) < 0) __PYX_ERR(0, 70, __pyx_L1_error) + + /* "cython_code/throttling_middleware.pyx":69 + * return await handler(event, data) + * else: + * if self.count_throttled >= 2: # <<<<<<<<<<<<<< + * self.default_rate = 3 + * else: + */ + goto __pyx_L9; + } + + /* "cython_code/throttling_middleware.pyx":72 + * self.default_rate = 3 + * else: + * try: # <<<<<<<<<<<<<< + * self.count_throttled += 1 + * tx = translator(text='Many requests have been made', dest=lang) + */ + /*else*/ { + { + __Pyx_ExceptionSave(&__pyx_t_6, &__pyx_t_7, &__pyx_t_8); + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_7); + __Pyx_XGOTREF(__pyx_t_8); + /*try:*/ { + + /* "cython_code/throttling_middleware.pyx":73 + * else: + * try: + * self.count_throttled += 1 # <<<<<<<<<<<<<< + * tx = translator(text='Many requests have been made', dest=lang) + * try: + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_count_throttled); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 73, __pyx_L10_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyInt_AddObjC(__pyx_t_4, __pyx_int_1, 1, 1, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 73, __pyx_L10_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__Pyx_PyObject_SetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_count_throttled, __pyx_t_3) < 0) __PYX_ERR(0, 73, __pyx_L10_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "cython_code/throttling_middleware.pyx":74 + * try: + * self.count_throttled += 1 + * tx = translator(text='Many requests have been made', dest=lang) # <<<<<<<<<<<<<< + * try: + * await event.callback_query.answer(tx) + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_translator); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 74, __pyx_L10_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 74, __pyx_L10_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_text, __pyx_kp_u_Many_requests_have_been_made) < 0) __PYX_ERR(0, 74, __pyx_L10_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_dest, __pyx_cur_scope->__pyx_v_lang) < 0) __PYX_ERR(0, 74, __pyx_L10_error) + __pyx_t_1 = __Pyx_PyObject_Call(__pyx_t_3, __pyx_empty_tuple, __pyx_t_4); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 74, __pyx_L10_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_v_tx = __pyx_t_1; + __pyx_t_1 = 0; + + /* "cython_code/throttling_middleware.pyx":75 + * self.count_throttled += 1 + * tx = translator(text='Many requests have been made', dest=lang) + * try: # <<<<<<<<<<<<<< + * await event.callback_query.answer(tx) + * except: + */ + { + __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + /*try:*/ { + + /* "cython_code/throttling_middleware.pyx":76 + * tx = translator(text='Many requests have been made', dest=lang) + * try: + * await event.callback_query.answer(tx) # <<<<<<<<<<<<<< + * except: + * await bot.send_message( + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_event, __pyx_n_s_callback_query); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 76, __pyx_L16_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_3 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_answer); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 76, __pyx_L16_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __pyx_t_4 = NULL; + __pyx_t_5 = 0; + #if CYTHON_UNPACK_METHODS + if (likely(PyMethod_Check(__pyx_t_3))) { + __pyx_t_4 = PyMethod_GET_SELF(__pyx_t_3); + if (likely(__pyx_t_4)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_3); + __Pyx_INCREF(__pyx_t_4); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_3, function); + __pyx_t_5 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_4, __pyx_cur_scope->__pyx_v_tx}; + __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_3, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5); + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 76, __pyx_L16_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + } + __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_t_1); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_r); + if (likely(__pyx_r)) { + __Pyx_XGIVEREF(__pyx_t_6); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_6; + __Pyx_XGIVEREF(__pyx_t_7); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_7; + __Pyx_XGIVEREF(__pyx_t_8); + __pyx_cur_scope->__pyx_t_2 = __pyx_t_8; + __Pyx_XGIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_t_3 = __pyx_t_9; + __Pyx_XGIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_t_4 = __pyx_t_10; + __Pyx_XGIVEREF(__pyx_t_11); + __pyx_cur_scope->__pyx_t_5 = __pyx_t_11; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, awaiting value */ + __pyx_generator->resume_label = 2; + return __pyx_r; + __pyx_L22_resume_from_await:; + __pyx_t_6 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_6); + __pyx_t_7 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_7); + __pyx_t_8 = __pyx_cur_scope->__pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = 0; + __Pyx_XGOTREF(__pyx_t_8); + __pyx_t_9 = __pyx_cur_scope->__pyx_t_3; + __pyx_cur_scope->__pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_t_9); + __pyx_t_10 = __pyx_cur_scope->__pyx_t_4; + __pyx_cur_scope->__pyx_t_4 = 0; + __Pyx_XGOTREF(__pyx_t_10); + __pyx_t_11 = __pyx_cur_scope->__pyx_t_5; + __pyx_cur_scope->__pyx_t_5 = 0; + __Pyx_XGOTREF(__pyx_t_11); + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 76, __pyx_L16_error) + } else { + PyObject* exc_type = __Pyx_PyErr_CurrentExceptionType(); + if (exc_type) { + if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear(); + else __PYX_ERR(0, 76, __pyx_L16_error) + } + } + + /* "cython_code/throttling_middleware.pyx":75 + * self.count_throttled += 1 + * tx = translator(text='Many requests have been made', dest=lang) + * try: # <<<<<<<<<<<<<< + * await event.callback_query.answer(tx) + * except: + */ + } + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L21_try_end; + __pyx_L16_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "cython_code/throttling_middleware.pyx":77 + * try: + * await event.callback_query.answer(tx) + * except: # <<<<<<<<<<<<<< + * await bot.send_message( + * chat_id=user_id, + */ + /*except:*/ { + __Pyx_AddTraceback("cython_code.throttling_middleware.ThrottlingMiddleware.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_1, &__pyx_t_3, &__pyx_t_4) < 0) __PYX_ERR(0, 77, __pyx_L18_except_error) + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_4); + + /* "cython_code/throttling_middleware.pyx":78 + * await event.callback_query.answer(tx) + * except: + * await bot.send_message( # <<<<<<<<<<<<<< + * chat_id=user_id, + * text=tx, + */ + __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_bot); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 78, __pyx_L18_except_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_send_message); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 78, __pyx_L18_except_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + + /* "cython_code/throttling_middleware.pyx":79 + * except: + * await bot.send_message( + * chat_id=user_id, # <<<<<<<<<<<<<< + * text=tx, + * reply_markup=close_btn() + */ + __pyx_t_12 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 79, __pyx_L18_except_error) + __Pyx_GOTREF(__pyx_t_12); + if (unlikely(!__pyx_cur_scope->__pyx_v_user_id)) { __Pyx_RaiseUnboundLocalError("user_id"); __PYX_ERR(0, 79, __pyx_L18_except_error) } + if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_chat_id, __pyx_cur_scope->__pyx_v_user_id) < 0) __PYX_ERR(0, 79, __pyx_L18_except_error) + + /* "cython_code/throttling_middleware.pyx":80 + * await bot.send_message( + * chat_id=user_id, + * text=tx, # <<<<<<<<<<<<<< + * reply_markup=close_btn() + * ) + */ + if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_text, __pyx_cur_scope->__pyx_v_tx) < 0) __PYX_ERR(0, 79, __pyx_L18_except_error) + + /* "cython_code/throttling_middleware.pyx":81 + * chat_id=user_id, + * text=tx, + * reply_markup=close_btn() # <<<<<<<<<<<<<< + * ) + * except Exception as err: + */ + __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_close_btn); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 81, __pyx_L18_except_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_16 = NULL; + __pyx_t_5 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_15))) { + __pyx_t_16 = PyMethod_GET_SELF(__pyx_t_15); + if (likely(__pyx_t_16)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15); + __Pyx_INCREF(__pyx_t_16); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_15, function); + __pyx_t_5 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_16, NULL}; + __pyx_t_14 = __Pyx_PyObject_FastCall(__pyx_t_15, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5); + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 81, __pyx_L18_except_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } + if (PyDict_SetItem(__pyx_t_12, __pyx_n_s_reply_markup, __pyx_t_14) < 0) __PYX_ERR(0, 79, __pyx_L18_except_error) + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + + /* "cython_code/throttling_middleware.pyx":78 + * await event.callback_query.answer(tx) + * except: + * await bot.send_message( # <<<<<<<<<<<<<< + * chat_id=user_id, + * text=tx, + */ + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_13, __pyx_empty_tuple, __pyx_t_12); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 78, __pyx_L18_except_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_t_14); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XGOTREF(__pyx_r); + if (likely(__pyx_r)) { + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __Pyx_XGIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_3; + __Pyx_XGIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_t_2 = __pyx_t_4; + __Pyx_XGIVEREF(__pyx_t_6); + __pyx_cur_scope->__pyx_t_3 = __pyx_t_6; + __Pyx_XGIVEREF(__pyx_t_7); + __pyx_cur_scope->__pyx_t_4 = __pyx_t_7; + __Pyx_XGIVEREF(__pyx_t_8); + __pyx_cur_scope->__pyx_t_5 = __pyx_t_8; + __Pyx_XGIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_t_6 = __pyx_t_9; + __Pyx_XGIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_t_7 = __pyx_t_10; + __Pyx_XGIVEREF(__pyx_t_11); + __pyx_cur_scope->__pyx_t_8 = __pyx_t_11; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_SwapException(__pyx_generator); + /* return from generator, awaiting value */ + __pyx_generator->resume_label = 3; + return __pyx_r; + __pyx_L25_resume_from_await:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_3 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_3); + __pyx_t_4 = __pyx_cur_scope->__pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = 0; + __Pyx_XGOTREF(__pyx_t_4); + __pyx_t_6 = __pyx_cur_scope->__pyx_t_3; + __pyx_cur_scope->__pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_t_6); + __pyx_t_7 = __pyx_cur_scope->__pyx_t_4; + __pyx_cur_scope->__pyx_t_4 = 0; + __Pyx_XGOTREF(__pyx_t_7); + __pyx_t_8 = __pyx_cur_scope->__pyx_t_5; + __pyx_cur_scope->__pyx_t_5 = 0; + __Pyx_XGOTREF(__pyx_t_8); + __pyx_t_9 = __pyx_cur_scope->__pyx_t_6; + __pyx_cur_scope->__pyx_t_6 = 0; + __Pyx_XGOTREF(__pyx_t_9); + __pyx_t_10 = __pyx_cur_scope->__pyx_t_7; + __pyx_cur_scope->__pyx_t_7 = 0; + __Pyx_XGOTREF(__pyx_t_10); + __pyx_t_11 = __pyx_cur_scope->__pyx_t_8; + __pyx_cur_scope->__pyx_t_8 = 0; + __Pyx_XGOTREF(__pyx_t_11); + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 78, __pyx_L18_except_error) + } else { + PyObject* exc_type = __Pyx_PyErr_CurrentExceptionType(); + if (exc_type) { + if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear(); + else __PYX_ERR(0, 78, __pyx_L18_except_error) + } + } + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L17_exception_handled; + } + + /* "cython_code/throttling_middleware.pyx":75 + * self.count_throttled += 1 + * tx = translator(text='Many requests have been made', dest=lang) + * try: # <<<<<<<<<<<<<< + * await event.callback_query.answer(tx) + * except: + */ + __pyx_L18_except_error:; + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11); + goto __pyx_L10_error; + __pyx_L17_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11); + __pyx_L21_try_end:; + } + + /* "cython_code/throttling_middleware.pyx":72 + * self.default_rate = 3 + * else: + * try: # <<<<<<<<<<<<<< + * self.count_throttled += 1 + * tx = translator(text='Many requests have been made', dest=lang) + */ + } + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_7); __pyx_t_7 = 0; + __Pyx_XDECREF(__pyx_t_8); __pyx_t_8 = 0; + goto __pyx_L15_try_end; + __pyx_L10_error:; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "cython_code/throttling_middleware.pyx":83 + * reply_markup=close_btn() + * ) + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + * + */ + __pyx_t_17 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); + if (__pyx_t_17) { + __Pyx_AddTraceback("cython_code.throttling_middleware.ThrottlingMiddleware.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_3, &__pyx_t_1) < 0) __PYX_ERR(0, 83, __pyx_L12_except_error) + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_INCREF(__pyx_t_3); + __Pyx_GIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_v_err = __pyx_t_3; + /*try:*/ { + + /* "cython_code/throttling_middleware.pyx":84 + * ) + * except Exception as err: + * logging.error(err) # <<<<<<<<<<<<<< + * + * self.last_throttled = int(time.time()) + */ + __Pyx_GetModuleGlobalName(__pyx_t_12, __pyx_n_s_logging); if (unlikely(!__pyx_t_12)) __PYX_ERR(0, 84, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_12); + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_t_12, __pyx_n_s_error); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 84, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_13); + __Pyx_DECREF(__pyx_t_12); __pyx_t_12 = 0; + __pyx_t_12 = NULL; + __pyx_t_5 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_13))) { + __pyx_t_12 = PyMethod_GET_SELF(__pyx_t_13); + if (likely(__pyx_t_12)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_13); + __Pyx_INCREF(__pyx_t_12); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_13, function); + __pyx_t_5 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_12, __pyx_cur_scope->__pyx_v_err}; + __pyx_t_14 = __Pyx_PyObject_FastCall(__pyx_t_13, __pyx_callargs+1-__pyx_t_5, 1+__pyx_t_5); + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 84, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } + + /* "cython_code/throttling_middleware.pyx":83 + * reply_markup=close_btn() + * ) + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + * + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_err); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_err); __pyx_cur_scope->__pyx_v_err = 0; + goto __pyx_L32; + } + __pyx_L31_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_assign + __pyx_t_11 = 0; __pyx_t_10 = 0; __pyx_t_9 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0; + __Pyx_XDECREF(__pyx_t_12); __pyx_t_12 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_t_16); __pyx_t_16 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_20, &__pyx_t_21, &__pyx_t_22); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9) < 0)) __Pyx_ErrFetch(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_20); + __Pyx_XGOTREF(__pyx_t_21); + __Pyx_XGOTREF(__pyx_t_22); + __pyx_t_17 = __pyx_lineno; __pyx_t_18 = __pyx_clineno; __pyx_t_19 = __pyx_filename; + { + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_err); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_err); __pyx_cur_scope->__pyx_v_err = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_20); + __Pyx_XGIVEREF(__pyx_t_21); + __Pyx_XGIVEREF(__pyx_t_22); + __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_21, __pyx_t_22); + } + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_ErrRestore(__pyx_t_11, __pyx_t_10, __pyx_t_9); + __pyx_t_11 = 0; __pyx_t_10 = 0; __pyx_t_9 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0; + __pyx_lineno = __pyx_t_17; __pyx_clineno = __pyx_t_18; __pyx_filename = __pyx_t_19; + goto __pyx_L12_except_error; + } + __pyx_L32:; + } + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_XDECREF(__pyx_t_1); __pyx_t_1 = 0; + goto __pyx_L11_exception_handled; + } + goto __pyx_L12_except_error; + + /* "cython_code/throttling_middleware.pyx":72 + * self.default_rate = 3 + * else: + * try: # <<<<<<<<<<<<<< + * self.count_throttled += 1 + * tx = translator(text='Many requests have been made', dest=lang) + */ + __pyx_L12_except_error:; + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8); + goto __pyx_L1_error; + __pyx_L11_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_6); + __Pyx_XGIVEREF(__pyx_t_7); + __Pyx_XGIVEREF(__pyx_t_8); + __Pyx_ExceptionReset(__pyx_t_6, __pyx_t_7, __pyx_t_8); + __pyx_L15_try_end:; + } + } + __pyx_L9:; + } + + /* "cython_code/throttling_middleware.pyx":86 + * logging.error(err) + * + * self.last_throttled = int(time.time()) # <<<<<<<<<<<<<< + * else: + * return await handler(event, data) + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 86, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_t_3, __pyx_n_s_time); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 86, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = NULL; + __pyx_t_5 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_4))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_4); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_4); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_4, function); + __pyx_t_5 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_3, NULL}; + __pyx_t_1 = __Pyx_PyObject_FastCall(__pyx_t_4, __pyx_callargs+1-__pyx_t_5, 0+__pyx_t_5); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 86, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + } + __pyx_t_4 = __Pyx_PyNumber_Int(__pyx_t_1); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 86, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + if (__Pyx_PyObject_SetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_last_throttled, __pyx_t_4) < 0) __PYX_ERR(0, 86, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "cython_code/throttling_middleware.pyx":62 + * skip_pass = real_handler.flags.get("skip_pass") + * + * if skip_pass: # <<<<<<<<<<<<<< + * if int(time.time()) - self.last_throttled >= self.default_rate: + * self.last_throttled = int(time.time()) + */ + goto __pyx_L6; + } + + /* "cython_code/throttling_middleware.pyx":88 + * self.last_throttled = int(time.time()) + * else: + * return await handler(event, data) # <<<<<<<<<<<<<< + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_handler); + __pyx_t_1 = __pyx_cur_scope->__pyx_v_handler; __pyx_t_3 = NULL; + __pyx_t_5 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_1))) { + __pyx_t_3 = PyMethod_GET_SELF(__pyx_t_1); + if (likely(__pyx_t_3)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_1); + __Pyx_INCREF(__pyx_t_3); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_1, function); + __pyx_t_5 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[3] = {__pyx_t_3, __pyx_cur_scope->__pyx_v_event, __pyx_cur_scope->__pyx_v_data}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_1, __pyx_callargs+1-__pyx_t_5, 2+__pyx_t_5); + __Pyx_XDECREF(__pyx_t_3); __pyx_t_3 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 88, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + } + __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XGOTREF(__pyx_r); + if (likely(__pyx_r)) { + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, awaiting value */ + __pyx_generator->resume_label = 4; + return __pyx_r; + __pyx_L37_resume_from_await:; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 88, __pyx_L1_error) + __pyx_t_4 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_4); + } else { + __pyx_t_4 = NULL; + if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_4) < 0) __PYX_ERR(0, 88, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + } + __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L0; + } + __pyx_L6:; + CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); + + /* "cython_code/throttling_middleware.pyx":31 + * self.last_throttled = 0 + * + * async def __call__(self, handler, event: types.Message, data): # <<<<<<<<<<<<<< + * """ + * Processes incoming messages and enforces throttling rules. + */ + + /* function exit code */ + PyErr_SetNone(PyExc_StopIteration); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_Generator_Replace_StopIteration(0); + __Pyx_XDECREF(__pyx_t_1); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_12); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_15); + __Pyx_XDECREF(__pyx_t_16); + __Pyx_AddTraceback("__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); __pyx_r = 0; + #if !CYTHON_USE_EXC_INFO_STACK + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + #endif + __pyx_generator->resume_label = -1; + __Pyx_Coroutine_clear((PyObject*)__pyx_generator); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +#if CYTHON_USE_FREELISTS +static struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__ *__pyx_freelist_11cython_code_21throttling_middleware___pyx_scope_struct____call__[8]; +static int __pyx_freecount_11cython_code_21throttling_middleware___pyx_scope_struct____call__ = 0; +#endif + +static PyObject *__pyx_tp_new_11cython_code_21throttling_middleware___pyx_scope_struct____call__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o; + #if CYTHON_COMPILING_IN_LIMITED_API + allocfunc alloc_func = (allocfunc)PyType_GetSlot(t, Py_tp_alloc); + o = alloc_func(t, 0); + #else + #if CYTHON_USE_FREELISTS + if (likely((int)(__pyx_freecount_11cython_code_21throttling_middleware___pyx_scope_struct____call__ > 0) & (int)(t->tp_basicsize == sizeof(struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__)))) { + o = (PyObject*)__pyx_freelist_11cython_code_21throttling_middleware___pyx_scope_struct____call__[--__pyx_freecount_11cython_code_21throttling_middleware___pyx_scope_struct____call__]; + memset(o, 0, sizeof(struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__)); + (void) PyObject_INIT(o, t); + PyObject_GC_Track(o); + } else + #endif + { + o = (*t->tp_alloc)(t, 0); + if (unlikely(!o)) return 0; + } + #endif + return o; +} + +static void __pyx_tp_dealloc_11cython_code_21throttling_middleware___pyx_scope_struct____call__(PyObject *o) { + struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__ *p = (struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__ *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && !__Pyx_PyObject_GC_IsFinalized(o)) { + if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_11cython_code_21throttling_middleware___pyx_scope_struct____call__) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->__pyx_v_data); + Py_CLEAR(p->__pyx_v_err); + Py_CLEAR(p->__pyx_v_event); + Py_CLEAR(p->__pyx_v_handler); + Py_CLEAR(p->__pyx_v_lang); + Py_CLEAR(p->__pyx_v_real_handler); + Py_CLEAR(p->__pyx_v_self); + Py_CLEAR(p->__pyx_v_skip_pass); + Py_CLEAR(p->__pyx_v_tx); + Py_CLEAR(p->__pyx_v_user_id); + Py_CLEAR(p->__pyx_t_0); + Py_CLEAR(p->__pyx_t_1); + Py_CLEAR(p->__pyx_t_2); + Py_CLEAR(p->__pyx_t_3); + Py_CLEAR(p->__pyx_t_4); + Py_CLEAR(p->__pyx_t_5); + Py_CLEAR(p->__pyx_t_6); + Py_CLEAR(p->__pyx_t_7); + Py_CLEAR(p->__pyx_t_8); + #if CYTHON_USE_FREELISTS + if (((int)(__pyx_freecount_11cython_code_21throttling_middleware___pyx_scope_struct____call__ < 8) & (int)(Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__)))) { + __pyx_freelist_11cython_code_21throttling_middleware___pyx_scope_struct____call__[__pyx_freecount_11cython_code_21throttling_middleware___pyx_scope_struct____call__++] = ((struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__ *)o); + } else + #endif + { + #if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY + (*Py_TYPE(o)->tp_free)(o); + #else + { + freefunc tp_free = (freefunc)PyType_GetSlot(Py_TYPE(o), Py_tp_free); + if (tp_free) tp_free(o); + } + #endif + } +} + +static int __pyx_tp_traverse_11cython_code_21throttling_middleware___pyx_scope_struct____call__(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__ *p = (struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__ *)o; + if (p->__pyx_v_data) { + e = (*v)(p->__pyx_v_data, a); if (e) return e; + } + if (p->__pyx_v_err) { + e = (*v)(p->__pyx_v_err, a); if (e) return e; + } + if (p->__pyx_v_event) { + e = (*v)(p->__pyx_v_event, a); if (e) return e; + } + if (p->__pyx_v_handler) { + e = (*v)(p->__pyx_v_handler, a); if (e) return e; + } + if (p->__pyx_v_lang) { + e = (*v)(p->__pyx_v_lang, a); if (e) return e; + } + if (p->__pyx_v_real_handler) { + e = (*v)(p->__pyx_v_real_handler, a); if (e) return e; + } + if (p->__pyx_v_self) { + e = (*v)(p->__pyx_v_self, a); if (e) return e; + } + if (p->__pyx_v_skip_pass) { + e = (*v)(p->__pyx_v_skip_pass, a); if (e) return e; + } + if (p->__pyx_v_tx) { + e = (*v)(p->__pyx_v_tx, a); if (e) return e; + } + if (p->__pyx_v_user_id) { + e = (*v)(p->__pyx_v_user_id, a); if (e) return e; + } + if (p->__pyx_t_0) { + e = (*v)(p->__pyx_t_0, a); if (e) return e; + } + if (p->__pyx_t_1) { + e = (*v)(p->__pyx_t_1, a); if (e) return e; + } + if (p->__pyx_t_2) { + e = (*v)(p->__pyx_t_2, a); if (e) return e; + } + if (p->__pyx_t_3) { + e = (*v)(p->__pyx_t_3, a); if (e) return e; + } + if (p->__pyx_t_4) { + e = (*v)(p->__pyx_t_4, a); if (e) return e; + } + if (p->__pyx_t_5) { + e = (*v)(p->__pyx_t_5, a); if (e) return e; + } + if (p->__pyx_t_6) { + e = (*v)(p->__pyx_t_6, a); if (e) return e; + } + if (p->__pyx_t_7) { + e = (*v)(p->__pyx_t_7, a); if (e) return e; + } + if (p->__pyx_t_8) { + e = (*v)(p->__pyx_t_8, a); if (e) return e; + } + return 0; +} +#if CYTHON_USE_TYPE_SPECS +static PyType_Slot __pyx_type_11cython_code_21throttling_middleware___pyx_scope_struct____call___slots[] = { + {Py_tp_dealloc, (void *)__pyx_tp_dealloc_11cython_code_21throttling_middleware___pyx_scope_struct____call__}, + {Py_tp_traverse, (void *)__pyx_tp_traverse_11cython_code_21throttling_middleware___pyx_scope_struct____call__}, + {Py_tp_new, (void *)__pyx_tp_new_11cython_code_21throttling_middleware___pyx_scope_struct____call__}, + {0, 0}, +}; +static PyType_Spec __pyx_type_11cython_code_21throttling_middleware___pyx_scope_struct____call___spec = { + "cython_code.throttling_middleware.__pyx_scope_struct____call__", + sizeof(struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__), + 0, + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_FINALIZE, + __pyx_type_11cython_code_21throttling_middleware___pyx_scope_struct____call___slots, +}; +#else + +static PyTypeObject __pyx_type_11cython_code_21throttling_middleware___pyx_scope_struct____call__ = { + PyVarObject_HEAD_INIT(0, 0) + "cython_code.throttling_middleware.""__pyx_scope_struct____call__", /*tp_name*/ + sizeof(struct __pyx_obj_11cython_code_21throttling_middleware___pyx_scope_struct____call__), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_11cython_code_21throttling_middleware___pyx_scope_struct____call__, /*tp_dealloc*/ + #if PY_VERSION_HEX < 0x030800b4 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 + 0, /*tp_vectorcall_offset*/ + #endif + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_FINALIZE, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_11cython_code_21throttling_middleware___pyx_scope_struct____call__, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + 0, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + #if !CYTHON_USE_TYPE_SPECS + 0, /*tp_dictoffset*/ + #endif + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_11cython_code_21throttling_middleware___pyx_scope_struct____call__, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + #if CYTHON_USE_TP_FINALIZE + 0, /*tp_finalize*/ + #else + NULL, /*tp_finalize*/ + #endif + #endif + #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) + 0, /*tp_vectorcall*/ + #endif + #if __PYX_NEED_TP_PRINT_SLOT == 1 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030C0000 + 0, /*tp_watched*/ + #endif + #if PY_VERSION_HEX >= 0x030d00A4 + 0, /*tp_versions_used*/ + #endif + #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 + 0, /*tp_pypy_flags*/ + #endif +}; +#endif + +static PyMethodDef __pyx_methods[] = { + {0, 0, 0, 0} +}; +#ifndef CYTHON_SMALL_CODE +#if defined(__clang__) + #define CYTHON_SMALL_CODE +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) + #define CYTHON_SMALL_CODE __attribute__((cold)) +#else + #define CYTHON_SMALL_CODE +#endif +#endif +/* #### Code section: pystring_table ### */ + +static int __Pyx_CreateStringTabAndInitStrings(void) { + __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_n_s_BaseMiddleware, __pyx_k_BaseMiddleware, sizeof(__pyx_k_BaseMiddleware), 0, 0, 1, 1}, + {&__pyx_n_s_HandlerObject, __pyx_k_HandlerObject, sizeof(__pyx_k_HandlerObject), 0, 0, 1, 1}, + {&__pyx_kp_u_Many_requests_have_been_made, __pyx_k_Many_requests_have_been_made, sizeof(__pyx_k_Many_requests_have_been_made), 0, 1, 0, 0}, + {&__pyx_kp_s_Middleware_class_to_manage_thro, __pyx_k_Middleware_class_to_manage_thro, sizeof(__pyx_k_Middleware_class_to_manage_thro), 0, 0, 1, 0}, + {&__pyx_n_s_None, __pyx_k_None, sizeof(__pyx_k_None), 0, 0, 1, 1}, + {&__pyx_n_s_ThrottlingMiddleware, __pyx_k_ThrottlingMiddleware, sizeof(__pyx_k_ThrottlingMiddleware), 0, 0, 1, 1}, + {&__pyx_n_s_ThrottlingMiddleware___call, __pyx_k_ThrottlingMiddleware___call, sizeof(__pyx_k_ThrottlingMiddleware___call), 0, 0, 1, 1}, + {&__pyx_n_s_ThrottlingMiddleware___init, __pyx_k_ThrottlingMiddleware___init, sizeof(__pyx_k_ThrottlingMiddleware___init), 0, 0, 1, 1}, + {&__pyx_n_s__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 0, 1, 1}, + {&__pyx_kp_u__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 1, 0, 0}, + {&__pyx_n_s__7, __pyx_k__7, sizeof(__pyx_k__7), 0, 0, 1, 1}, + {&__pyx_n_s_aiogram, __pyx_k_aiogram, sizeof(__pyx_k_aiogram), 0, 0, 1, 1}, + {&__pyx_n_s_aiogram_dispatcher_event_handler, __pyx_k_aiogram_dispatcher_event_handler, sizeof(__pyx_k_aiogram_dispatcher_event_handler), 0, 0, 1, 1}, + {&__pyx_n_s_answer, __pyx_k_answer, sizeof(__pyx_k_answer), 0, 0, 1, 1}, + {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1}, + {&__pyx_n_s_asyncio_coroutines, __pyx_k_asyncio_coroutines, sizeof(__pyx_k_asyncio_coroutines), 0, 0, 1, 1}, + {&__pyx_n_s_await, __pyx_k_await, sizeof(__pyx_k_await), 0, 0, 1, 1}, + {&__pyx_n_s_bot, __pyx_k_bot, sizeof(__pyx_k_bot), 0, 0, 1, 1}, + {&__pyx_n_s_call, __pyx_k_call, sizeof(__pyx_k_call), 0, 0, 1, 1}, + {&__pyx_n_s_callback_query, __pyx_k_callback_query, sizeof(__pyx_k_callback_query), 0, 0, 1, 1}, + {&__pyx_n_s_chat_id, __pyx_k_chat_id, sizeof(__pyx_k_chat_id), 0, 0, 1, 1}, + {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, + {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1}, + {&__pyx_n_s_close_btn, __pyx_k_close_btn, sizeof(__pyx_k_close_btn), 0, 0, 1, 1}, + {&__pyx_n_s_count_throttled, __pyx_k_count_throttled, sizeof(__pyx_k_count_throttled), 0, 0, 1, 1}, + {&__pyx_n_s_cython_code_throttling_middlewar, __pyx_k_cython_code_throttling_middlewar, sizeof(__pyx_k_cython_code_throttling_middlewar), 0, 0, 1, 1}, + {&__pyx_kp_s_cython_code_throttling_middlewar_2, __pyx_k_cython_code_throttling_middlewar_2, sizeof(__pyx_k_cython_code_throttling_middlewar_2), 0, 0, 1, 0}, + {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1}, + {&__pyx_n_s_default_rate, __pyx_k_default_rate, sizeof(__pyx_k_default_rate), 0, 0, 1, 1}, + {&__pyx_n_s_dest, __pyx_k_dest, sizeof(__pyx_k_dest), 0, 0, 1, 1}, + {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1}, + {&__pyx_kp_u_disable, __pyx_k_disable, sizeof(__pyx_k_disable), 0, 1, 0, 0}, + {&__pyx_n_s_doc, __pyx_k_doc, sizeof(__pyx_k_doc), 0, 0, 1, 1}, + {&__pyx_n_u_en, __pyx_k_en, sizeof(__pyx_k_en), 0, 1, 0, 1}, + {&__pyx_kp_u_enable, __pyx_k_enable, sizeof(__pyx_k_enable), 0, 1, 0, 0}, + {&__pyx_n_s_err, __pyx_k_err, sizeof(__pyx_k_err), 0, 0, 1, 1}, + {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1}, + {&__pyx_n_s_event, __pyx_k_event, sizeof(__pyx_k_event), 0, 0, 1, 1}, + {&__pyx_n_s_flags, __pyx_k_flags, sizeof(__pyx_k_flags), 0, 0, 1, 1}, + {&__pyx_n_s_float, __pyx_k_float, sizeof(__pyx_k_float), 0, 0, 1, 1}, + {&__pyx_n_s_from_user, __pyx_k_from_user, sizeof(__pyx_k_from_user), 0, 0, 1, 1}, + {&__pyx_n_s_function_translator, __pyx_k_function_translator, sizeof(__pyx_k_function_translator), 0, 0, 1, 1}, + {&__pyx_kp_u_gc, __pyx_k_gc, sizeof(__pyx_k_gc), 0, 1, 0, 0}, + {&__pyx_n_s_get, __pyx_k_get, sizeof(__pyx_k_get), 0, 0, 1, 1}, + {&__pyx_n_s_handler, __pyx_k_handler, sizeof(__pyx_k_handler), 0, 0, 1, 1}, + {&__pyx_n_u_handler, __pyx_k_handler, sizeof(__pyx_k_handler), 0, 1, 0, 1}, + {&__pyx_n_s_id, __pyx_k_id, sizeof(__pyx_k_id), 0, 0, 1, 1}, + {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, + {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1}, + {&__pyx_n_s_init_subclass, __pyx_k_init_subclass, sizeof(__pyx_k_init_subclass), 0, 0, 1, 1}, + {&__pyx_n_s_initializing, __pyx_k_initializing, sizeof(__pyx_k_initializing), 0, 0, 1, 1}, + {&__pyx_n_s_is_coroutine, __pyx_k_is_coroutine, sizeof(__pyx_k_is_coroutine), 0, 0, 1, 1}, + {&__pyx_kp_u_isenabled, __pyx_k_isenabled, sizeof(__pyx_k_isenabled), 0, 1, 0, 0}, + {&__pyx_n_s_keyboards_inline_close_btn, __pyx_k_keyboards_inline_close_btn, sizeof(__pyx_k_keyboards_inline_close_btn), 0, 0, 1, 1}, + {&__pyx_n_s_lang, __pyx_k_lang, sizeof(__pyx_k_lang), 0, 0, 1, 1}, + {&__pyx_n_s_language_code, __pyx_k_language_code, sizeof(__pyx_k_language_code), 0, 0, 1, 1}, + {&__pyx_n_s_last_throttled, __pyx_k_last_throttled, sizeof(__pyx_k_last_throttled), 0, 0, 1, 1}, + {&__pyx_n_s_limiters, __pyx_k_limiters, sizeof(__pyx_k_limiters), 0, 0, 1, 1}, + {&__pyx_n_s_loader, __pyx_k_loader, sizeof(__pyx_k_loader), 0, 0, 1, 1}, + {&__pyx_n_s_logging, __pyx_k_logging, sizeof(__pyx_k_logging), 0, 0, 1, 1}, + {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_s_message, __pyx_k_message, sizeof(__pyx_k_message), 0, 0, 1, 1}, + {&__pyx_n_s_metaclass, __pyx_k_metaclass, sizeof(__pyx_k_metaclass), 0, 0, 1, 1}, + {&__pyx_n_s_module, __pyx_k_module, sizeof(__pyx_k_module), 0, 0, 1, 1}, + {&__pyx_n_s_mro_entries, __pyx_k_mro_entries, sizeof(__pyx_k_mro_entries), 0, 0, 1, 1}, + {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, + {&__pyx_n_s_prepare, __pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 0, 1, 1}, + {&__pyx_n_s_qualname, __pyx_k_qualname, sizeof(__pyx_k_qualname), 0, 0, 1, 1}, + {&__pyx_n_s_real_handler, __pyx_k_real_handler, sizeof(__pyx_k_real_handler), 0, 0, 1, 1}, + {&__pyx_n_s_reply_markup, __pyx_k_reply_markup, sizeof(__pyx_k_reply_markup), 0, 0, 1, 1}, + {&__pyx_n_s_return, __pyx_k_return, sizeof(__pyx_k_return), 0, 0, 1, 1}, + {&__pyx_n_s_self, __pyx_k_self, sizeof(__pyx_k_self), 0, 0, 1, 1}, + {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1}, + {&__pyx_n_s_send_message, __pyx_k_send_message, sizeof(__pyx_k_send_message), 0, 0, 1, 1}, + {&__pyx_n_s_set_name, __pyx_k_set_name, sizeof(__pyx_k_set_name), 0, 0, 1, 1}, + {&__pyx_n_s_skip_pass, __pyx_k_skip_pass, sizeof(__pyx_k_skip_pass), 0, 0, 1, 1}, + {&__pyx_n_u_skip_pass, __pyx_k_skip_pass, sizeof(__pyx_k_skip_pass), 0, 1, 0, 1}, + {&__pyx_n_s_spec, __pyx_k_spec, sizeof(__pyx_k_spec), 0, 0, 1, 1}, + {&__pyx_n_s_super, __pyx_k_super, sizeof(__pyx_k_super), 0, 0, 1, 1}, + {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {&__pyx_n_s_text, __pyx_k_text, sizeof(__pyx_k_text), 0, 0, 1, 1}, + {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1}, + {&__pyx_n_s_time, __pyx_k_time, sizeof(__pyx_k_time), 0, 0, 1, 1}, + {&__pyx_n_s_translator, __pyx_k_translator, sizeof(__pyx_k_translator), 0, 0, 1, 1}, + {&__pyx_n_s_tx, __pyx_k_tx, sizeof(__pyx_k_tx), 0, 0, 1, 1}, + {&__pyx_n_s_types, __pyx_k_types, sizeof(__pyx_k_types), 0, 0, 1, 1}, + {&__pyx_kp_s_types_Message, __pyx_k_types_Message, sizeof(__pyx_k_types_Message), 0, 0, 1, 0}, + {&__pyx_n_s_user_id, __pyx_k_user_id, sizeof(__pyx_k_user_id), 0, 0, 1, 1}, + {0, 0, 0, 0, 0, 0, 0} + }; + return __Pyx_InitStrings(__pyx_string_tab); +} +/* #### Code section: cached_builtins ### */ +static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { + return 0; +} +/* #### Code section: cached_constants ### */ + +static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "cython_code/throttling_middleware.pyx":17 + * """ + * + * def __init__(self, default_rate: float = 0.5) -> None: # <<<<<<<<<<<<<< + * """ + * Initializes the ThrottlingMiddleware instance. + */ + __pyx_tuple__4 = PyTuple_Pack(2, __pyx_n_s_self, __pyx_n_s_default_rate); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); + __pyx_codeobj__5 = (PyObject*)__Pyx_PyCode_New(2, 0, 0, 2, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__4, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cython_code_throttling_middlewar_2, __pyx_n_s_init, 17, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__5)) __PYX_ERR(0, 17, __pyx_L1_error) + + /* "cython_code/throttling_middleware.pyx":31 + * self.last_throttled = 0 + * + * async def __call__(self, handler, event: types.Message, data): # <<<<<<<<<<<<<< + * """ + * Processes incoming messages and enforces throttling rules. + */ + __pyx_tuple__6 = PyTuple_Pack(10, __pyx_n_s_self, __pyx_n_s_handler, __pyx_n_s_event, __pyx_n_s_data, __pyx_n_s_real_handler, __pyx_n_s_skip_pass, __pyx_n_s_user_id, __pyx_n_s_lang, __pyx_n_s_tx, __pyx_n_s_err); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 31, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__6); + __Pyx_GIVEREF(__pyx_tuple__6); + __pyx_codeobj_ = (PyObject*)__Pyx_PyCode_New(4, 0, 0, 10, 0, CO_OPTIMIZED|CO_NEWLOCALS|CO_COROUTINE, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__6, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cython_code_throttling_middlewar_2, __pyx_n_s_call, 31, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj_)) __PYX_ERR(0, 31, __pyx_L1_error) + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} +/* #### Code section: init_constants ### */ + +static CYTHON_SMALL_CODE int __Pyx_InitConstants(void) { + if (__Pyx_CreateStringTabAndInitStrings() < 0) __PYX_ERR(0, 1, __pyx_L1_error); + __pyx_float_0_5 = PyFloat_FromDouble(0.5); if (unlikely(!__pyx_float_0_5)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_0 = PyInt_FromLong(0); if (unlikely(!__pyx_int_0)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_1 = PyInt_FromLong(1); if (unlikely(!__pyx_int_1)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_2 = PyInt_FromLong(2); if (unlikely(!__pyx_int_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_int_3 = PyInt_FromLong(3); if (unlikely(!__pyx_int_3)) __PYX_ERR(0, 1, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} +/* #### Code section: init_globals ### */ + +static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { + return 0; +} +/* #### Code section: init_module ### */ + +static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/ + +static int __Pyx_modinit_global_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); + /*--- Global init code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); + /*--- Variable export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); + /*--- Function export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_type_init_code(void) { + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); + /*--- Type init code ---*/ + #if CYTHON_USE_TYPE_SPECS + __pyx_ptype_11cython_code_21throttling_middleware___pyx_scope_struct____call__ = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_11cython_code_21throttling_middleware___pyx_scope_struct____call___spec, NULL); if (unlikely(!__pyx_ptype_11cython_code_21throttling_middleware___pyx_scope_struct____call__)) __PYX_ERR(0, 31, __pyx_L1_error) + if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_11cython_code_21throttling_middleware___pyx_scope_struct____call___spec, __pyx_ptype_11cython_code_21throttling_middleware___pyx_scope_struct____call__) < 0) __PYX_ERR(0, 31, __pyx_L1_error) + #else + __pyx_ptype_11cython_code_21throttling_middleware___pyx_scope_struct____call__ = &__pyx_type_11cython_code_21throttling_middleware___pyx_scope_struct____call__; + #endif + #if !CYTHON_COMPILING_IN_LIMITED_API + #endif + #if !CYTHON_USE_TYPE_SPECS + if (__Pyx_PyType_Ready(__pyx_ptype_11cython_code_21throttling_middleware___pyx_scope_struct____call__) < 0) __PYX_ERR(0, 31, __pyx_L1_error) + #endif + #if PY_MAJOR_VERSION < 3 + __pyx_ptype_11cython_code_21throttling_middleware___pyx_scope_struct____call__->tp_print = 0; + #endif + #if !CYTHON_COMPILING_IN_LIMITED_API + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_11cython_code_21throttling_middleware___pyx_scope_struct____call__->tp_dictoffset && __pyx_ptype_11cython_code_21throttling_middleware___pyx_scope_struct____call__->tp_getattro == PyObject_GenericGetAttr)) { + __pyx_ptype_11cython_code_21throttling_middleware___pyx_scope_struct____call__->tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; + } + #endif + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_modinit_type_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); + /*--- Type import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); + /*--- Variable import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); + /*--- Function import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + + +#if PY_MAJOR_VERSION >= 3 +#if CYTHON_PEP489_MULTI_PHASE_INIT +static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ +static int __pyx_pymod_exec_throttling_middleware(PyObject* module); /*proto*/ +static PyModuleDef_Slot __pyx_moduledef_slots[] = { + {Py_mod_create, (void*)__pyx_pymod_create}, + {Py_mod_exec, (void*)__pyx_pymod_exec_throttling_middleware}, + {0, NULL} +}; +#endif + +#ifdef __cplusplus +namespace { + struct PyModuleDef __pyx_moduledef = + #else + static struct PyModuleDef __pyx_moduledef = + #endif + { + PyModuleDef_HEAD_INIT, + "throttling_middleware", + 0, /* m_doc */ + #if CYTHON_PEP489_MULTI_PHASE_INIT + 0, /* m_size */ + #elif CYTHON_USE_MODULE_STATE + sizeof(__pyx_mstate), /* m_size */ + #else + -1, /* m_size */ + #endif + __pyx_methods /* m_methods */, + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_moduledef_slots, /* m_slots */ + #else + NULL, /* m_reload */ + #endif + #if CYTHON_USE_MODULE_STATE + __pyx_m_traverse, /* m_traverse */ + __pyx_m_clear, /* m_clear */ + NULL /* m_free */ + #else + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ + #endif + }; + #ifdef __cplusplus +} /* anonymous namespace */ +#endif +#endif + +#ifndef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#elif PY_MAJOR_VERSION < 3 +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" void +#else +#define __Pyx_PyMODINIT_FUNC void +#endif +#else +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" PyObject * +#else +#define __Pyx_PyMODINIT_FUNC PyObject * +#endif +#endif + + +#if PY_MAJOR_VERSION < 3 +__Pyx_PyMODINIT_FUNC initthrottling_middleware(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC initthrottling_middleware(void) +#else +__Pyx_PyMODINIT_FUNC PyInit_throttling_middleware(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC PyInit_throttling_middleware(void) +#if CYTHON_PEP489_MULTI_PHASE_INIT +{ + return PyModuleDef_Init(&__pyx_moduledef); +} +static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { + #if PY_VERSION_HEX >= 0x030700A1 + static PY_INT64_T main_interpreter_id = -1; + PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); + if (main_interpreter_id == -1) { + main_interpreter_id = current_id; + return (unlikely(current_id == -1)) ? -1 : 0; + } else if (unlikely(main_interpreter_id != current_id)) + #else + static PyInterpreterState *main_interpreter = NULL; + PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; + if (!main_interpreter) { + main_interpreter = current_interpreter; + } else if (unlikely(main_interpreter != current_interpreter)) + #endif + { + PyErr_SetString( + PyExc_ImportError, + "Interpreter change detected - this module can only be loaded into one interpreter per process."); + return -1; + } + return 0; +} +#if CYTHON_COMPILING_IN_LIMITED_API +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *module, const char* from_name, const char* to_name, int allow_none) +#else +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) +#endif +{ + PyObject *value = PyObject_GetAttrString(spec, from_name); + int result = 0; + if (likely(value)) { + if (allow_none || value != Py_None) { +#if CYTHON_COMPILING_IN_LIMITED_API + result = PyModule_AddObject(module, to_name, value); +#else + result = PyDict_SetItemString(moddict, to_name, value); +#endif + } + Py_DECREF(value); + } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + } else { + result = -1; + } + return result; +} +static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def) { + PyObject *module = NULL, *moddict, *modname; + CYTHON_UNUSED_VAR(def); + if (__Pyx_check_single_interpreter()) + return NULL; + if (__pyx_m) + return __Pyx_NewRef(__pyx_m); + modname = PyObject_GetAttrString(spec, "name"); + if (unlikely(!modname)) goto bad; + module = PyModule_NewObject(modname); + Py_DECREF(modname); + if (unlikely(!module)) goto bad; +#if CYTHON_COMPILING_IN_LIMITED_API + moddict = module; +#else + moddict = PyModule_GetDict(module); + if (unlikely(!moddict)) goto bad; +#endif + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; + return module; +bad: + Py_XDECREF(module); + return NULL; +} + + +static CYTHON_SMALL_CODE int __pyx_pymod_exec_throttling_middleware(PyObject *__pyx_pyinit_module) +#endif +#endif +{ + int stringtab_initialized = 0; + #if CYTHON_USE_MODULE_STATE + int pystate_addmodule_run = 0; + #endif + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + PyObject *__pyx_t_7 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannyDeclarations + #if CYTHON_PEP489_MULTI_PHASE_INIT + if (__pyx_m) { + if (__pyx_m == __pyx_pyinit_module) return 0; + PyErr_SetString(PyExc_RuntimeError, "Module 'throttling_middleware' has already been imported. Re-initialisation is not supported."); + return -1; + } + #elif PY_MAJOR_VERSION >= 3 + if (__pyx_m) return __Pyx_NewRef(__pyx_m); + #endif + /*--- Module creation code ---*/ + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_m = __pyx_pyinit_module; + Py_INCREF(__pyx_m); + #else + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4("throttling_middleware", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #elif CYTHON_USE_MODULE_STATE + __pyx_t_1 = PyModule_Create(&__pyx_moduledef); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) + { + int add_module_result = PyState_AddModule(__pyx_t_1, &__pyx_moduledef); + __pyx_t_1 = 0; /* transfer ownership from __pyx_t_1 to "throttling_middleware" pseudovariable */ + if (unlikely((add_module_result < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + pystate_addmodule_run = 1; + } + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #endif + CYTHON_UNUSED_VAR(__pyx_t_1); + __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_d); + __pyx_b = __Pyx_PyImport_AddModuleRef(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_cython_runtime = __Pyx_PyImport_AddModuleRef((const char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if CYTHON_REFNANNY +__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); +if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); +} +#endif + __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_throttling_middleware(void)", 0); + if (__Pyx_check_binary_version(__PYX_LIMITED_VERSION_HEX, __Pyx_get_runtime_version(), CYTHON_COMPILING_IN_LIMITED_API) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pxy_PyFrame_Initialize_Offsets + __Pxy_PyFrame_Initialize_Offsets(); + #endif + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pyx_CyFunction_USED + if (__pyx_CyFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_FusedFunction_USED + if (__pyx_FusedFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Coroutine_USED + if (__pyx_Coroutine_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Generator_USED + if (__pyx_Generator_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_AsyncGen_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_StopAsyncIteration_USED + if (__pyx_StopAsyncIteration_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + /*--- Library function declarations ---*/ + /*--- Threads initialization code ---*/ + #if defined(WITH_THREAD) && PY_VERSION_HEX < 0x030700F0 && defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + PyEval_InitThreads(); + #endif + /*--- Initialize various global constants etc. ---*/ + if (__Pyx_InitConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + stringtab_initialized = 1; + if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) + if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + if (__pyx_module_is_main_cython_code__throttling_middleware) { + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + } + #if PY_MAJOR_VERSION >= 3 + { + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) + if (!PyDict_GetItemString(modules, "cython_code.throttling_middleware")) { + if (unlikely((PyDict_SetItemString(modules, "cython_code.throttling_middleware", __pyx_m) < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + } + } + #endif + /*--- Builtin init code ---*/ + if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Constants init code ---*/ + if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Global type/function init code ---*/ + (void)__Pyx_modinit_global_init_code(); + (void)__Pyx_modinit_variable_export_code(); + (void)__Pyx_modinit_function_export_code(); + if (unlikely((__Pyx_modinit_type_init_code() < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + (void)__Pyx_modinit_type_import_code(); + (void)__Pyx_modinit_variable_import_code(); + (void)__Pyx_modinit_function_import_code(); + /*--- Execution code ---*/ + #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + + /* "cython_code/throttling_middleware.pyx":1 + * import logging # <<<<<<<<<<<<<< + * import time + * from keyboards.inline.close_btn import close_btn + */ + __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_logging, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_logging, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/throttling_middleware.pyx":2 + * import logging + * import time # <<<<<<<<<<<<<< + * from keyboards.inline.close_btn import close_btn + * from aiogram import BaseMiddleware, types + */ + __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_time, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_time, __pyx_t_2) < 0) __PYX_ERR(0, 2, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/throttling_middleware.pyx":3 + * import logging + * import time + * from keyboards.inline.close_btn import close_btn # <<<<<<<<<<<<<< + * from aiogram import BaseMiddleware, types + * from aiogram.dispatcher.event.handler import HandlerObject + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_close_btn); + __Pyx_GIVEREF(__pyx_n_s_close_btn); + if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_close_btn)) __PYX_ERR(0, 3, __pyx_L1_error); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_keyboards_inline_close_btn, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_close_btn); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_close_btn, __pyx_t_2) < 0) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "cython_code/throttling_middleware.pyx":4 + * import time + * from keyboards.inline.close_btn import close_btn + * from aiogram import BaseMiddleware, types # <<<<<<<<<<<<<< + * from aiogram.dispatcher.event.handler import HandlerObject + * from loader import bot + */ + __pyx_t_3 = PyList_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_n_s_BaseMiddleware); + __Pyx_GIVEREF(__pyx_n_s_BaseMiddleware); + if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_BaseMiddleware)) __PYX_ERR(0, 4, __pyx_L1_error); + __Pyx_INCREF(__pyx_n_s_types); + __Pyx_GIVEREF(__pyx_n_s_types); + if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_types)) __PYX_ERR(0, 4, __pyx_L1_error); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_aiogram, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_BaseMiddleware); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_BaseMiddleware, __pyx_t_3) < 0) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_types); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_types, __pyx_t_3) < 0) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/throttling_middleware.pyx":5 + * from keyboards.inline.close_btn import close_btn + * from aiogram import BaseMiddleware, types + * from aiogram.dispatcher.event.handler import HandlerObject # <<<<<<<<<<<<<< + * from loader import bot + * from function.translator import translator + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_HandlerObject); + __Pyx_GIVEREF(__pyx_n_s_HandlerObject); + if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_HandlerObject)) __PYX_ERR(0, 5, __pyx_L1_error); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_aiogram_dispatcher_event_handler, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_HandlerObject); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_HandlerObject, __pyx_t_2) < 0) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "cython_code/throttling_middleware.pyx":6 + * from aiogram import BaseMiddleware, types + * from aiogram.dispatcher.event.handler import HandlerObject + * from loader import bot # <<<<<<<<<<<<<< + * from function.translator import translator + * + */ + __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_n_s_bot); + __Pyx_GIVEREF(__pyx_n_s_bot); + if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_bot)) __PYX_ERR(0, 6, __pyx_L1_error); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_loader, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_bot); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_bot, __pyx_t_3) < 0) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/throttling_middleware.pyx":7 + * from aiogram.dispatcher.event.handler import HandlerObject + * from loader import bot + * from function.translator import translator # <<<<<<<<<<<<<< + * + * class ThrottlingMiddleware(BaseMiddleware): + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_translator); + __Pyx_GIVEREF(__pyx_n_s_translator); + if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_translator)) __PYX_ERR(0, 7, __pyx_L1_error); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_function_translator, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_translator); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_translator, __pyx_t_2) < 0) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "cython_code/throttling_middleware.pyx":9 + * from function.translator import translator + * + * class ThrottlingMiddleware(BaseMiddleware): # <<<<<<<<<<<<<< + * """ + * Middleware class to manage throttling of requests to prevent overloading. + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_BaseMiddleware); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_2 = PyTuple_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_GIVEREF(__pyx_t_3); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_2, 0, __pyx_t_3)) __PYX_ERR(0, 9, __pyx_L1_error); + __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_PEP560_update_bases(__pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_4 = __Pyx_CalculateMetaclass(NULL, __pyx_t_3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_5 = __Pyx_Py3MetaclassPrepare(__pyx_t_4, __pyx_t_3, __pyx_n_s_ThrottlingMiddleware, __pyx_n_s_ThrottlingMiddleware, (PyObject *) NULL, __pyx_n_s_cython_code_throttling_middlewar, __pyx_kp_s_Middleware_class_to_manage_thro); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_3 != __pyx_t_2) { + if (unlikely((PyDict_SetItemString(__pyx_t_5, "__orig_bases__", __pyx_t_2) < 0))) __PYX_ERR(0, 9, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/throttling_middleware.pyx":17 + * """ + * + * def __init__(self, default_rate: float = 0.5) -> None: # <<<<<<<<<<<<<< + * """ + * Initializes the ThrottlingMiddleware instance. + */ + __pyx_t_2 = PyFloat_FromDouble(((double)0.5)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_6 = PyTuple_New(1); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_GIVEREF(__pyx_t_2); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_6, 0, __pyx_t_2)) __PYX_ERR(0, 17, __pyx_L1_error); + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_default_rate, __pyx_n_s_float) < 0) __PYX_ERR(0, 17, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_2, __pyx_n_s_return, __pyx_n_s_None) < 0) __PYX_ERR(0, 17, __pyx_L1_error) + __pyx_t_7 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_21throttling_middleware_20ThrottlingMiddleware_1__init__, 0, __pyx_n_s_ThrottlingMiddleware___init, NULL, __pyx_n_s_cython_code_throttling_middlewar, __pyx_d, ((PyObject *)__pyx_codeobj__5)); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_7, __pyx_t_6); + __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_7, __pyx_t_2); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + if (__Pyx_SetNameInClass(__pyx_t_5, __pyx_n_s_init, __pyx_t_7) < 0) __PYX_ERR(0, 17, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + + /* "cython_code/throttling_middleware.pyx":31 + * self.last_throttled = 0 + * + * async def __call__(self, handler, event: types.Message, data): # <<<<<<<<<<<<<< + * """ + * Processes incoming messages and enforces throttling rules. + */ + __pyx_t_7 = __Pyx_PyDict_NewPresized(1); if (unlikely(!__pyx_t_7)) __PYX_ERR(0, 31, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_7); + if (PyDict_SetItem(__pyx_t_7, __pyx_n_s_event, __pyx_kp_s_types_Message) < 0) __PYX_ERR(0, 31, __pyx_L1_error) + __pyx_t_2 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_21throttling_middleware_20ThrottlingMiddleware_3__call__, __Pyx_CYFUNCTION_COROUTINE, __pyx_n_s_ThrottlingMiddleware___call, NULL, __pyx_n_s_cython_code_throttling_middlewar, __pyx_d, ((PyObject *)__pyx_codeobj_)); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 31, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_2, __pyx_t_7); + __Pyx_DECREF(__pyx_t_7); __pyx_t_7 = 0; + if (__Pyx_SetNameInClass(__pyx_t_5, __pyx_n_s_call, __pyx_t_2) < 0) __PYX_ERR(0, 31, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/throttling_middleware.pyx":9 + * from function.translator import translator + * + * class ThrottlingMiddleware(BaseMiddleware): # <<<<<<<<<<<<<< + * """ + * Middleware class to manage throttling of requests to prevent overloading. + */ + __pyx_t_2 = __Pyx_Py3ClassCreate(__pyx_t_4, __pyx_n_s_ThrottlingMiddleware, __pyx_t_3, __pyx_t_5, NULL, 0, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_ThrottlingMiddleware, __pyx_t_2) < 0) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "cython_code/throttling_middleware.pyx":1 + * import logging # <<<<<<<<<<<<<< + * import time + * from keyboards.inline.close_btn import close_btn + */ + __pyx_t_3 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_3) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /*--- Wrapped vars code ---*/ + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_7); + if (__pyx_m) { + if (__pyx_d && stringtab_initialized) { + __Pyx_AddTraceback("init cython_code.throttling_middleware", __pyx_clineno, __pyx_lineno, __pyx_filename); + } + #if !CYTHON_USE_MODULE_STATE + Py_CLEAR(__pyx_m); + #else + Py_DECREF(__pyx_m); + if (pystate_addmodule_run) { + PyObject *tp, *value, *tb; + PyErr_Fetch(&tp, &value, &tb); + PyState_RemoveModule(&__pyx_moduledef); + PyErr_Restore(tp, value, tb); + } + #endif + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init cython_code.throttling_middleware"); + } + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + #if CYTHON_PEP489_MULTI_PHASE_INIT + return (__pyx_m != NULL) ? 0 : -1; + #elif PY_MAJOR_VERSION >= 3 + return __pyx_m; + #else + return; + #endif +} +/* #### Code section: cleanup_globals ### */ +/* #### Code section: cleanup_module ### */ +/* #### Code section: main_method ### */ +/* #### Code section: utility_code_pragmas ### */ +#ifdef _MSC_VER +#pragma warning( push ) +/* Warning 4127: conditional expression is constant + * Cython uses constant conditional expressions to allow in inline functions to be optimized at + * compile-time, so this warning is not useful + */ +#pragma warning( disable : 4127 ) +#endif + + + +/* #### Code section: utility_code_def ### */ + +/* --- Runtime support code --- */ +/* Refnanny */ +#if CYTHON_REFNANNY +static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { + PyObject *m = NULL, *p = NULL; + void *r = NULL; + m = PyImport_ImportModule(modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, "RefNannyAPI"); + if (!p) goto end; + r = PyLong_AsVoidPtr(p); +end: + Py_XDECREF(p); + Py_XDECREF(m); + return (__Pyx_RefNannyAPIStruct *)r; +} +#endif + +/* TupleAndListFromArray */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE void __Pyx_copy_object_array(PyObject *const *CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) { + PyObject *v; + Py_ssize_t i; + for (i = 0; i < length; i++) { + v = dest[i] = src[i]; + Py_INCREF(v); + } +} +static CYTHON_INLINE PyObject * +__Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n) +{ + PyObject *res; + if (n <= 0) { + Py_INCREF(__pyx_empty_tuple); + return __pyx_empty_tuple; + } + res = PyTuple_New(n); + if (unlikely(res == NULL)) return NULL; + __Pyx_copy_object_array(src, ((PyTupleObject*)res)->ob_item, n); + return res; +} +static CYTHON_INLINE PyObject * +__Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n) +{ + PyObject *res; + if (n <= 0) { + return PyList_New(0); + } + res = PyList_New(n); + if (unlikely(res == NULL)) return NULL; + __Pyx_copy_object_array(src, ((PyListObject*)res)->ob_item, n); + return res; +} +#endif + +/* BytesEquals */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API + return PyObject_RichCompareBool(s1, s2, equals); +#else + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { + const char *ps1, *ps2; + Py_ssize_t length = PyBytes_GET_SIZE(s1); + if (length != PyBytes_GET_SIZE(s2)) + return (equals == Py_NE); + ps1 = PyBytes_AS_STRING(s1); + ps2 = PyBytes_AS_STRING(s2); + if (ps1[0] != ps2[0]) { + return (equals == Py_NE); + } else if (length == 1) { + return (equals == Py_EQ); + } else { + int result; +#if CYTHON_USE_UNICODE_INTERNALS && (PY_VERSION_HEX < 0x030B0000) + Py_hash_t hash1, hash2; + hash1 = ((PyBytesObject*)s1)->ob_shash; + hash2 = ((PyBytesObject*)s2)->ob_shash; + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + return (equals == Py_NE); + } +#endif + result = memcmp(ps1, ps2, (size_t)length); + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +#endif +} + +/* UnicodeEquals */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API + return PyObject_RichCompareBool(s1, s2, equals); +#else +#if PY_MAJOR_VERSION < 3 + PyObject* owned_ref = NULL; +#endif + int s1_is_unicode, s2_is_unicode; + if (s1 == s2) { + goto return_eq; + } + s1_is_unicode = PyUnicode_CheckExact(s1); + s2_is_unicode = PyUnicode_CheckExact(s2); +#if PY_MAJOR_VERSION < 3 + if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { + owned_ref = PyUnicode_FromObject(s2); + if (unlikely(!owned_ref)) + return -1; + s2 = owned_ref; + s2_is_unicode = 1; + } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { + owned_ref = PyUnicode_FromObject(s1); + if (unlikely(!owned_ref)) + return -1; + s1 = owned_ref; + s1_is_unicode = 1; + } else if (((!s2_is_unicode) & (!s1_is_unicode))) { + return __Pyx_PyBytes_Equals(s1, s2, equals); + } +#endif + if (s1_is_unicode & s2_is_unicode) { + Py_ssize_t length; + int kind; + void *data1, *data2; + if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) + return -1; + length = __Pyx_PyUnicode_GET_LENGTH(s1); + if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { + goto return_ne; + } +#if CYTHON_USE_UNICODE_INTERNALS + { + Py_hash_t hash1, hash2; + #if CYTHON_PEP393_ENABLED + hash1 = ((PyASCIIObject*)s1)->hash; + hash2 = ((PyASCIIObject*)s2)->hash; + #else + hash1 = ((PyUnicodeObject*)s1)->hash; + hash2 = ((PyUnicodeObject*)s2)->hash; + #endif + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + goto return_ne; + } + } +#endif + kind = __Pyx_PyUnicode_KIND(s1); + if (kind != __Pyx_PyUnicode_KIND(s2)) { + goto return_ne; + } + data1 = __Pyx_PyUnicode_DATA(s1); + data2 = __Pyx_PyUnicode_DATA(s2); + if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { + goto return_ne; + } else if (length == 1) { + goto return_eq; + } else { + int result = memcmp(data1, data2, (size_t)(length * kind)); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & s2_is_unicode) { + goto return_ne; + } else if ((s2 == Py_None) & s1_is_unicode) { + goto return_ne; + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +return_eq: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ); +return_ne: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_NE); +#endif +} + +/* fastcall */ +#if CYTHON_METH_FASTCALL +static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s) +{ + Py_ssize_t i, n = PyTuple_GET_SIZE(kwnames); + for (i = 0; i < n; i++) + { + if (s == PyTuple_GET_ITEM(kwnames, i)) return kwvalues[i]; + } + for (i = 0; i < n; i++) + { + int eq = __Pyx_PyUnicode_Equals(s, PyTuple_GET_ITEM(kwnames, i), Py_EQ); + if (unlikely(eq != 0)) { + if (unlikely(eq < 0)) return NULL; + return kwvalues[i]; + } + } + return NULL; +} +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000 +CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues) { + Py_ssize_t i, nkwargs = PyTuple_GET_SIZE(kwnames); + PyObject *dict; + dict = PyDict_New(); + if (unlikely(!dict)) + return NULL; + for (i=0; i= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AsString(kw_name)); + #endif +} + +/* ParseKeywords */ +static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject *const *kwvalues, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + int kwds_is_tuple = CYTHON_METH_FASTCALL && likely(PyTuple_Check(kwds)); + while (1) { + Py_XDECREF(key); key = NULL; + Py_XDECREF(value); value = NULL; + if (kwds_is_tuple) { + Py_ssize_t size; +#if CYTHON_ASSUME_SAFE_MACROS + size = PyTuple_GET_SIZE(kwds); +#else + size = PyTuple_Size(kwds); + if (size < 0) goto bad; +#endif + if (pos >= size) break; +#if CYTHON_AVOID_BORROWED_REFS + key = __Pyx_PySequence_ITEM(kwds, pos); + if (!key) goto bad; +#elif CYTHON_ASSUME_SAFE_MACROS + key = PyTuple_GET_ITEM(kwds, pos); +#else + key = PyTuple_GetItem(kwds, pos); + if (!key) goto bad; +#endif + value = kwvalues[pos]; + pos++; + } + else + { + if (!PyDict_Next(kwds, &pos, &key, &value)) break; +#if CYTHON_AVOID_BORROWED_REFS + Py_INCREF(key); +#endif + } + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; +#if CYTHON_AVOID_BORROWED_REFS + Py_INCREF(value); + Py_DECREF(key); +#endif + key = NULL; + value = NULL; + continue; + } +#if !CYTHON_AVOID_BORROWED_REFS + Py_INCREF(key); +#endif + Py_INCREF(value); + name = first_kw_arg; + #if PY_MAJOR_VERSION < 3 + if (likely(PyString_Check(key))) { + while (*name) { + if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) + && _PyString_Eq(**name, key)) { + values[name-argnames] = value; +#if CYTHON_AVOID_BORROWED_REFS + value = NULL; +#endif + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + if ((**argname == key) || ( + (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) + && _PyString_Eq(**argname, key))) { + goto arg_passed_twice; + } + argname++; + } + } + } else + #endif + if (likely(PyUnicode_Check(key))) { + while (*name) { + int cmp = ( + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : + #endif + PyUnicode_Compare(**name, key) + ); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) { + values[name-argnames] = value; +#if CYTHON_AVOID_BORROWED_REFS + value = NULL; +#endif + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + int cmp = (**argname == key) ? 0 : + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : + #endif + PyUnicode_Compare(**argname, key); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) goto arg_passed_twice; + argname++; + } + } + } else + goto invalid_keyword_type; + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; + } + } + Py_XDECREF(key); + Py_XDECREF(value); + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, key); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + #if PY_MAJOR_VERSION < 3 + PyErr_Format(PyExc_TypeError, + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + PyErr_Format(PyExc_TypeError, + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + Py_XDECREF(key); + Py_XDECREF(value); + return -1; +} + +/* RaiseArgTupleInvalid */ +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *more_or_less; + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; + } else { + num_expected = num_max; + more_or_less = "at most"; + } + if (exact) { + more_or_less = "exactly"; + } + PyErr_Format(PyExc_TypeError, + "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", + func_name, more_or_less, num_expected, + (num_expected == 1) ? "" : "s", num_found); +} + +/* PyObjectSetAttrStr */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_setattro)) + return tp->tp_setattro(obj, attr_name, value); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_setattr)) + return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value); +#endif + return PyObject_SetAttr(obj, attr_name, value); +} +#endif + +/* DictGetItem */ +#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY +static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { + PyObject *value; + value = PyDict_GetItemWithError(d, key); + if (unlikely(!value)) { + if (!PyErr_Occurred()) { + if (unlikely(PyTuple_Check(key))) { + PyObject* args = PyTuple_Pack(1, key); + if (likely(args)) { + PyErr_SetObject(PyExc_KeyError, args); + Py_DECREF(args); + } + } else { + PyErr_SetObject(PyExc_KeyError, key); + } + } + return NULL; + } + Py_INCREF(value); + return value; +} +#endif + +/* PyObjectGetAttrStr */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro)) + return tp->tp_getattro(obj, attr_name); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_getattr)) + return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); +#endif + return PyObject_GetAttr(obj, attr_name); +} +#endif + +/* PyFunctionFastCall */ +#if CYTHON_FAST_PYCALL && !CYTHON_VECTORCALL +static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na, + PyObject *globals) { + PyFrameObject *f; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject **fastlocals; + Py_ssize_t i; + PyObject *result; + assert(globals != NULL); + /* XXX Perhaps we should create a specialized + PyFrame_New() that doesn't take locals, but does + take builtins without sanity checking them. + */ + assert(tstate != NULL); + f = PyFrame_New(tstate, co, globals, NULL); + if (f == NULL) { + return NULL; + } + fastlocals = __Pyx_PyFrame_GetLocalsplus(f); + for (i = 0; i < na; i++) { + Py_INCREF(*args); + fastlocals[i] = *args++; + } + result = PyEval_EvalFrameEx(f,0); + ++tstate->recursion_depth; + Py_DECREF(f); + --tstate->recursion_depth; + return result; +} +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) { + PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); + PyObject *globals = PyFunction_GET_GLOBALS(func); + PyObject *argdefs = PyFunction_GET_DEFAULTS(func); + PyObject *closure; +#if PY_MAJOR_VERSION >= 3 + PyObject *kwdefs; +#endif + PyObject *kwtuple, **k; + PyObject **d; + Py_ssize_t nd; + Py_ssize_t nk; + PyObject *result; + assert(kwargs == NULL || PyDict_Check(kwargs)); + nk = kwargs ? PyDict_Size(kwargs) : 0; + #if PY_MAJOR_VERSION < 3 + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) { + return NULL; + } + #else + if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) { + return NULL; + } + #endif + if ( +#if PY_MAJOR_VERSION >= 3 + co->co_kwonlyargcount == 0 && +#endif + likely(kwargs == NULL || nk == 0) && + co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { + if (argdefs == NULL && co->co_argcount == nargs) { + result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals); + goto done; + } + else if (nargs == 0 && argdefs != NULL + && co->co_argcount == Py_SIZE(argdefs)) { + /* function called with no arguments, but all parameters have + a default value: use default values as arguments .*/ + args = &PyTuple_GET_ITEM(argdefs, 0); + result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals); + goto done; + } + } + if (kwargs != NULL) { + Py_ssize_t pos, i; + kwtuple = PyTuple_New(2 * nk); + if (kwtuple == NULL) { + result = NULL; + goto done; + } + k = &PyTuple_GET_ITEM(kwtuple, 0); + pos = i = 0; + while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) { + Py_INCREF(k[i]); + Py_INCREF(k[i+1]); + i += 2; + } + nk = i / 2; + } + else { + kwtuple = NULL; + k = NULL; + } + closure = PyFunction_GET_CLOSURE(func); +#if PY_MAJOR_VERSION >= 3 + kwdefs = PyFunction_GET_KW_DEFAULTS(func); +#endif + if (argdefs != NULL) { + d = &PyTuple_GET_ITEM(argdefs, 0); + nd = Py_SIZE(argdefs); + } + else { + d = NULL; + nd = 0; + } +#if PY_MAJOR_VERSION >= 3 + result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL, + args, (int)nargs, + k, (int)nk, + d, (int)nd, kwdefs, closure); +#else + result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, + args, (int)nargs, + k, (int)nk, + d, (int)nd, closure); +#endif + Py_XDECREF(kwtuple); +done: + Py_LeaveRecursiveCall(); + return result; +} +#endif + +/* PyObjectCall */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *result; + ternaryfunc call = Py_TYPE(func)->tp_call; + if (unlikely(!call)) + return PyObject_Call(func, arg, kw); + #if PY_MAJOR_VERSION < 3 + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + #else + if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) + return NULL; + #endif + result = (*call)(func, arg, kw); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* PyObjectCallMethO */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) { + PyObject *self, *result; + PyCFunction cfunc; + cfunc = __Pyx_CyOrPyCFunction_GET_FUNCTION(func); + self = __Pyx_CyOrPyCFunction_GET_SELF(func); + #if PY_MAJOR_VERSION < 3 + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + #else + if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) + return NULL; + #endif + result = cfunc(self, arg); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* PyObjectFastCall */ +#if PY_VERSION_HEX < 0x03090000 || CYTHON_COMPILING_IN_LIMITED_API +static PyObject* __Pyx_PyObject_FastCall_fallback(PyObject *func, PyObject **args, size_t nargs, PyObject *kwargs) { + PyObject *argstuple; + PyObject *result = 0; + size_t i; + argstuple = PyTuple_New((Py_ssize_t)nargs); + if (unlikely(!argstuple)) return NULL; + for (i = 0; i < nargs; i++) { + Py_INCREF(args[i]); + if (__Pyx_PyTuple_SET_ITEM(argstuple, (Py_ssize_t)i, args[i]) < 0) goto bad; + } + result = __Pyx_PyObject_Call(func, argstuple, kwargs); + bad: + Py_DECREF(argstuple); + return result; +} +#endif +static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject **args, size_t _nargs, PyObject *kwargs) { + Py_ssize_t nargs = __Pyx_PyVectorcall_NARGS(_nargs); +#if CYTHON_COMPILING_IN_CPYTHON + if (nargs == 0 && kwargs == NULL) { + if (__Pyx_CyOrPyCFunction_Check(func) && likely( __Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_NOARGS)) + return __Pyx_PyObject_CallMethO(func, NULL); + } + else if (nargs == 1 && kwargs == NULL) { + if (__Pyx_CyOrPyCFunction_Check(func) && likely( __Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_O)) + return __Pyx_PyObject_CallMethO(func, args[0]); + } +#endif + #if PY_VERSION_HEX < 0x030800B1 + #if CYTHON_FAST_PYCCALL + if (PyCFunction_Check(func)) { + if (kwargs) { + return _PyCFunction_FastCallDict(func, args, nargs, kwargs); + } else { + return _PyCFunction_FastCallKeywords(func, args, nargs, NULL); + } + } + #if PY_VERSION_HEX >= 0x030700A1 + if (!kwargs && __Pyx_IS_TYPE(func, &PyMethodDescr_Type)) { + return _PyMethodDescr_FastCallKeywords(func, args, nargs, NULL); + } + #endif + #endif + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(func)) { + return __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs); + } + #endif + #endif + if (kwargs == NULL) { + #if CYTHON_VECTORCALL + #if PY_VERSION_HEX < 0x03090000 + vectorcallfunc f = _PyVectorcall_Function(func); + #else + vectorcallfunc f = PyVectorcall_Function(func); + #endif + if (f) { + return f(func, args, (size_t)nargs, NULL); + } + #elif defined(__Pyx_CyFunction_USED) && CYTHON_BACKPORT_VECTORCALL + if (__Pyx_CyFunction_CheckExact(func)) { + __pyx_vectorcallfunc f = __Pyx_CyFunction_func_vectorcall(func); + if (f) return f(func, args, (size_t)nargs, NULL); + } + #endif + } + if (nargs == 0) { + return __Pyx_PyObject_Call(func, __pyx_empty_tuple, kwargs); + } + #if PY_VERSION_HEX >= 0x03090000 && !CYTHON_COMPILING_IN_LIMITED_API + return PyObject_VectorcallDict(func, args, (size_t)nargs, kwargs); + #else + return __Pyx_PyObject_FastCall_fallback(func, args, (size_t)nargs, kwargs); + #endif +} + +/* PyErrExceptionMatches */ +#if CYTHON_FAST_THREAD_STATE +static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; i= 0x030C00A6 + PyObject *current_exception = tstate->current_exception; + if (unlikely(!current_exception)) return 0; + exc_type = (PyObject*) Py_TYPE(current_exception); + if (exc_type == err) return 1; +#else + exc_type = tstate->curexc_type; + if (exc_type == err) return 1; + if (unlikely(!exc_type)) return 0; +#endif + #if CYTHON_AVOID_BORROWED_REFS + Py_INCREF(exc_type); + #endif + if (unlikely(PyTuple_Check(err))) { + result = __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); + } else { + result = __Pyx_PyErr_GivenExceptionMatches(exc_type, err); + } + #if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(exc_type); + #endif + return result; +} +#endif + +/* PyErrFetchRestore */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { +#if PY_VERSION_HEX >= 0x030C00A6 + PyObject *tmp_value; + assert(type == NULL || (value != NULL && type == (PyObject*) Py_TYPE(value))); + if (value) { + #if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(((PyBaseExceptionObject*) value)->traceback != tb)) + #endif + PyException_SetTraceback(value, tb); + } + tmp_value = tstate->current_exception; + tstate->current_exception = value; + Py_XDECREF(tmp_value); + Py_XDECREF(type); + Py_XDECREF(tb); +#else + PyObject *tmp_type, *tmp_value, *tmp_tb; + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#endif +} +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { +#if PY_VERSION_HEX >= 0x030C00A6 + PyObject* exc_value; + exc_value = tstate->current_exception; + tstate->current_exception = 0; + *value = exc_value; + *type = NULL; + *tb = NULL; + if (exc_value) { + *type = (PyObject*) Py_TYPE(exc_value); + Py_INCREF(*type); + #if CYTHON_COMPILING_IN_CPYTHON + *tb = ((PyBaseExceptionObject*) exc_value)->traceback; + Py_XINCREF(*tb); + #else + *tb = PyException_GetTraceback(exc_value); + #endif + } +#else + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +#endif +} +#endif + +/* PyObjectGetAttrStrNoError */ +#if __PYX_LIMITED_VERSION_HEX < 0x030d00A1 +static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + __Pyx_PyErr_Clear(); +} +#endif +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { + PyObject *result; +#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1 + (void) PyObject_GetOptionalAttr(obj, attr_name, &result); + return result; +#else +#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { + return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); + } +#endif + result = __Pyx_PyObject_GetAttrStr(obj, attr_name); + if (unlikely(!result)) { + __Pyx_PyObject_GetAttrStr_ClearAttributeError(); + } + return result; +#endif +} + +/* GetBuiltinName */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name) { + PyObject* result = __Pyx_PyObject_GetAttrStrNoError(__pyx_b, name); + if (unlikely(!result) && !PyErr_Occurred()) { + PyErr_Format(PyExc_NameError, +#if PY_MAJOR_VERSION >= 3 + "name '%U' is not defined", name); +#else + "name '%.200s' is not defined", PyString_AS_STRING(name)); +#endif + } + return result; +} + +/* PyDictVersioning */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { + PyObject **dictptr = NULL; + Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; + if (offset) { +#if CYTHON_COMPILING_IN_CPYTHON + dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); +#else + dictptr = _PyObject_GetDictPtr(obj); +#endif + } + return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; +} +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) + return 0; + return obj_dict_version == __Pyx_get_object_dict_version(obj); +} +#endif + +/* GetModuleGlobalName */ +#if CYTHON_USE_DICT_VERSIONS +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) +#else +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) +#endif +{ + PyObject *result; +#if !CYTHON_AVOID_BORROWED_REFS +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && PY_VERSION_HEX < 0x030d0000 + result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } else if (unlikely(PyErr_Occurred())) { + return NULL; + } +#elif CYTHON_COMPILING_IN_LIMITED_API + if (unlikely(!__pyx_m)) { + return NULL; + } + result = PyObject_GetAttr(__pyx_m, name); + if (likely(result)) { + return result; + } +#else + result = PyDict_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } +#endif +#else + result = PyObject_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } + PyErr_Clear(); +#endif + return __Pyx_GetBuiltinName(name); +} + +/* FixUpExtensionType */ +#if CYTHON_USE_TYPE_SPECS +static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type) { +#if PY_VERSION_HEX > 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + CYTHON_UNUSED_VAR(spec); + CYTHON_UNUSED_VAR(type); +#else + const PyType_Slot *slot = spec->slots; + while (slot && slot->slot && slot->slot != Py_tp_members) + slot++; + if (slot && slot->slot == Py_tp_members) { + int changed = 0; +#if !(PY_VERSION_HEX <= 0x030900b1 && CYTHON_COMPILING_IN_CPYTHON) + const +#endif + PyMemberDef *memb = (PyMemberDef*) slot->pfunc; + while (memb && memb->name) { + if (memb->name[0] == '_' && memb->name[1] == '_') { +#if PY_VERSION_HEX < 0x030900b1 + if (strcmp(memb->name, "__weaklistoffset__") == 0) { + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); + type->tp_weaklistoffset = memb->offset; + changed = 1; + } + else if (strcmp(memb->name, "__dictoffset__") == 0) { + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); + type->tp_dictoffset = memb->offset; + changed = 1; + } +#if CYTHON_METH_FASTCALL + else if (strcmp(memb->name, "__vectorcalloffset__") == 0) { + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); +#if PY_VERSION_HEX >= 0x030800b4 + type->tp_vectorcall_offset = memb->offset; +#else + type->tp_print = (printfunc) memb->offset; +#endif + changed = 1; + } +#endif +#else + if ((0)); +#endif +#if PY_VERSION_HEX <= 0x030900b1 && CYTHON_COMPILING_IN_CPYTHON + else if (strcmp(memb->name, "__module__") == 0) { + PyObject *descr; + assert(memb->type == T_OBJECT); + assert(memb->flags == 0 || memb->flags == READONLY); + descr = PyDescr_NewMember(type, memb); + if (unlikely(!descr)) + return -1; + if (unlikely(PyDict_SetItem(type->tp_dict, PyDescr_NAME(descr), descr) < 0)) { + Py_DECREF(descr); + return -1; + } + Py_DECREF(descr); + changed = 1; + } +#endif + } + memb++; + } + if (changed) + PyType_Modified(type); + } +#endif + return 0; +} +#endif + +/* FetchSharedCythonModule */ +static PyObject *__Pyx_FetchSharedCythonABIModule(void) { + return __Pyx_PyImport_AddModuleRef((char*) __PYX_ABI_MODULE_NAME); +} + +/* FetchCommonType */ +static int __Pyx_VerifyCachedType(PyObject *cached_type, + const char *name, + Py_ssize_t basicsize, + Py_ssize_t expected_basicsize) { + if (!PyType_Check(cached_type)) { + PyErr_Format(PyExc_TypeError, + "Shared Cython type %.200s is not a type object", name); + return -1; + } + if (basicsize != expected_basicsize) { + PyErr_Format(PyExc_TypeError, + "Shared Cython type %.200s has the wrong size, try recompiling", + name); + return -1; + } + return 0; +} +#if !CYTHON_USE_TYPE_SPECS +static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) { + PyObject* abi_module; + const char* object_name; + PyTypeObject *cached_type = NULL; + abi_module = __Pyx_FetchSharedCythonABIModule(); + if (!abi_module) return NULL; + object_name = strrchr(type->tp_name, '.'); + object_name = object_name ? object_name+1 : type->tp_name; + cached_type = (PyTypeObject*) PyObject_GetAttrString(abi_module, object_name); + if (cached_type) { + if (__Pyx_VerifyCachedType( + (PyObject *)cached_type, + object_name, + cached_type->tp_basicsize, + type->tp_basicsize) < 0) { + goto bad; + } + goto done; + } + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; + PyErr_Clear(); + if (PyType_Ready(type) < 0) goto bad; + if (PyObject_SetAttrString(abi_module, object_name, (PyObject *)type) < 0) + goto bad; + Py_INCREF(type); + cached_type = type; +done: + Py_DECREF(abi_module); + return cached_type; +bad: + Py_XDECREF(cached_type); + cached_type = NULL; + goto done; +} +#else +static PyTypeObject *__Pyx_FetchCommonTypeFromSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) { + PyObject *abi_module, *cached_type = NULL; + const char* object_name = strrchr(spec->name, '.'); + object_name = object_name ? object_name+1 : spec->name; + abi_module = __Pyx_FetchSharedCythonABIModule(); + if (!abi_module) return NULL; + cached_type = PyObject_GetAttrString(abi_module, object_name); + if (cached_type) { + Py_ssize_t basicsize; +#if CYTHON_COMPILING_IN_LIMITED_API + PyObject *py_basicsize; + py_basicsize = PyObject_GetAttrString(cached_type, "__basicsize__"); + if (unlikely(!py_basicsize)) goto bad; + basicsize = PyLong_AsSsize_t(py_basicsize); + Py_DECREF(py_basicsize); + py_basicsize = 0; + if (unlikely(basicsize == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad; +#else + basicsize = likely(PyType_Check(cached_type)) ? ((PyTypeObject*) cached_type)->tp_basicsize : -1; +#endif + if (__Pyx_VerifyCachedType( + cached_type, + object_name, + basicsize, + spec->basicsize) < 0) { + goto bad; + } + goto done; + } + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; + PyErr_Clear(); + CYTHON_UNUSED_VAR(module); + cached_type = __Pyx_PyType_FromModuleAndSpec(abi_module, spec, bases); + if (unlikely(!cached_type)) goto bad; + if (unlikely(__Pyx_fix_up_extension_type_from_spec(spec, (PyTypeObject *) cached_type) < 0)) goto bad; + if (PyObject_SetAttrString(abi_module, object_name, cached_type) < 0) goto bad; +done: + Py_DECREF(abi_module); + assert(cached_type == NULL || PyType_Check(cached_type)); + return (PyTypeObject *) cached_type; +bad: + Py_XDECREF(cached_type); + cached_type = NULL; + goto done; +} +#endif + +/* RaiseException */ +#if PY_MAJOR_VERSION < 3 +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + __Pyx_PyThreadState_declare + CYTHON_UNUSED_VAR(cause); + Py_XINCREF(type); + if (!value || value == Py_None) + value = NULL; + else + Py_INCREF(value); + if (!tb || tb == Py_None) + tb = NULL; + else { + Py_INCREF(tb); + if (!PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + } + if (PyType_Check(type)) { +#if CYTHON_COMPILING_IN_PYPY + if (!value) { + Py_INCREF(Py_None); + value = Py_None; + } +#endif + PyErr_NormalizeException(&type, &value, &tb); + } else { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + value = type; + type = (PyObject*) Py_TYPE(type); + Py_INCREF(type); + if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto raise_error; + } + } + __Pyx_PyThreadState_assign + __Pyx_ErrRestore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} +#else +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + PyObject* owned_instance = NULL; + if (tb == Py_None) { + tb = 0; + } else if (tb && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto bad; + } + if (value == Py_None) + value = 0; + if (PyExceptionInstance_Check(type)) { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto bad; + } + value = type; + type = (PyObject*) Py_TYPE(value); + } else if (PyExceptionClass_Check(type)) { + PyObject *instance_class = NULL; + if (value && PyExceptionInstance_Check(value)) { + instance_class = (PyObject*) Py_TYPE(value); + if (instance_class != type) { + int is_subclass = PyObject_IsSubclass(instance_class, type); + if (!is_subclass) { + instance_class = NULL; + } else if (unlikely(is_subclass == -1)) { + goto bad; + } else { + type = instance_class; + } + } + } + if (!instance_class) { + PyObject *args; + if (!value) + args = PyTuple_New(0); + else if (PyTuple_Check(value)) { + Py_INCREF(value); + args = value; + } else + args = PyTuple_Pack(1, value); + if (!args) + goto bad; + owned_instance = PyObject_Call(type, args, NULL); + Py_DECREF(args); + if (!owned_instance) + goto bad; + value = owned_instance; + if (!PyExceptionInstance_Check(value)) { + PyErr_Format(PyExc_TypeError, + "calling %R should have returned an instance of " + "BaseException, not %R", + type, Py_TYPE(value)); + goto bad; + } + } + } else { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto bad; + } + if (cause) { + PyObject *fixed_cause; + if (cause == Py_None) { + fixed_cause = NULL; + } else if (PyExceptionClass_Check(cause)) { + fixed_cause = PyObject_CallObject(cause, NULL); + if (fixed_cause == NULL) + goto bad; + } else if (PyExceptionInstance_Check(cause)) { + fixed_cause = cause; + Py_INCREF(fixed_cause); + } else { + PyErr_SetString(PyExc_TypeError, + "exception causes must derive from " + "BaseException"); + goto bad; + } + PyException_SetCause(value, fixed_cause); + } + PyErr_SetObject(type, value); + if (tb) { + #if PY_VERSION_HEX >= 0x030C00A6 + PyException_SetTraceback(value, tb); + #elif CYTHON_FAST_THREAD_STATE + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject* tmp_tb = tstate->curexc_traceback; + if (tb != tmp_tb) { + Py_INCREF(tb); + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_tb); + } +#else + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); + Py_INCREF(tb); + PyErr_Restore(tmp_type, tmp_value, tb); + Py_XDECREF(tmp_tb); +#endif + } +bad: + Py_XDECREF(owned_instance); + return; +} +#endif + +/* GetTopmostException */ +#if CYTHON_USE_EXC_INFO_STACK && CYTHON_FAST_THREAD_STATE +static _PyErr_StackItem * +__Pyx_PyErr_GetTopmostException(PyThreadState *tstate) +{ + _PyErr_StackItem *exc_info = tstate->exc_info; + while ((exc_info->exc_value == NULL || exc_info->exc_value == Py_None) && + exc_info->previous_item != NULL) + { + exc_info = exc_info->previous_item; + } + return exc_info; +} +#endif + +/* SaveResetException */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4 + _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); + PyObject *exc_value = exc_info->exc_value; + if (exc_value == NULL || exc_value == Py_None) { + *value = NULL; + *type = NULL; + *tb = NULL; + } else { + *value = exc_value; + Py_INCREF(*value); + *type = (PyObject*) Py_TYPE(exc_value); + Py_INCREF(*type); + *tb = PyException_GetTraceback(exc_value); + } + #elif CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); + *type = exc_info->exc_type; + *value = exc_info->exc_value; + *tb = exc_info->exc_traceback; + Py_XINCREF(*type); + Py_XINCREF(*value); + Py_XINCREF(*tb); + #else + *type = tstate->exc_type; + *value = tstate->exc_value; + *tb = tstate->exc_traceback; + Py_XINCREF(*type); + Py_XINCREF(*value); + Py_XINCREF(*tb); + #endif +} +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { + #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4 + _PyErr_StackItem *exc_info = tstate->exc_info; + PyObject *tmp_value = exc_info->exc_value; + exc_info->exc_value = value; + Py_XDECREF(tmp_value); + Py_XDECREF(type); + Py_XDECREF(tb); + #else + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = type; + exc_info->exc_value = value; + exc_info->exc_traceback = tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = type; + tstate->exc_value = value; + tstate->exc_traceback = tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); + #endif +} +#endif + +/* SwapException */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4 + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_value = exc_info->exc_value; + exc_info->exc_value = *value; + if (tmp_value == NULL || tmp_value == Py_None) { + Py_XDECREF(tmp_value); + tmp_value = NULL; + tmp_type = NULL; + tmp_tb = NULL; + } else { + tmp_type = (PyObject*) Py_TYPE(tmp_value); + Py_INCREF(tmp_type); + #if CYTHON_COMPILING_IN_CPYTHON + tmp_tb = ((PyBaseExceptionObject*) tmp_value)->traceback; + Py_XINCREF(tmp_tb); + #else + tmp_tb = PyException_GetTraceback(tmp_value); + #endif + } + #elif CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = *type; + exc_info->exc_value = *value; + exc_info->exc_traceback = *tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = *type; + tstate->exc_value = *value; + tstate->exc_traceback = *tb; + #endif + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb); + PyErr_SetExcInfo(*type, *value, *tb); + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#endif + +/* PyObjectCall2Args */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) { + PyObject *args[3] = {NULL, arg1, arg2}; + return __Pyx_PyObject_FastCall(function, args+1, 2 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET); +} + +/* PyObjectCallOneArg */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { + PyObject *args[2] = {NULL, arg}; + return __Pyx_PyObject_FastCall(func, args+1, 1 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET); +} + +/* PyObjectGetMethod */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) { + PyObject *attr; +#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP + __Pyx_TypeName type_name; + PyTypeObject *tp = Py_TYPE(obj); + PyObject *descr; + descrgetfunc f = NULL; + PyObject **dictptr, *dict; + int meth_found = 0; + assert (*method == NULL); + if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) { + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; + } + if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) { + return 0; + } + descr = _PyType_Lookup(tp, name); + if (likely(descr != NULL)) { + Py_INCREF(descr); +#if defined(Py_TPFLAGS_METHOD_DESCRIPTOR) && Py_TPFLAGS_METHOD_DESCRIPTOR + if (__Pyx_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR)) +#elif PY_MAJOR_VERSION >= 3 + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type))) + #endif +#else + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr))) + #endif +#endif + { + meth_found = 1; + } else { + f = Py_TYPE(descr)->tp_descr_get; + if (f != NULL && PyDescr_IsData(descr)) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + } + } + dictptr = _PyObject_GetDictPtr(obj); + if (dictptr != NULL && (dict = *dictptr) != NULL) { + Py_INCREF(dict); + attr = __Pyx_PyDict_GetItemStr(dict, name); + if (attr != NULL) { + Py_INCREF(attr); + Py_DECREF(dict); + Py_XDECREF(descr); + goto try_unpack; + } + Py_DECREF(dict); + } + if (meth_found) { + *method = descr; + return 1; + } + if (f != NULL) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + if (likely(descr != NULL)) { + *method = descr; + return 0; + } + type_name = __Pyx_PyType_GetName(tp); + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%U'", + type_name, name); +#else + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%.400s'", + type_name, PyString_AS_STRING(name)); +#endif + __Pyx_DECREF_TypeName(type_name); + return 0; +#else + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; +#endif +try_unpack: +#if CYTHON_UNPACK_METHODS + if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) { + PyObject *function = PyMethod_GET_FUNCTION(attr); + Py_INCREF(function); + Py_DECREF(attr); + *method = function; + return 1; + } +#endif + *method = attr; + return 0; +} + +/* PyObjectCallMethod1 */ +#if !(CYTHON_VECTORCALL && __PYX_LIMITED_VERSION_HEX >= 0x030C00A2) +static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) { + PyObject *result = __Pyx_PyObject_CallOneArg(method, arg); + Py_DECREF(method); + return result; +} +#endif +static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) { +#if CYTHON_VECTORCALL && __PYX_LIMITED_VERSION_HEX >= 0x030C00A2 + PyObject *args[2] = {obj, arg}; + (void) __Pyx_PyObject_GetMethod; + (void) __Pyx_PyObject_CallOneArg; + (void) __Pyx_PyObject_Call2Args; + return PyObject_VectorcallMethod(method_name, args, 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL); +#else + PyObject *method = NULL, *result; + int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); + if (likely(is_method)) { + result = __Pyx_PyObject_Call2Args(method, obj, arg); + Py_DECREF(method); + return result; + } + if (unlikely(!method)) return NULL; + return __Pyx__PyObject_CallMethod1(method, arg); +#endif +} + +/* PyObjectCallNoArg */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { + PyObject *arg[2] = {NULL, NULL}; + return __Pyx_PyObject_FastCall(func, arg + 1, 0 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET); +} + +/* CoroutineBase */ +#include +#if PY_VERSION_HEX >= 0x030b00a6 + #ifndef Py_BUILD_CORE + #define Py_BUILD_CORE 1 + #endif + #include "internal/pycore_frame.h" +#endif +#define __Pyx_Coroutine_Undelegate(gen) Py_CLEAR((gen)->yieldfrom) +static int __Pyx_PyGen__FetchStopIterationValue(PyThreadState *__pyx_tstate, PyObject **pvalue) { + PyObject *et, *ev, *tb; + PyObject *value = NULL; + CYTHON_UNUSED_VAR(__pyx_tstate); + __Pyx_ErrFetch(&et, &ev, &tb); + if (!et) { + Py_XDECREF(tb); + Py_XDECREF(ev); + Py_INCREF(Py_None); + *pvalue = Py_None; + return 0; + } + if (likely(et == PyExc_StopIteration)) { + if (!ev) { + Py_INCREF(Py_None); + value = Py_None; + } +#if PY_VERSION_HEX >= 0x030300A0 + else if (likely(__Pyx_IS_TYPE(ev, (PyTypeObject*)PyExc_StopIteration))) { + value = ((PyStopIterationObject *)ev)->value; + Py_INCREF(value); + Py_DECREF(ev); + } +#endif + else if (unlikely(PyTuple_Check(ev))) { + if (PyTuple_GET_SIZE(ev) >= 1) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + value = PyTuple_GET_ITEM(ev, 0); + Py_INCREF(value); +#else + value = PySequence_ITEM(ev, 0); +#endif + } else { + Py_INCREF(Py_None); + value = Py_None; + } + Py_DECREF(ev); + } + else if (!__Pyx_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration)) { + value = ev; + } + if (likely(value)) { + Py_XDECREF(tb); + Py_DECREF(et); + *pvalue = value; + return 0; + } + } else if (!__Pyx_PyErr_GivenExceptionMatches(et, PyExc_StopIteration)) { + __Pyx_ErrRestore(et, ev, tb); + return -1; + } + PyErr_NormalizeException(&et, &ev, &tb); + if (unlikely(!PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration))) { + __Pyx_ErrRestore(et, ev, tb); + return -1; + } + Py_XDECREF(tb); + Py_DECREF(et); +#if PY_VERSION_HEX >= 0x030300A0 + value = ((PyStopIterationObject *)ev)->value; + Py_INCREF(value); + Py_DECREF(ev); +#else + { + PyObject* args = __Pyx_PyObject_GetAttrStr(ev, __pyx_n_s_args); + Py_DECREF(ev); + if (likely(args)) { + value = PySequence_GetItem(args, 0); + Py_DECREF(args); + } + if (unlikely(!value)) { + __Pyx_ErrRestore(NULL, NULL, NULL); + Py_INCREF(Py_None); + value = Py_None; + } + } +#endif + *pvalue = value; + return 0; +} +static CYTHON_INLINE +void __Pyx_Coroutine_ExceptionClear(__Pyx_ExcInfoStruct *exc_state) { +#if PY_VERSION_HEX >= 0x030B00a4 + Py_CLEAR(exc_state->exc_value); +#else + PyObject *t, *v, *tb; + t = exc_state->exc_type; + v = exc_state->exc_value; + tb = exc_state->exc_traceback; + exc_state->exc_type = NULL; + exc_state->exc_value = NULL; + exc_state->exc_traceback = NULL; + Py_XDECREF(t); + Py_XDECREF(v); + Py_XDECREF(tb); +#endif +} +#define __Pyx_Coroutine_AlreadyRunningError(gen) (__Pyx__Coroutine_AlreadyRunningError(gen), (PyObject*)NULL) +static void __Pyx__Coroutine_AlreadyRunningError(__pyx_CoroutineObject *gen) { + const char *msg; + CYTHON_MAYBE_UNUSED_VAR(gen); + if ((0)) { + #ifdef __Pyx_Coroutine_USED + } else if (__Pyx_Coroutine_Check((PyObject*)gen)) { + msg = "coroutine already executing"; + #endif + #ifdef __Pyx_AsyncGen_USED + } else if (__Pyx_AsyncGen_CheckExact((PyObject*)gen)) { + msg = "async generator already executing"; + #endif + } else { + msg = "generator already executing"; + } + PyErr_SetString(PyExc_ValueError, msg); +} +#define __Pyx_Coroutine_NotStartedError(gen) (__Pyx__Coroutine_NotStartedError(gen), (PyObject*)NULL) +static void __Pyx__Coroutine_NotStartedError(PyObject *gen) { + const char *msg; + CYTHON_MAYBE_UNUSED_VAR(gen); + if ((0)) { + #ifdef __Pyx_Coroutine_USED + } else if (__Pyx_Coroutine_Check(gen)) { + msg = "can't send non-None value to a just-started coroutine"; + #endif + #ifdef __Pyx_AsyncGen_USED + } else if (__Pyx_AsyncGen_CheckExact(gen)) { + msg = "can't send non-None value to a just-started async generator"; + #endif + } else { + msg = "can't send non-None value to a just-started generator"; + } + PyErr_SetString(PyExc_TypeError, msg); +} +#define __Pyx_Coroutine_AlreadyTerminatedError(gen, value, closing) (__Pyx__Coroutine_AlreadyTerminatedError(gen, value, closing), (PyObject*)NULL) +static void __Pyx__Coroutine_AlreadyTerminatedError(PyObject *gen, PyObject *value, int closing) { + CYTHON_MAYBE_UNUSED_VAR(gen); + CYTHON_MAYBE_UNUSED_VAR(closing); + #ifdef __Pyx_Coroutine_USED + if (!closing && __Pyx_Coroutine_Check(gen)) { + PyErr_SetString(PyExc_RuntimeError, "cannot reuse already awaited coroutine"); + } else + #endif + if (value) { + #ifdef __Pyx_AsyncGen_USED + if (__Pyx_AsyncGen_CheckExact(gen)) + PyErr_SetNone(__Pyx_PyExc_StopAsyncIteration); + else + #endif + PyErr_SetNone(PyExc_StopIteration); + } +} +static +PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value, int closing) { + __Pyx_PyThreadState_declare + PyThreadState *tstate; + __Pyx_ExcInfoStruct *exc_state; + PyObject *retval; + assert(!self->is_running); + if (unlikely(self->resume_label == 0)) { + if (unlikely(value && value != Py_None)) { + return __Pyx_Coroutine_NotStartedError((PyObject*)self); + } + } + if (unlikely(self->resume_label == -1)) { + return __Pyx_Coroutine_AlreadyTerminatedError((PyObject*)self, value, closing); + } +#if CYTHON_FAST_THREAD_STATE + __Pyx_PyThreadState_assign + tstate = __pyx_tstate; +#else + tstate = __Pyx_PyThreadState_Current; +#endif + exc_state = &self->gi_exc_state; + if (exc_state->exc_value) { + #if CYTHON_COMPILING_IN_PYPY + #else + PyObject *exc_tb; + #if PY_VERSION_HEX >= 0x030B00a4 && !CYTHON_COMPILING_IN_CPYTHON + exc_tb = PyException_GetTraceback(exc_state->exc_value); + #elif PY_VERSION_HEX >= 0x030B00a4 + exc_tb = ((PyBaseExceptionObject*) exc_state->exc_value)->traceback; + #else + exc_tb = exc_state->exc_traceback; + #endif + if (exc_tb) { + PyTracebackObject *tb = (PyTracebackObject *) exc_tb; + PyFrameObject *f = tb->tb_frame; + assert(f->f_back == NULL); + #if PY_VERSION_HEX >= 0x030B00A1 + f->f_back = PyThreadState_GetFrame(tstate); + #else + Py_XINCREF(tstate->frame); + f->f_back = tstate->frame; + #endif + #if PY_VERSION_HEX >= 0x030B00a4 && !CYTHON_COMPILING_IN_CPYTHON + Py_DECREF(exc_tb); + #endif + } + #endif + } +#if CYTHON_USE_EXC_INFO_STACK + exc_state->previous_item = tstate->exc_info; + tstate->exc_info = exc_state; +#else + if (exc_state->exc_type) { + __Pyx_ExceptionSwap(&exc_state->exc_type, &exc_state->exc_value, &exc_state->exc_traceback); + } else { + __Pyx_Coroutine_ExceptionClear(exc_state); + __Pyx_ExceptionSave(&exc_state->exc_type, &exc_state->exc_value, &exc_state->exc_traceback); + } +#endif + self->is_running = 1; + retval = self->body(self, tstate, value); + self->is_running = 0; +#if CYTHON_USE_EXC_INFO_STACK + exc_state = &self->gi_exc_state; + tstate->exc_info = exc_state->previous_item; + exc_state->previous_item = NULL; + __Pyx_Coroutine_ResetFrameBackpointer(exc_state); +#endif + return retval; +} +static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__Pyx_ExcInfoStruct *exc_state) { +#if CYTHON_COMPILING_IN_PYPY + CYTHON_UNUSED_VAR(exc_state); +#else + PyObject *exc_tb; + #if PY_VERSION_HEX >= 0x030B00a4 + if (!exc_state->exc_value) return; + exc_tb = PyException_GetTraceback(exc_state->exc_value); + #else + exc_tb = exc_state->exc_traceback; + #endif + if (likely(exc_tb)) { + PyTracebackObject *tb = (PyTracebackObject *) exc_tb; + PyFrameObject *f = tb->tb_frame; + Py_CLEAR(f->f_back); + #if PY_VERSION_HEX >= 0x030B00a4 + Py_DECREF(exc_tb); + #endif + } +#endif +} +static CYTHON_INLINE +PyObject *__Pyx_Coroutine_MethodReturn(PyObject* gen, PyObject *retval) { + CYTHON_MAYBE_UNUSED_VAR(gen); + if (unlikely(!retval)) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (!__Pyx_PyErr_Occurred()) { + PyObject *exc = PyExc_StopIteration; + #ifdef __Pyx_AsyncGen_USED + if (__Pyx_AsyncGen_CheckExact(gen)) + exc = __Pyx_PyExc_StopAsyncIteration; + #endif + __Pyx_PyErr_SetNone(exc); + } + } + return retval; +} +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3) +static CYTHON_INLINE +PyObject *__Pyx_PyGen_Send(PyGenObject *gen, PyObject *arg) { +#if PY_VERSION_HEX <= 0x030A00A1 + return _PyGen_Send(gen, arg); +#else + PyObject *result; + if (PyIter_Send((PyObject*)gen, arg ? arg : Py_None, &result) == PYGEN_RETURN) { + if (PyAsyncGen_CheckExact(gen)) { + assert(result == Py_None); + PyErr_SetNone(PyExc_StopAsyncIteration); + } + else if (result == Py_None) { + PyErr_SetNone(PyExc_StopIteration); + } + else { +#if PY_VERSION_HEX < 0x030d00A1 + _PyGen_SetStopIterationValue(result); +#else + if (!PyTuple_Check(result) && !PyExceptionInstance_Check(result)) { + PyErr_SetObject(PyExc_StopIteration, result); + } else { + PyObject *exc = __Pyx_PyObject_CallOneArg(PyExc_StopIteration, result); + if (likely(exc != NULL)) { + PyErr_SetObject(PyExc_StopIteration, exc); + Py_DECREF(exc); + } + } +#endif + } + Py_DECREF(result); + result = NULL; + } + return result; +#endif +} +#endif +static CYTHON_INLINE +PyObject *__Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen) { + PyObject *ret; + PyObject *val = NULL; + __Pyx_Coroutine_Undelegate(gen); + __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, &val); + ret = __Pyx_Coroutine_SendEx(gen, val, 0); + Py_XDECREF(val); + return ret; +} +static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value) { + PyObject *retval; + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self; + PyObject *yf = gen->yieldfrom; + if (unlikely(gen->is_running)) + return __Pyx_Coroutine_AlreadyRunningError(gen); + if (yf) { + PyObject *ret; + gen->is_running = 1; + #ifdef __Pyx_Generator_USED + if (__Pyx_Generator_CheckExact(yf)) { + ret = __Pyx_Coroutine_Send(yf, value); + } else + #endif + #ifdef __Pyx_Coroutine_USED + if (__Pyx_Coroutine_Check(yf)) { + ret = __Pyx_Coroutine_Send(yf, value); + } else + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_PyAsyncGenASend_CheckExact(yf)) { + ret = __Pyx_async_gen_asend_send(yf, value); + } else + #endif + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3) + if (PyGen_CheckExact(yf)) { + ret = __Pyx_PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value); + } else + #endif + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03050000 && defined(PyCoro_CheckExact) && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3) + if (PyCoro_CheckExact(yf)) { + ret = __Pyx_PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value); + } else + #endif + { + if (value == Py_None) + ret = __Pyx_PyObject_GetIterNextFunc(yf)(yf); + else + ret = __Pyx_PyObject_CallMethod1(yf, __pyx_n_s_send, value); + } + gen->is_running = 0; + if (likely(ret)) { + return ret; + } + retval = __Pyx_Coroutine_FinishDelegation(gen); + } else { + retval = __Pyx_Coroutine_SendEx(gen, value, 0); + } + return __Pyx_Coroutine_MethodReturn(self, retval); +} +static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) { + PyObject *retval = NULL; + int err = 0; + #ifdef __Pyx_Generator_USED + if (__Pyx_Generator_CheckExact(yf)) { + retval = __Pyx_Coroutine_Close(yf); + if (!retval) + return -1; + } else + #endif + #ifdef __Pyx_Coroutine_USED + if (__Pyx_Coroutine_Check(yf)) { + retval = __Pyx_Coroutine_Close(yf); + if (!retval) + return -1; + } else + if (__Pyx_CoroutineAwait_CheckExact(yf)) { + retval = __Pyx_CoroutineAwait_Close((__pyx_CoroutineAwaitObject*)yf, NULL); + if (!retval) + return -1; + } else + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_PyAsyncGenASend_CheckExact(yf)) { + retval = __Pyx_async_gen_asend_close(yf, NULL); + } else + if (__pyx_PyAsyncGenAThrow_CheckExact(yf)) { + retval = __Pyx_async_gen_athrow_close(yf, NULL); + } else + #endif + { + PyObject *meth; + gen->is_running = 1; + meth = __Pyx_PyObject_GetAttrStrNoError(yf, __pyx_n_s_close); + if (unlikely(!meth)) { + if (unlikely(PyErr_Occurred())) { + PyErr_WriteUnraisable(yf); + } + } else { + retval = __Pyx_PyObject_CallNoArg(meth); + Py_DECREF(meth); + if (unlikely(!retval)) + err = -1; + } + gen->is_running = 0; + } + Py_XDECREF(retval); + return err; +} +static PyObject *__Pyx_Generator_Next(PyObject *self) { + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self; + PyObject *yf = gen->yieldfrom; + if (unlikely(gen->is_running)) + return __Pyx_Coroutine_AlreadyRunningError(gen); + if (yf) { + PyObject *ret; + gen->is_running = 1; + #ifdef __Pyx_Generator_USED + if (__Pyx_Generator_CheckExact(yf)) { + ret = __Pyx_Generator_Next(yf); + } else + #endif + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3) + if (PyGen_CheckExact(yf)) { + ret = __Pyx_PyGen_Send((PyGenObject*)yf, NULL); + } else + #endif + #ifdef __Pyx_Coroutine_USED + if (__Pyx_Coroutine_Check(yf)) { + ret = __Pyx_Coroutine_Send(yf, Py_None); + } else + #endif + ret = __Pyx_PyObject_GetIterNextFunc(yf)(yf); + gen->is_running = 0; + if (likely(ret)) { + return ret; + } + return __Pyx_Coroutine_FinishDelegation(gen); + } + return __Pyx_Coroutine_SendEx(gen, Py_None, 0); +} +static PyObject *__Pyx_Coroutine_Close_Method(PyObject *self, PyObject *arg) { + CYTHON_UNUSED_VAR(arg); + return __Pyx_Coroutine_Close(self); +} +static PyObject *__Pyx_Coroutine_Close(PyObject *self) { + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; + PyObject *retval, *raised_exception; + PyObject *yf = gen->yieldfrom; + int err = 0; + if (unlikely(gen->is_running)) + return __Pyx_Coroutine_AlreadyRunningError(gen); + if (yf) { + Py_INCREF(yf); + err = __Pyx_Coroutine_CloseIter(gen, yf); + __Pyx_Coroutine_Undelegate(gen); + Py_DECREF(yf); + } + if (err == 0) + PyErr_SetNone(PyExc_GeneratorExit); + retval = __Pyx_Coroutine_SendEx(gen, NULL, 1); + if (unlikely(retval)) { + const char *msg; + Py_DECREF(retval); + if ((0)) { + #ifdef __Pyx_Coroutine_USED + } else if (__Pyx_Coroutine_Check(self)) { + msg = "coroutine ignored GeneratorExit"; + #endif + #ifdef __Pyx_AsyncGen_USED + } else if (__Pyx_AsyncGen_CheckExact(self)) { +#if PY_VERSION_HEX < 0x03060000 + msg = "async generator ignored GeneratorExit - might require Python 3.6+ finalisation (PEP 525)"; +#else + msg = "async generator ignored GeneratorExit"; +#endif + #endif + } else { + msg = "generator ignored GeneratorExit"; + } + PyErr_SetString(PyExc_RuntimeError, msg); + return NULL; + } + raised_exception = PyErr_Occurred(); + if (likely(!raised_exception || __Pyx_PyErr_GivenExceptionMatches2(raised_exception, PyExc_GeneratorExit, PyExc_StopIteration))) { + if (raised_exception) PyErr_Clear(); + Py_INCREF(Py_None); + return Py_None; + } + return NULL; +} +static PyObject *__Pyx__Coroutine_Throw(PyObject *self, PyObject *typ, PyObject *val, PyObject *tb, + PyObject *args, int close_on_genexit) { + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; + PyObject *yf = gen->yieldfrom; + if (unlikely(gen->is_running)) + return __Pyx_Coroutine_AlreadyRunningError(gen); + if (yf) { + PyObject *ret; + Py_INCREF(yf); + if (__Pyx_PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit) && close_on_genexit) { + int err = __Pyx_Coroutine_CloseIter(gen, yf); + Py_DECREF(yf); + __Pyx_Coroutine_Undelegate(gen); + if (err < 0) + return __Pyx_Coroutine_MethodReturn(self, __Pyx_Coroutine_SendEx(gen, NULL, 0)); + goto throw_here; + } + gen->is_running = 1; + if (0 + #ifdef __Pyx_Generator_USED + || __Pyx_Generator_CheckExact(yf) + #endif + #ifdef __Pyx_Coroutine_USED + || __Pyx_Coroutine_Check(yf) + #endif + ) { + ret = __Pyx__Coroutine_Throw(yf, typ, val, tb, args, close_on_genexit); + #ifdef __Pyx_Coroutine_USED + } else if (__Pyx_CoroutineAwait_CheckExact(yf)) { + ret = __Pyx__Coroutine_Throw(((__pyx_CoroutineAwaitObject*)yf)->coroutine, typ, val, tb, args, close_on_genexit); + #endif + } else { + PyObject *meth = __Pyx_PyObject_GetAttrStrNoError(yf, __pyx_n_s_throw); + if (unlikely(!meth)) { + Py_DECREF(yf); + if (unlikely(PyErr_Occurred())) { + gen->is_running = 0; + return NULL; + } + __Pyx_Coroutine_Undelegate(gen); + gen->is_running = 0; + goto throw_here; + } + if (likely(args)) { + ret = __Pyx_PyObject_Call(meth, args, NULL); + } else { + PyObject *cargs[4] = {NULL, typ, val, tb}; + ret = __Pyx_PyObject_FastCall(meth, cargs+1, 3 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET); + } + Py_DECREF(meth); + } + gen->is_running = 0; + Py_DECREF(yf); + if (!ret) { + ret = __Pyx_Coroutine_FinishDelegation(gen); + } + return __Pyx_Coroutine_MethodReturn(self, ret); + } +throw_here: + __Pyx_Raise(typ, val, tb, NULL); + return __Pyx_Coroutine_MethodReturn(self, __Pyx_Coroutine_SendEx(gen, NULL, 0)); +} +static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) { + PyObject *typ; + PyObject *val = NULL; + PyObject *tb = NULL; + if (unlikely(!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb))) + return NULL; + return __Pyx__Coroutine_Throw(self, typ, val, tb, args, 1); +} +static CYTHON_INLINE int __Pyx_Coroutine_traverse_excstate(__Pyx_ExcInfoStruct *exc_state, visitproc visit, void *arg) { +#if PY_VERSION_HEX >= 0x030B00a4 + Py_VISIT(exc_state->exc_value); +#else + Py_VISIT(exc_state->exc_type); + Py_VISIT(exc_state->exc_value); + Py_VISIT(exc_state->exc_traceback); +#endif + return 0; +} +static int __Pyx_Coroutine_traverse(__pyx_CoroutineObject *gen, visitproc visit, void *arg) { + Py_VISIT(gen->closure); + Py_VISIT(gen->classobj); + Py_VISIT(gen->yieldfrom); + return __Pyx_Coroutine_traverse_excstate(&gen->gi_exc_state, visit, arg); +} +static int __Pyx_Coroutine_clear(PyObject *self) { + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; + Py_CLEAR(gen->closure); + Py_CLEAR(gen->classobj); + Py_CLEAR(gen->yieldfrom); + __Pyx_Coroutine_ExceptionClear(&gen->gi_exc_state); +#ifdef __Pyx_AsyncGen_USED + if (__Pyx_AsyncGen_CheckExact(self)) { + Py_CLEAR(((__pyx_PyAsyncGenObject*)gen)->ag_finalizer); + } +#endif + Py_CLEAR(gen->gi_code); + Py_CLEAR(gen->gi_frame); + Py_CLEAR(gen->gi_name); + Py_CLEAR(gen->gi_qualname); + Py_CLEAR(gen->gi_modulename); + return 0; +} +static void __Pyx_Coroutine_dealloc(PyObject *self) { + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; + PyObject_GC_UnTrack(gen); + if (gen->gi_weakreflist != NULL) + PyObject_ClearWeakRefs(self); + if (gen->resume_label >= 0) { + PyObject_GC_Track(self); +#if PY_VERSION_HEX >= 0x030400a1 && CYTHON_USE_TP_FINALIZE + if (unlikely(PyObject_CallFinalizerFromDealloc(self))) +#else + Py_TYPE(gen)->tp_del(self); + if (unlikely(Py_REFCNT(self) > 0)) +#endif + { + return; + } + PyObject_GC_UnTrack(self); + } +#ifdef __Pyx_AsyncGen_USED + if (__Pyx_AsyncGen_CheckExact(self)) { + /* We have to handle this case for asynchronous generators + right here, because this code has to be between UNTRACK + and GC_Del. */ + Py_CLEAR(((__pyx_PyAsyncGenObject*)self)->ag_finalizer); + } +#endif + __Pyx_Coroutine_clear(self); + __Pyx_PyHeapTypeObject_GC_Del(gen); +} +static void __Pyx_Coroutine_del(PyObject *self) { + PyObject *error_type, *error_value, *error_traceback; + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; + __Pyx_PyThreadState_declare + if (gen->resume_label < 0) { + return; + } +#if !CYTHON_USE_TP_FINALIZE + assert(self->ob_refcnt == 0); + __Pyx_SET_REFCNT(self, 1); +#endif + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&error_type, &error_value, &error_traceback); +#ifdef __Pyx_AsyncGen_USED + if (__Pyx_AsyncGen_CheckExact(self)) { + __pyx_PyAsyncGenObject *agen = (__pyx_PyAsyncGenObject*)self; + PyObject *finalizer = agen->ag_finalizer; + if (finalizer && !agen->ag_closed) { + PyObject *res = __Pyx_PyObject_CallOneArg(finalizer, self); + if (unlikely(!res)) { + PyErr_WriteUnraisable(self); + } else { + Py_DECREF(res); + } + __Pyx_ErrRestore(error_type, error_value, error_traceback); + return; + } + } +#endif + if (unlikely(gen->resume_label == 0 && !error_value)) { +#ifdef __Pyx_Coroutine_USED +#ifdef __Pyx_Generator_USED + if (!__Pyx_Generator_CheckExact(self)) +#endif + { + PyObject_GC_UnTrack(self); +#if PY_MAJOR_VERSION >= 3 || defined(PyErr_WarnFormat) + if (unlikely(PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "coroutine '%.50S' was never awaited", gen->gi_qualname) < 0)) + PyErr_WriteUnraisable(self); +#else + {PyObject *msg; + char *cmsg; + #if CYTHON_COMPILING_IN_PYPY + msg = NULL; + cmsg = (char*) "coroutine was never awaited"; + #else + char *cname; + PyObject *qualname; + qualname = gen->gi_qualname; + cname = PyString_AS_STRING(qualname); + msg = PyString_FromFormat("coroutine '%.50s' was never awaited", cname); + if (unlikely(!msg)) { + PyErr_Clear(); + cmsg = (char*) "coroutine was never awaited"; + } else { + cmsg = PyString_AS_STRING(msg); + } + #endif + if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, cmsg, 1) < 0)) + PyErr_WriteUnraisable(self); + Py_XDECREF(msg);} +#endif + PyObject_GC_Track(self); + } +#endif + } else { + PyObject *res = __Pyx_Coroutine_Close(self); + if (unlikely(!res)) { + if (PyErr_Occurred()) + PyErr_WriteUnraisable(self); + } else { + Py_DECREF(res); + } + } + __Pyx_ErrRestore(error_type, error_value, error_traceback); +#if !CYTHON_USE_TP_FINALIZE + assert(Py_REFCNT(self) > 0); + if (likely(--self->ob_refcnt == 0)) { + return; + } + { + Py_ssize_t refcnt = Py_REFCNT(self); + _Py_NewReference(self); + __Pyx_SET_REFCNT(self, refcnt); + } +#if CYTHON_COMPILING_IN_CPYTHON + assert(PyType_IS_GC(Py_TYPE(self)) && + _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED); + _Py_DEC_REFTOTAL; +#endif +#ifdef COUNT_ALLOCS + --Py_TYPE(self)->tp_frees; + --Py_TYPE(self)->tp_allocs; +#endif +#endif +} +static PyObject * +__Pyx_Coroutine_get_name(__pyx_CoroutineObject *self, void *context) +{ + PyObject *name = self->gi_name; + CYTHON_UNUSED_VAR(context); + if (unlikely(!name)) name = Py_None; + Py_INCREF(name); + return name; +} +static int +__Pyx_Coroutine_set_name(__pyx_CoroutineObject *self, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) +#else + if (unlikely(value == NULL || !PyString_Check(value))) +#endif + { + PyErr_SetString(PyExc_TypeError, + "__name__ must be set to a string object"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(self->gi_name, value); + return 0; +} +static PyObject * +__Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self, void *context) +{ + PyObject *name = self->gi_qualname; + CYTHON_UNUSED_VAR(context); + if (unlikely(!name)) name = Py_None; + Py_INCREF(name); + return name; +} +static int +__Pyx_Coroutine_set_qualname(__pyx_CoroutineObject *self, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) +#else + if (unlikely(value == NULL || !PyString_Check(value))) +#endif + { + PyErr_SetString(PyExc_TypeError, + "__qualname__ must be set to a string object"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(self->gi_qualname, value); + return 0; +} +static PyObject * +__Pyx_Coroutine_get_frame(__pyx_CoroutineObject *self, void *context) +{ + PyObject *frame = self->gi_frame; + CYTHON_UNUSED_VAR(context); + if (!frame) { + if (unlikely(!self->gi_code)) { + Py_RETURN_NONE; + } + frame = (PyObject *) PyFrame_New( + PyThreadState_Get(), /*PyThreadState *tstate,*/ + (PyCodeObject*) self->gi_code, /*PyCodeObject *code,*/ + __pyx_d, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (unlikely(!frame)) + return NULL; + self->gi_frame = frame; + } + Py_INCREF(frame); + return frame; +} +static __pyx_CoroutineObject *__Pyx__Coroutine_New( + PyTypeObject* type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, + PyObject *name, PyObject *qualname, PyObject *module_name) { + __pyx_CoroutineObject *gen = PyObject_GC_New(__pyx_CoroutineObject, type); + if (unlikely(!gen)) + return NULL; + return __Pyx__Coroutine_NewInit(gen, body, code, closure, name, qualname, module_name); +} +static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit( + __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, + PyObject *name, PyObject *qualname, PyObject *module_name) { + gen->body = body; + gen->closure = closure; + Py_XINCREF(closure); + gen->is_running = 0; + gen->resume_label = 0; + gen->classobj = NULL; + gen->yieldfrom = NULL; + #if PY_VERSION_HEX >= 0x030B00a4 + gen->gi_exc_state.exc_value = NULL; + #else + gen->gi_exc_state.exc_type = NULL; + gen->gi_exc_state.exc_value = NULL; + gen->gi_exc_state.exc_traceback = NULL; + #endif +#if CYTHON_USE_EXC_INFO_STACK + gen->gi_exc_state.previous_item = NULL; +#endif + gen->gi_weakreflist = NULL; + Py_XINCREF(qualname); + gen->gi_qualname = qualname; + Py_XINCREF(name); + gen->gi_name = name; + Py_XINCREF(module_name); + gen->gi_modulename = module_name; + Py_XINCREF(code); + gen->gi_code = code; + gen->gi_frame = NULL; + PyObject_GC_Track(gen); + return gen; +} + +/* PyObject_GenericGetAttrNoDict */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) { + __Pyx_TypeName type_name = __Pyx_PyType_GetName(tp); + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%U'", + type_name, attr_name); +#else + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%.400s'", + type_name, PyString_AS_STRING(attr_name)); +#endif + __Pyx_DECREF_TypeName(type_name); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) { + PyObject *descr; + PyTypeObject *tp = Py_TYPE(obj); + if (unlikely(!PyString_Check(attr_name))) { + return PyObject_GenericGetAttr(obj, attr_name); + } + assert(!tp->tp_dictoffset); + descr = _PyType_Lookup(tp, attr_name); + if (unlikely(!descr)) { + return __Pyx_RaiseGenericGetAttributeError(tp, attr_name); + } + Py_INCREF(descr); + #if PY_MAJOR_VERSION < 3 + if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS))) + #endif + { + descrgetfunc f = Py_TYPE(descr)->tp_descr_get; + if (unlikely(f)) { + PyObject *res = f(descr, obj, (PyObject *)tp); + Py_DECREF(descr); + return res; + } + } + return descr; +} +#endif + +/* PatchModuleWithCoroutine */ +static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code) { +#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + int result; + PyObject *globals, *result_obj; + globals = PyDict_New(); if (unlikely(!globals)) goto ignore; + result = PyDict_SetItemString(globals, "_cython_coroutine_type", + #ifdef __Pyx_Coroutine_USED + (PyObject*)__pyx_CoroutineType); + #else + Py_None); + #endif + if (unlikely(result < 0)) goto ignore; + result = PyDict_SetItemString(globals, "_cython_generator_type", + #ifdef __Pyx_Generator_USED + (PyObject*)__pyx_GeneratorType); + #else + Py_None); + #endif + if (unlikely(result < 0)) goto ignore; + if (unlikely(PyDict_SetItemString(globals, "_module", module) < 0)) goto ignore; + if (unlikely(PyDict_SetItemString(globals, "__builtins__", __pyx_b) < 0)) goto ignore; + result_obj = PyRun_String(py_code, Py_file_input, globals, globals); + if (unlikely(!result_obj)) goto ignore; + Py_DECREF(result_obj); + Py_DECREF(globals); + return module; +ignore: + Py_XDECREF(globals); + PyErr_WriteUnraisable(module); + if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, "Cython module failed to patch module with custom type", 1) < 0)) { + Py_DECREF(module); + module = NULL; + } +#else + py_code++; +#endif + return module; +} + +/* PatchGeneratorABC */ +#ifndef CYTHON_REGISTER_ABCS +#define CYTHON_REGISTER_ABCS 1 +#endif +#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) +static PyObject* __Pyx_patch_abc_module(PyObject *module); +static PyObject* __Pyx_patch_abc_module(PyObject *module) { + module = __Pyx_Coroutine_patch_module( + module, "" +"if _cython_generator_type is not None:\n" +" try: Generator = _module.Generator\n" +" except AttributeError: pass\n" +" else: Generator.register(_cython_generator_type)\n" +"if _cython_coroutine_type is not None:\n" +" try: Coroutine = _module.Coroutine\n" +" except AttributeError: pass\n" +" else: Coroutine.register(_cython_coroutine_type)\n" + ); + return module; +} +#endif +static int __Pyx_patch_abc(void) { +#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + static int abc_patched = 0; + if (CYTHON_REGISTER_ABCS && !abc_patched) { + PyObject *module; + module = PyImport_ImportModule((PY_MAJOR_VERSION >= 3) ? "collections.abc" : "collections"); + if (unlikely(!module)) { + PyErr_WriteUnraisable(NULL); + if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, + ((PY_MAJOR_VERSION >= 3) ? + "Cython module failed to register with collections.abc module" : + "Cython module failed to register with collections module"), 1) < 0)) { + return -1; + } + } else { + module = __Pyx_patch_abc_module(module); + abc_patched = 1; + if (unlikely(!module)) + return -1; + Py_DECREF(module); + } + module = PyImport_ImportModule("backports_abc"); + if (module) { + module = __Pyx_patch_abc_module(module); + Py_XDECREF(module); + } + if (!module) { + PyErr_Clear(); + } + } +#else + if ((0)) __Pyx_Coroutine_patch_module(NULL, NULL); +#endif + return 0; +} + +/* Coroutine */ +static void __Pyx_CoroutineAwait_dealloc(PyObject *self) { + PyObject_GC_UnTrack(self); + Py_CLEAR(((__pyx_CoroutineAwaitObject*)self)->coroutine); + __Pyx_PyHeapTypeObject_GC_Del(self); +} +static int __Pyx_CoroutineAwait_traverse(__pyx_CoroutineAwaitObject *self, visitproc visit, void *arg) { + Py_VISIT(self->coroutine); + return 0; +} +static int __Pyx_CoroutineAwait_clear(__pyx_CoroutineAwaitObject *self) { + Py_CLEAR(self->coroutine); + return 0; +} +static PyObject *__Pyx_CoroutineAwait_Next(__pyx_CoroutineAwaitObject *self) { + return __Pyx_Generator_Next(self->coroutine); +} +static PyObject *__Pyx_CoroutineAwait_Send(__pyx_CoroutineAwaitObject *self, PyObject *value) { + return __Pyx_Coroutine_Send(self->coroutine, value); +} +static PyObject *__Pyx_CoroutineAwait_Throw(__pyx_CoroutineAwaitObject *self, PyObject *args) { + return __Pyx_Coroutine_Throw(self->coroutine, args); +} +static PyObject *__Pyx_CoroutineAwait_Close(__pyx_CoroutineAwaitObject *self, PyObject *arg) { + CYTHON_UNUSED_VAR(arg); + return __Pyx_Coroutine_Close(self->coroutine); +} +static PyObject *__Pyx_CoroutineAwait_self(PyObject *self) { + Py_INCREF(self); + return self; +} +#if !CYTHON_COMPILING_IN_PYPY +static PyObject *__Pyx_CoroutineAwait_no_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { + CYTHON_UNUSED_VAR(type); + CYTHON_UNUSED_VAR(args); + CYTHON_UNUSED_VAR(kwargs); + PyErr_SetString(PyExc_TypeError, "cannot instantiate type, use 'await coroutine' instead"); + return NULL; +} +#endif +static PyObject *__Pyx_CoroutineAwait_reduce_ex(__pyx_CoroutineAwaitObject *self, PyObject *arg) { + CYTHON_UNUSED_VAR(arg); + PyErr_Format(PyExc_TypeError, "cannot pickle '%.200s' object", + Py_TYPE(self)->tp_name); + return NULL; +} +static PyMethodDef __pyx_CoroutineAwait_methods[] = { + {"send", (PyCFunction) __Pyx_CoroutineAwait_Send, METH_O, + (char*) PyDoc_STR("send(arg) -> send 'arg' into coroutine,\nreturn next yielded value or raise StopIteration.")}, + {"throw", (PyCFunction) __Pyx_CoroutineAwait_Throw, METH_VARARGS, + (char*) PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in coroutine,\nreturn next yielded value or raise StopIteration.")}, + {"close", (PyCFunction) __Pyx_CoroutineAwait_Close, METH_NOARGS, + (char*) PyDoc_STR("close() -> raise GeneratorExit inside coroutine.")}, + {"__reduce_ex__", (PyCFunction) __Pyx_CoroutineAwait_reduce_ex, METH_O, 0}, + {"__reduce__", (PyCFunction) __Pyx_CoroutineAwait_reduce_ex, METH_NOARGS, 0}, + {0, 0, 0, 0} +}; +#if CYTHON_USE_TYPE_SPECS +static PyType_Slot __pyx_CoroutineAwaitType_slots[] = { + {Py_tp_dealloc, (void *)__Pyx_CoroutineAwait_dealloc}, + {Py_tp_traverse, (void *)__Pyx_CoroutineAwait_traverse}, + {Py_tp_clear, (void *)__Pyx_CoroutineAwait_clear}, +#if !CYTHON_COMPILING_IN_PYPY + {Py_tp_new, (void *)__Pyx_CoroutineAwait_no_new}, +#endif + {Py_tp_methods, (void *)__pyx_CoroutineAwait_methods}, + {Py_tp_iter, (void *)__Pyx_CoroutineAwait_self}, + {Py_tp_iternext, (void *)__Pyx_CoroutineAwait_Next}, + {0, 0}, +}; +static PyType_Spec __pyx_CoroutineAwaitType_spec = { + __PYX_TYPE_MODULE_PREFIX "coroutine_wrapper", + sizeof(__pyx_CoroutineAwaitObject), + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, + __pyx_CoroutineAwaitType_slots +}; +#else +static PyTypeObject __pyx_CoroutineAwaitType_type = { + PyVarObject_HEAD_INIT(0, 0) + __PYX_TYPE_MODULE_PREFIX "coroutine_wrapper", + sizeof(__pyx_CoroutineAwaitObject), + 0, + (destructor) __Pyx_CoroutineAwait_dealloc, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, + PyDoc_STR("A wrapper object implementing __await__ for coroutines."), + (traverseproc) __Pyx_CoroutineAwait_traverse, + (inquiry) __Pyx_CoroutineAwait_clear, + 0, + 0, + __Pyx_CoroutineAwait_self, + (iternextfunc) __Pyx_CoroutineAwait_Next, + __pyx_CoroutineAwait_methods, + 0 , + 0 , + 0, + 0, + 0, + 0, + 0, + 0, + 0, +#if !CYTHON_COMPILING_IN_PYPY + __Pyx_CoroutineAwait_no_new, +#else + 0, +#endif + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +#if PY_VERSION_HEX >= 0x030400a1 + 0, +#endif +#if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) + 0, +#endif +#if __PYX_NEED_TP_PRINT_SLOT + 0, +#endif +#if PY_VERSION_HEX >= 0x030C0000 + 0, +#endif +#if PY_VERSION_HEX >= 0x030d00A4 + 0, +#endif +#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 + 0, +#endif +}; +#endif +#if PY_VERSION_HEX < 0x030500B1 || defined(__Pyx_IterableCoroutine_USED) || CYTHON_USE_ASYNC_SLOTS +static CYTHON_INLINE PyObject *__Pyx__Coroutine_await(PyObject *coroutine) { + __pyx_CoroutineAwaitObject *await = PyObject_GC_New(__pyx_CoroutineAwaitObject, __pyx_CoroutineAwaitType); + if (unlikely(!await)) return NULL; + Py_INCREF(coroutine); + await->coroutine = coroutine; + PyObject_GC_Track(await); + return (PyObject*)await; +} +#endif +#if PY_VERSION_HEX < 0x030500B1 +static PyObject *__Pyx_Coroutine_await_method(PyObject *coroutine, PyObject *arg) { + CYTHON_UNUSED_VAR(arg); + return __Pyx__Coroutine_await(coroutine); +} +#endif +#if defined(__Pyx_IterableCoroutine_USED) || CYTHON_USE_ASYNC_SLOTS +static PyObject *__Pyx_Coroutine_await(PyObject *coroutine) { + if (unlikely(!coroutine || !__Pyx_Coroutine_Check(coroutine))) { + PyErr_SetString(PyExc_TypeError, "invalid input, expected coroutine"); + return NULL; + } + return __Pyx__Coroutine_await(coroutine); +} +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 && PY_VERSION_HEX < 0x030500B1 +static PyObject *__Pyx_Coroutine_compare(PyObject *obj, PyObject *other, int op) { + PyObject* result; + switch (op) { + case Py_EQ: result = (other == obj) ? Py_True : Py_False; break; + case Py_NE: result = (other != obj) ? Py_True : Py_False; break; + default: + result = Py_NotImplemented; + } + Py_INCREF(result); + return result; +} +#endif +static PyMethodDef __pyx_Coroutine_methods[] = { + {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O, + (char*) PyDoc_STR("send(arg) -> send 'arg' into coroutine,\nreturn next iterated value or raise StopIteration.")}, + {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS, + (char*) PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in coroutine,\nreturn next iterated value or raise StopIteration.")}, + {"close", (PyCFunction) __Pyx_Coroutine_Close_Method, METH_NOARGS, + (char*) PyDoc_STR("close() -> raise GeneratorExit inside coroutine.")}, +#if PY_VERSION_HEX < 0x030500B1 + {"__await__", (PyCFunction) __Pyx_Coroutine_await_method, METH_NOARGS, + (char*) PyDoc_STR("__await__() -> return an iterator to be used in await expression.")}, +#endif + {0, 0, 0, 0} +}; +static PyMemberDef __pyx_Coroutine_memberlist[] = { + {(char *) "cr_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL}, + {(char*) "cr_await", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY, + (char*) PyDoc_STR("object being awaited, or None")}, + {(char*) "cr_code", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_code), READONLY, NULL}, + {(char *) "__module__", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_modulename), 0, 0}, +#if CYTHON_USE_TYPE_SPECS + {(char *) "__weaklistoffset__", T_PYSSIZET, offsetof(__pyx_CoroutineObject, gi_weakreflist), READONLY, 0}, +#endif + {0, 0, 0, 0, 0} +}; +static PyGetSetDef __pyx_Coroutine_getsets[] = { + {(char *) "__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name, + (char*) PyDoc_STR("name of the coroutine"), 0}, + {(char *) "__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname, + (char*) PyDoc_STR("qualified name of the coroutine"), 0}, + {(char *) "cr_frame", (getter)__Pyx_Coroutine_get_frame, NULL, + (char*) PyDoc_STR("Frame of the coroutine"), 0}, + {0, 0, 0, 0, 0} +}; +#if CYTHON_USE_TYPE_SPECS +static PyType_Slot __pyx_CoroutineType_slots[] = { + {Py_tp_dealloc, (void *)__Pyx_Coroutine_dealloc}, + {Py_am_await, (void *)&__Pyx_Coroutine_await}, + {Py_tp_traverse, (void *)__Pyx_Coroutine_traverse}, + {Py_tp_methods, (void *)__pyx_Coroutine_methods}, + {Py_tp_members, (void *)__pyx_Coroutine_memberlist}, + {Py_tp_getset, (void *)__pyx_Coroutine_getsets}, + {Py_tp_getattro, (void *) __Pyx_PyObject_GenericGetAttrNoDict}, +#if CYTHON_USE_TP_FINALIZE + {Py_tp_finalize, (void *)__Pyx_Coroutine_del}, +#endif + {0, 0}, +}; +static PyType_Spec __pyx_CoroutineType_spec = { + __PYX_TYPE_MODULE_PREFIX "coroutine", + sizeof(__pyx_CoroutineObject), + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE, + __pyx_CoroutineType_slots +}; +#else +#if CYTHON_USE_ASYNC_SLOTS +static __Pyx_PyAsyncMethodsStruct __pyx_Coroutine_as_async = { + __Pyx_Coroutine_await, + 0, + 0, +#if PY_VERSION_HEX >= 0x030A00A3 + 0, +#endif +}; +#endif +static PyTypeObject __pyx_CoroutineType_type = { + PyVarObject_HEAD_INIT(0, 0) + __PYX_TYPE_MODULE_PREFIX "coroutine", + sizeof(__pyx_CoroutineObject), + 0, + (destructor) __Pyx_Coroutine_dealloc, + 0, + 0, + 0, +#if CYTHON_USE_ASYNC_SLOTS + &__pyx_Coroutine_as_async, +#else + 0, +#endif + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE, + 0, + (traverseproc) __Pyx_Coroutine_traverse, + 0, +#if CYTHON_USE_ASYNC_SLOTS && CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 && PY_VERSION_HEX < 0x030500B1 + __Pyx_Coroutine_compare, +#else + 0, +#endif + offsetof(__pyx_CoroutineObject, gi_weakreflist), + 0, + 0, + __pyx_Coroutine_methods, + __pyx_Coroutine_memberlist, + __pyx_Coroutine_getsets, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +#if CYTHON_USE_TP_FINALIZE + 0, +#else + __Pyx_Coroutine_del, +#endif + 0, +#if CYTHON_USE_TP_FINALIZE + __Pyx_Coroutine_del, +#elif PY_VERSION_HEX >= 0x030400a1 + 0, +#endif +#if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) + 0, +#endif +#if __PYX_NEED_TP_PRINT_SLOT + 0, +#endif +#if PY_VERSION_HEX >= 0x030C0000 + 0, +#endif +#if PY_VERSION_HEX >= 0x030d00A4 + 0, +#endif +#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 + 0, +#endif +}; +#endif +static int __pyx_Coroutine_init(PyObject *module) { + CYTHON_MAYBE_UNUSED_VAR(module); +#if CYTHON_USE_TYPE_SPECS + __pyx_CoroutineType = __Pyx_FetchCommonTypeFromSpec(module, &__pyx_CoroutineType_spec, NULL); +#else + __pyx_CoroutineType_type.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; + __pyx_CoroutineType = __Pyx_FetchCommonType(&__pyx_CoroutineType_type); +#endif + if (unlikely(!__pyx_CoroutineType)) + return -1; +#ifdef __Pyx_IterableCoroutine_USED + if (unlikely(__pyx_IterableCoroutine_init(module) == -1)) + return -1; +#endif +#if CYTHON_USE_TYPE_SPECS + __pyx_CoroutineAwaitType = __Pyx_FetchCommonTypeFromSpec(module, &__pyx_CoroutineAwaitType_spec, NULL); +#else + __pyx_CoroutineAwaitType = __Pyx_FetchCommonType(&__pyx_CoroutineAwaitType_type); +#endif + if (unlikely(!__pyx_CoroutineAwaitType)) + return -1; + return 0; +} + +/* GetAwaitIter */ +static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAwaitableIter(PyObject *o) { +#ifdef __Pyx_Coroutine_USED + if (__Pyx_Coroutine_Check(o)) { + return __Pyx_NewRef(o); + } +#endif + return __Pyx__Coroutine_GetAwaitableIter(o); +} +static void __Pyx_Coroutine_AwaitableIterError(PyObject *source) { +#if PY_VERSION_HEX >= 0x030600B3 && PY_VERSION_HEX < 0x030d0000 || defined(_PyErr_FormatFromCause) + __Pyx_TypeName source_type_name = __Pyx_PyType_GetName(Py_TYPE(source)); + _PyErr_FormatFromCause(PyExc_TypeError, + "'async for' received an invalid object from __anext__: " __Pyx_FMT_TYPENAME, source_type_name); + __Pyx_DECREF_TypeName(source_type_name); +#elif PY_MAJOR_VERSION >= 3 + PyObject *exc, *val, *val2, *tb; + __Pyx_TypeName source_type_name = __Pyx_PyType_GetName(Py_TYPE(source)); + assert(PyErr_Occurred()); + PyErr_Fetch(&exc, &val, &tb); + PyErr_NormalizeException(&exc, &val, &tb); + if (tb != NULL) { + PyException_SetTraceback(val, tb); + Py_DECREF(tb); + } + Py_DECREF(exc); + assert(!PyErr_Occurred()); + PyErr_Format(PyExc_TypeError, + "'async for' received an invalid object from __anext__: " __Pyx_FMT_TYPENAME, source_type_name); + __Pyx_DECREF_TypeName(source_type_name); + PyErr_Fetch(&exc, &val2, &tb); + PyErr_NormalizeException(&exc, &val2, &tb); + Py_INCREF(val); + PyException_SetCause(val2, val); + PyException_SetContext(val2, val); + PyErr_Restore(exc, val2, tb); +#else + CYTHON_UNUSED_VAR(source); +#endif +} +static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *obj) { + PyObject *res; +#if CYTHON_USE_ASYNC_SLOTS + __Pyx_PyAsyncMethodsStruct* am = __Pyx_PyType_AsAsync(obj); + if (likely(am && am->am_await)) { + res = (*am->am_await)(obj); + } else +#endif +#if PY_VERSION_HEX >= 0x030500B2 || defined(PyCoro_CheckExact) + if (PyCoro_CheckExact(obj)) { + return __Pyx_NewRef(obj); + } else +#endif +#if CYTHON_COMPILING_IN_CPYTHON && defined(CO_ITERABLE_COROUTINE) +#if PY_VERSION_HEX >= 0x030C00A6 + if (PyGen_CheckExact(obj) && (PyGen_GetCode((PyGenObject*)obj)->co_flags & CO_ITERABLE_COROUTINE)) { +#else + if (PyGen_CheckExact(obj) && ((PyGenObject*)obj)->gi_code && ((PyCodeObject *)((PyGenObject*)obj)->gi_code)->co_flags & CO_ITERABLE_COROUTINE) { +#endif + return __Pyx_NewRef(obj); + } else +#endif + { + PyObject *method = NULL; + int is_method = __Pyx_PyObject_GetMethod(obj, __pyx_n_s_await, &method); + if (likely(is_method)) { + res = __Pyx_PyObject_CallOneArg(method, obj); + } else if (likely(method)) { + res = __Pyx_PyObject_CallNoArg(method); + } else + goto slot_error; + Py_DECREF(method); + } + if (unlikely(!res)) { + __Pyx_Coroutine_AwaitableIterError(obj); + goto bad; + } + if (unlikely(!PyIter_Check(res))) { + __Pyx_TypeName res_type_name = __Pyx_PyType_GetName(Py_TYPE(res)); + PyErr_Format(PyExc_TypeError, + "__await__() returned non-iterator of type '" __Pyx_FMT_TYPENAME "'", res_type_name); + __Pyx_DECREF_TypeName(res_type_name); + Py_CLEAR(res); + } else { + int is_coroutine = 0; + #ifdef __Pyx_Coroutine_USED + is_coroutine |= __Pyx_Coroutine_Check(res); + #endif + #if PY_VERSION_HEX >= 0x030500B2 || defined(PyCoro_CheckExact) + is_coroutine |= PyCoro_CheckExact(res); + #endif + if (unlikely(is_coroutine)) { + /* __await__ must return an *iterator*, not + a coroutine or another awaitable (see PEP 492) */ + PyErr_SetString(PyExc_TypeError, + "__await__() returned a coroutine"); + Py_CLEAR(res); + } + } + return res; +slot_error: + { + __Pyx_TypeName obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj)); + PyErr_Format(PyExc_TypeError, + "object " __Pyx_FMT_TYPENAME " can't be used in 'await' expression", obj_type_name); + __Pyx_DECREF_TypeName(obj_type_name); + } +bad: + return NULL; +} + +/* CoroutineYieldFrom */ + static PyObject* __Pyx__Coroutine_Yield_From_Generic(__pyx_CoroutineObject *gen, PyObject *source) { + PyObject *retval; + PyObject *source_gen = __Pyx__Coroutine_GetAwaitableIter(source); + if (unlikely(!source_gen)) { + return NULL; + } + if (__Pyx_Coroutine_Check(source_gen)) { + retval = __Pyx_Generator_Next(source_gen); + } else { + retval = __Pyx_PyObject_GetIterNextFunc(source_gen)(source_gen); + } + if (retval) { + gen->yieldfrom = source_gen; + return retval; + } + Py_DECREF(source_gen); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_Coroutine_Yield_From(__pyx_CoroutineObject *gen, PyObject *source) { + PyObject *retval; + if (__Pyx_Coroutine_Check(source)) { + if (unlikely(((__pyx_CoroutineObject*)source)->yieldfrom)) { + PyErr_SetString( + PyExc_RuntimeError, + "coroutine is being awaited already"); + return NULL; + } + retval = __Pyx_Generator_Next(source); +#ifdef __Pyx_AsyncGen_USED + } else if (__pyx_PyAsyncGenASend_CheckExact(source)) { + retval = __Pyx_async_gen_asend_iternext(source); +#endif + } else { + return __Pyx__Coroutine_Yield_From_Generic(gen, source); + } + if (retval) { + Py_INCREF(source); + gen->yieldfrom = source; + } + return retval; +} + +/* ReturnWithStopIteration */ + static void __Pyx__ReturnWithStopIteration(PyObject* value) { + PyObject *exc, *args; +#if CYTHON_COMPILING_IN_CPYTHON + __Pyx_PyThreadState_declare + if (PY_VERSION_HEX >= 0x030C00A6 + || unlikely(PyTuple_Check(value) || PyExceptionInstance_Check(value))) { + args = PyTuple_New(1); + if (unlikely(!args)) return; + Py_INCREF(value); + PyTuple_SET_ITEM(args, 0, value); + exc = PyType_Type.tp_call(PyExc_StopIteration, args, NULL); + Py_DECREF(args); + if (!exc) return; + } else { + Py_INCREF(value); + exc = value; + } + #if CYTHON_FAST_THREAD_STATE + __Pyx_PyThreadState_assign + #if CYTHON_USE_EXC_INFO_STACK + if (!__pyx_tstate->exc_info->exc_value) + #else + if (!__pyx_tstate->exc_type) + #endif + { + Py_INCREF(PyExc_StopIteration); + __Pyx_ErrRestore(PyExc_StopIteration, exc, NULL); + return; + } + #endif +#else + args = PyTuple_Pack(1, value); + if (unlikely(!args)) return; + exc = PyObject_Call(PyExc_StopIteration, args, NULL); + Py_DECREF(args); + if (unlikely(!exc)) return; +#endif + PyErr_SetObject(PyExc_StopIteration, exc); + Py_DECREF(exc); +} + +/* PyIntBinop */ + #if !CYTHON_COMPILING_IN_PYPY +static PyObject* __Pyx_PyInt_AddObjC(PyObject *op1, PyObject *op2, long intval, int inplace, int zerodivision_check) { + CYTHON_MAYBE_UNUSED_VAR(intval); + CYTHON_MAYBE_UNUSED_VAR(inplace); + CYTHON_UNUSED_VAR(zerodivision_check); + #if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(op1))) { + const long b = intval; + long x; + long a = PyInt_AS_LONG(op1); + + x = (long)((unsigned long)a + (unsigned long)b); + if (likely((x^a) >= 0 || (x^b) >= 0)) + return PyInt_FromLong(x); + return PyLong_Type.tp_as_number->nb_add(op1, op2); + } + #endif + #if CYTHON_USE_PYLONG_INTERNALS + if (likely(PyLong_CheckExact(op1))) { + const long b = intval; + long a, x; +#ifdef HAVE_LONG_LONG + const PY_LONG_LONG llb = intval; + PY_LONG_LONG lla, llx; +#endif + if (unlikely(__Pyx_PyLong_IsZero(op1))) { + return __Pyx_NewRef(op2); + } + if (likely(__Pyx_PyLong_IsCompact(op1))) { + a = __Pyx_PyLong_CompactValue(op1); + } else { + const digit* digits = __Pyx_PyLong_Digits(op1); + const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount(op1); + switch (size) { + case -2: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + a = -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + #ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; + #endif + } + CYTHON_FALLTHROUGH; + case 2: + if (8 * sizeof(long) - 1 > 2 * PyLong_SHIFT) { + a = (long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + #ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 2 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; + #endif + } + CYTHON_FALLTHROUGH; + case -3: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + a = -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + #ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; + #endif + } + CYTHON_FALLTHROUGH; + case 3: + if (8 * sizeof(long) - 1 > 3 * PyLong_SHIFT) { + a = (long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + #ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 3 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((((unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; + #endif + } + CYTHON_FALLTHROUGH; + case -4: + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + a = -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + #ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + lla = -(PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; + #endif + } + CYTHON_FALLTHROUGH; + case 4: + if (8 * sizeof(long) - 1 > 4 * PyLong_SHIFT) { + a = (long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0])); + break; + #ifdef HAVE_LONG_LONG + } else if (8 * sizeof(PY_LONG_LONG) - 1 > 4 * PyLong_SHIFT) { + lla = (PY_LONG_LONG) (((((((((unsigned PY_LONG_LONG)digits[3]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[2]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[1]) << PyLong_SHIFT) | (unsigned PY_LONG_LONG)digits[0])); + goto long_long; + #endif + } + CYTHON_FALLTHROUGH; + default: return PyLong_Type.tp_as_number->nb_add(op1, op2); + } + } + x = a + b; + return PyLong_FromLong(x); +#ifdef HAVE_LONG_LONG + long_long: + llx = lla + llb; + return PyLong_FromLongLong(llx); +#endif + + + } + #endif + if (PyFloat_CheckExact(op1)) { + const long b = intval; +#if CYTHON_COMPILING_IN_LIMITED_API + double a = __pyx_PyFloat_AsDouble(op1); +#else + double a = PyFloat_AS_DOUBLE(op1); +#endif + double result; + + PyFPE_START_PROTECT("add", return NULL) + result = ((double)a) + (double)b; + PyFPE_END_PROTECT(result) + return PyFloat_FromDouble(result); + } + return (inplace ? PyNumber_InPlaceAdd : PyNumber_Add)(op1, op2); +} +#endif + +/* GetException */ + #if CYTHON_FAST_THREAD_STATE +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) +#endif +{ + PyObject *local_type = NULL, *local_value, *local_tb = NULL; +#if CYTHON_FAST_THREAD_STATE + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if PY_VERSION_HEX >= 0x030C00A6 + local_value = tstate->current_exception; + tstate->current_exception = 0; + if (likely(local_value)) { + local_type = (PyObject*) Py_TYPE(local_value); + Py_INCREF(local_type); + local_tb = PyException_GetTraceback(local_value); + } + #else + local_type = tstate->curexc_type; + local_value = tstate->curexc_value; + local_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; + #endif +#else + PyErr_Fetch(&local_type, &local_value, &local_tb); +#endif + PyErr_NormalizeException(&local_type, &local_value, &local_tb); +#if CYTHON_FAST_THREAD_STATE && PY_VERSION_HEX >= 0x030C00A6 + if (unlikely(tstate->current_exception)) +#elif CYTHON_FAST_THREAD_STATE + if (unlikely(tstate->curexc_type)) +#else + if (unlikely(PyErr_Occurred())) +#endif + goto bad; + #if PY_MAJOR_VERSION >= 3 + if (local_tb) { + if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) + goto bad; + } + #endif + Py_XINCREF(local_tb); + Py_XINCREF(local_type); + Py_XINCREF(local_value); + *type = local_type; + *value = local_value; + *tb = local_tb; +#if CYTHON_FAST_THREAD_STATE + #if CYTHON_USE_EXC_INFO_STACK + { + _PyErr_StackItem *exc_info = tstate->exc_info; + #if PY_VERSION_HEX >= 0x030B00a4 + tmp_value = exc_info->exc_value; + exc_info->exc_value = local_value; + tmp_type = NULL; + tmp_tb = NULL; + Py_XDECREF(local_type); + Py_XDECREF(local_tb); + #else + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = local_type; + exc_info->exc_value = local_value; + exc_info->exc_traceback = local_tb; + #endif + } + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = local_type; + tstate->exc_value = local_value; + tstate->exc_traceback = local_tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#else + PyErr_SetExcInfo(local_type, local_value, local_tb); +#endif + return 0; +bad: + *type = 0; + *value = 0; + *tb = 0; + Py_XDECREF(local_type); + Py_XDECREF(local_value); + Py_XDECREF(local_tb); + return -1; +} + +/* RaiseUnboundLocalError */ + static CYTHON_INLINE void __Pyx_RaiseUnboundLocalError(const char *varname) { + PyErr_Format(PyExc_UnboundLocalError, "local variable '%s' referenced before assignment", varname); +} + +/* pep479 */ + static void __Pyx_Generator_Replace_StopIteration(int in_async_gen) { + PyObject *exc, *val, *tb, *cur_exc; + __Pyx_PyThreadState_declare + #ifdef __Pyx_StopAsyncIteration_USED + int is_async_stopiteration = 0; + #endif + CYTHON_MAYBE_UNUSED_VAR(in_async_gen); + cur_exc = PyErr_Occurred(); + if (likely(!__Pyx_PyErr_GivenExceptionMatches(cur_exc, PyExc_StopIteration))) { + #ifdef __Pyx_StopAsyncIteration_USED + if (in_async_gen && unlikely(__Pyx_PyErr_GivenExceptionMatches(cur_exc, __Pyx_PyExc_StopAsyncIteration))) { + is_async_stopiteration = 1; + } else + #endif + return; + } + __Pyx_PyThreadState_assign + __Pyx_GetException(&exc, &val, &tb); + Py_XDECREF(exc); + Py_XDECREF(val); + Py_XDECREF(tb); + PyErr_SetString(PyExc_RuntimeError, + #ifdef __Pyx_StopAsyncIteration_USED + is_async_stopiteration ? "async generator raised StopAsyncIteration" : + in_async_gen ? "async generator raised StopIteration" : + #endif + "generator raised StopIteration"); +} + +/* PyObjectCallMethod0 */ + static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) { + PyObject *method = NULL, *result = NULL; + int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); + if (likely(is_method)) { + result = __Pyx_PyObject_CallOneArg(method, obj); + Py_DECREF(method); + return result; + } + if (unlikely(!method)) goto bad; + result = __Pyx_PyObject_CallNoArg(method); + Py_DECREF(method); +bad: + return result; +} + +/* ValidateBasesTuple */ + #if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS +static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases) { + Py_ssize_t i, n; +#if CYTHON_ASSUME_SAFE_MACROS + n = PyTuple_GET_SIZE(bases); +#else + n = PyTuple_Size(bases); + if (n < 0) return -1; +#endif + for (i = 1; i < n; i++) + { +#if CYTHON_AVOID_BORROWED_REFS + PyObject *b0 = PySequence_GetItem(bases, i); + if (!b0) return -1; +#elif CYTHON_ASSUME_SAFE_MACROS + PyObject *b0 = PyTuple_GET_ITEM(bases, i); +#else + PyObject *b0 = PyTuple_GetItem(bases, i); + if (!b0) return -1; +#endif + PyTypeObject *b; +#if PY_MAJOR_VERSION < 3 + if (PyClass_Check(b0)) + { + PyErr_Format(PyExc_TypeError, "base class '%.200s' is an old-style class", + PyString_AS_STRING(((PyClassObject*)b0)->cl_name)); +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + return -1; + } +#endif + b = (PyTypeObject*) b0; + if (!__Pyx_PyType_HasFeature(b, Py_TPFLAGS_HEAPTYPE)) + { + __Pyx_TypeName b_name = __Pyx_PyType_GetName(b); + PyErr_Format(PyExc_TypeError, + "base class '" __Pyx_FMT_TYPENAME "' is not a heap type", b_name); + __Pyx_DECREF_TypeName(b_name); +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + return -1; + } + if (dictoffset == 0) + { + Py_ssize_t b_dictoffset = 0; +#if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY + b_dictoffset = b->tp_dictoffset; +#else + PyObject *py_b_dictoffset = PyObject_GetAttrString((PyObject*)b, "__dictoffset__"); + if (!py_b_dictoffset) goto dictoffset_return; + b_dictoffset = PyLong_AsSsize_t(py_b_dictoffset); + Py_DECREF(py_b_dictoffset); + if (b_dictoffset == -1 && PyErr_Occurred()) goto dictoffset_return; +#endif + if (b_dictoffset) { + { + __Pyx_TypeName b_name = __Pyx_PyType_GetName(b); + PyErr_Format(PyExc_TypeError, + "extension type '%.200s' has no __dict__ slot, " + "but base type '" __Pyx_FMT_TYPENAME "' has: " + "either add 'cdef dict __dict__' to the extension type " + "or add '__slots__ = [...]' to the base type", + type_name, b_name); + __Pyx_DECREF_TypeName(b_name); + } +#if !(CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY) + dictoffset_return: +#endif +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + return -1; + } + } +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + } + return 0; +} +#endif + +/* PyType_Ready */ + static int __Pyx_PyType_Ready(PyTypeObject *t) { +#if CYTHON_USE_TYPE_SPECS || !(CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API) || defined(PYSTON_MAJOR_VERSION) + (void)__Pyx_PyObject_CallMethod0; +#if CYTHON_USE_TYPE_SPECS + (void)__Pyx_validate_bases_tuple; +#endif + return PyType_Ready(t); +#else + int r; + PyObject *bases = __Pyx_PyType_GetSlot(t, tp_bases, PyObject*); + if (bases && unlikely(__Pyx_validate_bases_tuple(t->tp_name, t->tp_dictoffset, bases) == -1)) + return -1; +#if PY_VERSION_HEX >= 0x03050000 && !defined(PYSTON_MAJOR_VERSION) + { + int gc_was_enabled; + #if PY_VERSION_HEX >= 0x030A00b1 + gc_was_enabled = PyGC_Disable(); + (void)__Pyx_PyObject_CallMethod0; + #else + PyObject *ret, *py_status; + PyObject *gc = NULL; + #if PY_VERSION_HEX >= 0x030700a1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM+0 >= 0x07030400) + gc = PyImport_GetModule(__pyx_kp_u_gc); + #endif + if (unlikely(!gc)) gc = PyImport_Import(__pyx_kp_u_gc); + if (unlikely(!gc)) return -1; + py_status = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_isenabled); + if (unlikely(!py_status)) { + Py_DECREF(gc); + return -1; + } + gc_was_enabled = __Pyx_PyObject_IsTrue(py_status); + Py_DECREF(py_status); + if (gc_was_enabled > 0) { + ret = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_disable); + if (unlikely(!ret)) { + Py_DECREF(gc); + return -1; + } + Py_DECREF(ret); + } else if (unlikely(gc_was_enabled == -1)) { + Py_DECREF(gc); + return -1; + } + #endif + t->tp_flags |= Py_TPFLAGS_HEAPTYPE; +#if PY_VERSION_HEX >= 0x030A0000 + t->tp_flags |= Py_TPFLAGS_IMMUTABLETYPE; +#endif +#else + (void)__Pyx_PyObject_CallMethod0; +#endif + r = PyType_Ready(t); +#if PY_VERSION_HEX >= 0x03050000 && !defined(PYSTON_MAJOR_VERSION) + t->tp_flags &= ~Py_TPFLAGS_HEAPTYPE; + #if PY_VERSION_HEX >= 0x030A00b1 + if (gc_was_enabled) + PyGC_Enable(); + #else + if (gc_was_enabled) { + PyObject *tp, *v, *tb; + PyErr_Fetch(&tp, &v, &tb); + ret = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_enable); + if (likely(ret || r == -1)) { + Py_XDECREF(ret); + PyErr_Restore(tp, v, tb); + } else { + Py_XDECREF(tp); + Py_XDECREF(v); + Py_XDECREF(tb); + r = -1; + } + } + Py_DECREF(gc); + #endif + } +#endif + return r; +#endif +} + +/* Import */ + static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { + PyObject *module = 0; + PyObject *empty_dict = 0; + PyObject *empty_list = 0; + #if PY_MAJOR_VERSION < 3 + PyObject *py_import; + py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); + if (unlikely(!py_import)) + goto bad; + if (!from_list) { + empty_list = PyList_New(0); + if (unlikely(!empty_list)) + goto bad; + from_list = empty_list; + } + #endif + empty_dict = PyDict_New(); + if (unlikely(!empty_dict)) + goto bad; + { + #if PY_MAJOR_VERSION >= 3 + if (level == -1) { + if (strchr(__Pyx_MODULE_NAME, '.') != NULL) { + module = PyImport_ImportModuleLevelObject( + name, __pyx_d, empty_dict, from_list, 1); + if (unlikely(!module)) { + if (unlikely(!PyErr_ExceptionMatches(PyExc_ImportError))) + goto bad; + PyErr_Clear(); + } + } + level = 0; + } + #endif + if (!module) { + #if PY_MAJOR_VERSION < 3 + PyObject *py_level = PyInt_FromLong(level); + if (unlikely(!py_level)) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, __pyx_d, empty_dict, from_list, py_level, (PyObject *)NULL); + Py_DECREF(py_level); + #else + module = PyImport_ImportModuleLevelObject( + name, __pyx_d, empty_dict, from_list, level); + #endif + } + } +bad: + Py_XDECREF(empty_dict); + Py_XDECREF(empty_list); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(py_import); + #endif + return module; +} + +/* ImportDottedModule */ + #if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx__ImportDottedModule_Error(PyObject *name, PyObject *parts_tuple, Py_ssize_t count) { + PyObject *partial_name = NULL, *slice = NULL, *sep = NULL; + if (unlikely(PyErr_Occurred())) { + PyErr_Clear(); + } + if (likely(PyTuple_GET_SIZE(parts_tuple) == count)) { + partial_name = name; + } else { + slice = PySequence_GetSlice(parts_tuple, 0, count); + if (unlikely(!slice)) + goto bad; + sep = PyUnicode_FromStringAndSize(".", 1); + if (unlikely(!sep)) + goto bad; + partial_name = PyUnicode_Join(sep, slice); + } + PyErr_Format( +#if PY_MAJOR_VERSION < 3 + PyExc_ImportError, + "No module named '%s'", PyString_AS_STRING(partial_name)); +#else +#if PY_VERSION_HEX >= 0x030600B1 + PyExc_ModuleNotFoundError, +#else + PyExc_ImportError, +#endif + "No module named '%U'", partial_name); +#endif +bad: + Py_XDECREF(sep); + Py_XDECREF(slice); + Py_XDECREF(partial_name); + return NULL; +} +#endif +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx__ImportDottedModule_Lookup(PyObject *name) { + PyObject *imported_module; +#if PY_VERSION_HEX < 0x030700A1 || (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM < 0x07030400) + PyObject *modules = PyImport_GetModuleDict(); + if (unlikely(!modules)) + return NULL; + imported_module = __Pyx_PyDict_GetItemStr(modules, name); + Py_XINCREF(imported_module); +#else + imported_module = PyImport_GetModule(name); +#endif + return imported_module; +} +#endif +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple) { + Py_ssize_t i, nparts; + nparts = PyTuple_GET_SIZE(parts_tuple); + for (i=1; i < nparts && module; i++) { + PyObject *part, *submodule; +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + part = PyTuple_GET_ITEM(parts_tuple, i); +#else + part = PySequence_ITEM(parts_tuple, i); +#endif + submodule = __Pyx_PyObject_GetAttrStrNoError(module, part); +#if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) + Py_DECREF(part); +#endif + Py_DECREF(module); + module = submodule; + } + if (unlikely(!module)) { + return __Pyx__ImportDottedModule_Error(name, parts_tuple, i); + } + return module; +} +#endif +static PyObject *__Pyx__ImportDottedModule(PyObject *name, PyObject *parts_tuple) { +#if PY_MAJOR_VERSION < 3 + PyObject *module, *from_list, *star = __pyx_n_s__2; + CYTHON_UNUSED_VAR(parts_tuple); + from_list = PyList_New(1); + if (unlikely(!from_list)) + return NULL; + Py_INCREF(star); + PyList_SET_ITEM(from_list, 0, star); + module = __Pyx_Import(name, from_list, 0); + Py_DECREF(from_list); + return module; +#else + PyObject *imported_module; + PyObject *module = __Pyx_Import(name, NULL, 0); + if (!parts_tuple || unlikely(!module)) + return module; + imported_module = __Pyx__ImportDottedModule_Lookup(name); + if (likely(imported_module)) { + Py_DECREF(module); + return imported_module; + } + PyErr_Clear(); + return __Pyx_ImportDottedModule_WalkParts(module, name, parts_tuple); +#endif +} +static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030400B1 + PyObject *module = __Pyx__ImportDottedModule_Lookup(name); + if (likely(module)) { + PyObject *spec = __Pyx_PyObject_GetAttrStrNoError(module, __pyx_n_s_spec); + if (likely(spec)) { + PyObject *unsafe = __Pyx_PyObject_GetAttrStrNoError(spec, __pyx_n_s_initializing); + if (likely(!unsafe || !__Pyx_PyObject_IsTrue(unsafe))) { + Py_DECREF(spec); + spec = NULL; + } + Py_XDECREF(unsafe); + } + if (likely(!spec)) { + PyErr_Clear(); + return module; + } + Py_DECREF(spec); + Py_DECREF(module); + } else if (PyErr_Occurred()) { + PyErr_Clear(); + } +#endif + return __Pyx__ImportDottedModule(name, parts_tuple); +} + +/* ImportFrom */ + static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) { + PyObject* value = __Pyx_PyObject_GetAttrStr(module, name); + if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) { + const char* module_name_str = 0; + PyObject* module_name = 0; + PyObject* module_dot = 0; + PyObject* full_name = 0; + PyErr_Clear(); + module_name_str = PyModule_GetName(module); + if (unlikely(!module_name_str)) { goto modbad; } + module_name = PyUnicode_FromString(module_name_str); + if (unlikely(!module_name)) { goto modbad; } + module_dot = PyUnicode_Concat(module_name, __pyx_kp_u__3); + if (unlikely(!module_dot)) { goto modbad; } + full_name = PyUnicode_Concat(module_dot, name); + if (unlikely(!full_name)) { goto modbad; } + #if PY_VERSION_HEX < 0x030700A1 || (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM < 0x07030400) + { + PyObject *modules = PyImport_GetModuleDict(); + if (unlikely(!modules)) + goto modbad; + value = PyObject_GetItem(modules, full_name); + } + #else + value = PyImport_GetModule(full_name); + #endif + modbad: + Py_XDECREF(full_name); + Py_XDECREF(module_dot); + Py_XDECREF(module_name); + } + if (unlikely(!value)) { + PyErr_Format(PyExc_ImportError, + #if PY_MAJOR_VERSION < 3 + "cannot import name %.230s", PyString_AS_STRING(name)); + #else + "cannot import name %S", name); + #endif + } + return value; +} + +/* Py3UpdateBases */ + static PyObject* +__Pyx_PEP560_update_bases(PyObject *bases) +{ + Py_ssize_t i, j, size_bases; + PyObject *base, *meth, *new_base, *result, *new_bases = NULL; + size_bases = PyTuple_GET_SIZE(bases); + for (i = 0; i < size_bases; i++) { + base = PyTuple_GET_ITEM(bases, i); + if (PyType_Check(base)) { + if (new_bases) { + if (PyList_Append(new_bases, base) < 0) { + goto error; + } + } + continue; + } + meth = __Pyx_PyObject_GetAttrStrNoError(base, __pyx_n_s_mro_entries); + if (!meth && PyErr_Occurred()) { + goto error; + } + if (!meth) { + if (new_bases) { + if (PyList_Append(new_bases, base) < 0) { + goto error; + } + } + continue; + } + new_base = __Pyx_PyObject_CallOneArg(meth, bases); + Py_DECREF(meth); + if (!new_base) { + goto error; + } + if (!PyTuple_Check(new_base)) { + PyErr_SetString(PyExc_TypeError, + "__mro_entries__ must return a tuple"); + Py_DECREF(new_base); + goto error; + } + if (!new_bases) { + if (!(new_bases = PyList_New(i))) { + goto error; + } + for (j = 0; j < i; j++) { + base = PyTuple_GET_ITEM(bases, j); + PyList_SET_ITEM(new_bases, j, base); + Py_INCREF(base); + } + } + j = PyList_GET_SIZE(new_bases); + if (PyList_SetSlice(new_bases, j, j, new_base) < 0) { + goto error; + } + Py_DECREF(new_base); + } + if (!new_bases) { + Py_INCREF(bases); + return bases; + } + result = PyList_AsTuple(new_bases); + Py_DECREF(new_bases); + return result; +error: + Py_XDECREF(new_bases); + return NULL; +} + +/* CalculateMetaclass */ + static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) { + Py_ssize_t i, nbases; +#if CYTHON_ASSUME_SAFE_MACROS + nbases = PyTuple_GET_SIZE(bases); +#else + nbases = PyTuple_Size(bases); + if (nbases < 0) return NULL; +#endif + for (i=0; i < nbases; i++) { + PyTypeObject *tmptype; +#if CYTHON_ASSUME_SAFE_MACROS + PyObject *tmp = PyTuple_GET_ITEM(bases, i); +#else + PyObject *tmp = PyTuple_GetItem(bases, i); + if (!tmp) return NULL; +#endif + tmptype = Py_TYPE(tmp); +#if PY_MAJOR_VERSION < 3 + if (tmptype == &PyClass_Type) + continue; +#endif + if (!metaclass) { + metaclass = tmptype; + continue; + } + if (PyType_IsSubtype(metaclass, tmptype)) + continue; + if (PyType_IsSubtype(tmptype, metaclass)) { + metaclass = tmptype; + continue; + } + PyErr_SetString(PyExc_TypeError, + "metaclass conflict: " + "the metaclass of a derived class " + "must be a (non-strict) subclass " + "of the metaclasses of all its bases"); + return NULL; + } + if (!metaclass) { +#if PY_MAJOR_VERSION < 3 + metaclass = &PyClass_Type; +#else + metaclass = &PyType_Type; +#endif + } + Py_INCREF((PyObject*) metaclass); + return (PyObject*) metaclass; +} + +/* PyVectorcallFastCallDict */ + #if CYTHON_METH_FASTCALL +static PyObject *__Pyx_PyVectorcall_FastCallDict_kw(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw) +{ + PyObject *res = NULL; + PyObject *kwnames; + PyObject **newargs; + PyObject **kwvalues; + Py_ssize_t i, pos; + size_t j; + PyObject *key, *value; + unsigned long keys_are_strings; + Py_ssize_t nkw = PyDict_GET_SIZE(kw); + newargs = (PyObject **)PyMem_Malloc((nargs + (size_t)nkw) * sizeof(args[0])); + if (unlikely(newargs == NULL)) { + PyErr_NoMemory(); + return NULL; + } + for (j = 0; j < nargs; j++) newargs[j] = args[j]; + kwnames = PyTuple_New(nkw); + if (unlikely(kwnames == NULL)) { + PyMem_Free(newargs); + return NULL; + } + kwvalues = newargs + nargs; + pos = i = 0; + keys_are_strings = Py_TPFLAGS_UNICODE_SUBCLASS; + while (PyDict_Next(kw, &pos, &key, &value)) { + keys_are_strings &= Py_TYPE(key)->tp_flags; + Py_INCREF(key); + Py_INCREF(value); + PyTuple_SET_ITEM(kwnames, i, key); + kwvalues[i] = value; + i++; + } + if (unlikely(!keys_are_strings)) { + PyErr_SetString(PyExc_TypeError, "keywords must be strings"); + goto cleanup; + } + res = vc(func, newargs, nargs, kwnames); +cleanup: + Py_DECREF(kwnames); + for (i = 0; i < nkw; i++) + Py_DECREF(kwvalues[i]); + PyMem_Free(newargs); + return res; +} +static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw) +{ + if (likely(kw == NULL) || PyDict_GET_SIZE(kw) == 0) { + return vc(func, args, nargs, NULL); + } + return __Pyx_PyVectorcall_FastCallDict_kw(func, vc, args, nargs, kw); +} +#endif + +/* CythonFunctionShared */ + #if CYTHON_COMPILING_IN_LIMITED_API +static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc) { + if (__Pyx_CyFunction_Check(func)) { + return PyCFunction_GetFunction(((__pyx_CyFunctionObject*)func)->func) == (PyCFunction) cfunc; + } else if (PyCFunction_Check(func)) { + return PyCFunction_GetFunction(func) == (PyCFunction) cfunc; + } + return 0; +} +#else +static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc) { + return __Pyx_CyOrPyCFunction_Check(func) && __Pyx_CyOrPyCFunction_GET_FUNCTION(func) == (PyCFunction) cfunc; +} +#endif +static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj) { +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + __Pyx_Py_XDECREF_SET( + __Pyx_CyFunction_GetClassObj(f), + ((classobj) ? __Pyx_NewRef(classobj) : NULL)); +#else + __Pyx_Py_XDECREF_SET( + ((PyCMethodObject *) (f))->mm_class, + (PyTypeObject*)((classobj) ? __Pyx_NewRef(classobj) : NULL)); +#endif +} +static PyObject * +__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, void *closure) +{ + CYTHON_UNUSED_VAR(closure); + if (unlikely(op->func_doc == NULL)) { +#if CYTHON_COMPILING_IN_LIMITED_API + op->func_doc = PyObject_GetAttrString(op->func, "__doc__"); + if (unlikely(!op->func_doc)) return NULL; +#else + if (((PyCFunctionObject*)op)->m_ml->ml_doc) { +#if PY_MAJOR_VERSION >= 3 + op->func_doc = PyUnicode_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc); +#else + op->func_doc = PyString_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc); +#endif + if (unlikely(op->func_doc == NULL)) + return NULL; + } else { + Py_INCREF(Py_None); + return Py_None; + } +#endif + } + Py_INCREF(op->func_doc); + return op->func_doc; +} +static int +__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (value == NULL) { + value = Py_None; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_doc, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (unlikely(op->func_name == NULL)) { +#if CYTHON_COMPILING_IN_LIMITED_API + op->func_name = PyObject_GetAttrString(op->func, "__name__"); +#elif PY_MAJOR_VERSION >= 3 + op->func_name = PyUnicode_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name); +#else + op->func_name = PyString_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name); +#endif + if (unlikely(op->func_name == NULL)) + return NULL; + } + Py_INCREF(op->func_name); + return op->func_name; +} +static int +__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) +#else + if (unlikely(value == NULL || !PyString_Check(value))) +#endif + { + PyErr_SetString(PyExc_TypeError, + "__name__ must be set to a string object"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_name, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + Py_INCREF(op->func_qualname); + return op->func_qualname; +} +static int +__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) +#else + if (unlikely(value == NULL || !PyString_Check(value))) +#endif + { + PyErr_SetString(PyExc_TypeError, + "__qualname__ must be set to a string object"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_qualname, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (unlikely(op->func_dict == NULL)) { + op->func_dict = PyDict_New(); + if (unlikely(op->func_dict == NULL)) + return NULL; + } + Py_INCREF(op->func_dict); + return op->func_dict; +} +static int +__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (unlikely(value == NULL)) { + PyErr_SetString(PyExc_TypeError, + "function's dictionary may not be deleted"); + return -1; + } + if (unlikely(!PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "setting function's dictionary to a non-dict"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_dict, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + Py_INCREF(op->func_globals); + return op->func_globals; +} +static PyObject * +__Pyx_CyFunction_get_closure(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(op); + CYTHON_UNUSED_VAR(context); + Py_INCREF(Py_None); + return Py_None; +} +static PyObject * +__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op, void *context) +{ + PyObject* result = (op->func_code) ? op->func_code : Py_None; + CYTHON_UNUSED_VAR(context); + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) { + int result = 0; + PyObject *res = op->defaults_getter((PyObject *) op); + if (unlikely(!res)) + return -1; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + op->defaults_tuple = PyTuple_GET_ITEM(res, 0); + Py_INCREF(op->defaults_tuple); + op->defaults_kwdict = PyTuple_GET_ITEM(res, 1); + Py_INCREF(op->defaults_kwdict); + #else + op->defaults_tuple = __Pyx_PySequence_ITEM(res, 0); + if (unlikely(!op->defaults_tuple)) result = -1; + else { + op->defaults_kwdict = __Pyx_PySequence_ITEM(res, 1); + if (unlikely(!op->defaults_kwdict)) result = -1; + } + #endif + Py_DECREF(res); + return result; +} +static int +__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + if (!value) { + value = Py_None; + } else if (unlikely(value != Py_None && !PyTuple_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "__defaults__ must be set to a tuple object"); + return -1; + } + PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__defaults__ will not " + "currently affect the values used in function calls", 1); + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->defaults_tuple, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op, void *context) { + PyObject* result = op->defaults_tuple; + CYTHON_UNUSED_VAR(context); + if (unlikely(!result)) { + if (op->defaults_getter) { + if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL; + result = op->defaults_tuple; + } else { + result = Py_None; + } + } + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + if (!value) { + value = Py_None; + } else if (unlikely(value != Py_None && !PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "__kwdefaults__ must be set to a dict object"); + return -1; + } + PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__kwdefaults__ will not " + "currently affect the values used in function calls", 1); + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->defaults_kwdict, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op, void *context) { + PyObject* result = op->defaults_kwdict; + CYTHON_UNUSED_VAR(context); + if (unlikely(!result)) { + if (op->defaults_getter) { + if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL; + result = op->defaults_kwdict; + } else { + result = Py_None; + } + } + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + if (!value || value == Py_None) { + value = NULL; + } else if (unlikely(!PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "__annotations__ must be set to a dict object"); + return -1; + } + Py_XINCREF(value); + __Pyx_Py_XDECREF_SET(op->func_annotations, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op, void *context) { + PyObject* result = op->func_annotations; + CYTHON_UNUSED_VAR(context); + if (unlikely(!result)) { + result = PyDict_New(); + if (unlikely(!result)) return NULL; + op->func_annotations = result; + } + Py_INCREF(result); + return result; +} +static PyObject * +__Pyx_CyFunction_get_is_coroutine(__pyx_CyFunctionObject *op, void *context) { + int is_coroutine; + CYTHON_UNUSED_VAR(context); + if (op->func_is_coroutine) { + return __Pyx_NewRef(op->func_is_coroutine); + } + is_coroutine = op->flags & __Pyx_CYFUNCTION_COROUTINE; +#if PY_VERSION_HEX >= 0x03050000 + if (is_coroutine) { + PyObject *module, *fromlist, *marker = __pyx_n_s_is_coroutine; + fromlist = PyList_New(1); + if (unlikely(!fromlist)) return NULL; + Py_INCREF(marker); +#if CYTHON_ASSUME_SAFE_MACROS + PyList_SET_ITEM(fromlist, 0, marker); +#else + if (unlikely(PyList_SetItem(fromlist, 0, marker) < 0)) { + Py_DECREF(marker); + Py_DECREF(fromlist); + return NULL; + } +#endif + module = PyImport_ImportModuleLevelObject(__pyx_n_s_asyncio_coroutines, NULL, NULL, fromlist, 0); + Py_DECREF(fromlist); + if (unlikely(!module)) goto ignore; + op->func_is_coroutine = __Pyx_PyObject_GetAttrStr(module, marker); + Py_DECREF(module); + if (likely(op->func_is_coroutine)) { + return __Pyx_NewRef(op->func_is_coroutine); + } +ignore: + PyErr_Clear(); + } +#endif + op->func_is_coroutine = __Pyx_PyBool_FromLong(is_coroutine); + return __Pyx_NewRef(op->func_is_coroutine); +} +#if CYTHON_COMPILING_IN_LIMITED_API +static PyObject * +__Pyx_CyFunction_get_module(__pyx_CyFunctionObject *op, void *context) { + CYTHON_UNUSED_VAR(context); + return PyObject_GetAttrString(op->func, "__module__"); +} +static int +__Pyx_CyFunction_set_module(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + return PyObject_SetAttrString(op->func, "__module__", value); +} +#endif +static PyGetSetDef __pyx_CyFunction_getsets[] = { + {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, + {(char *) "__doc__", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, + {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, + {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, + {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0}, + {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, + {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, + {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, + {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, + {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, + {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, + {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, + {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, + {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, + {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, + {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0}, + {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0}, + {(char *) "_is_coroutine", (getter)__Pyx_CyFunction_get_is_coroutine, 0, 0, 0}, +#if CYTHON_COMPILING_IN_LIMITED_API + {"__module__", (getter)__Pyx_CyFunction_get_module, (setter)__Pyx_CyFunction_set_module, 0, 0}, +#endif + {0, 0, 0, 0, 0} +}; +static PyMemberDef __pyx_CyFunction_members[] = { +#if !CYTHON_COMPILING_IN_LIMITED_API + {(char *) "__module__", T_OBJECT, offsetof(PyCFunctionObject, m_module), 0, 0}, +#endif +#if CYTHON_USE_TYPE_SPECS + {(char *) "__dictoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_dict), READONLY, 0}, +#if CYTHON_METH_FASTCALL +#if CYTHON_BACKPORT_VECTORCALL + {(char *) "__vectorcalloffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_vectorcall), READONLY, 0}, +#else +#if !CYTHON_COMPILING_IN_LIMITED_API + {(char *) "__vectorcalloffset__", T_PYSSIZET, offsetof(PyCFunctionObject, vectorcall), READONLY, 0}, +#endif +#endif +#endif +#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API + {(char *) "__weaklistoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_weakreflist), READONLY, 0}, +#else + {(char *) "__weaklistoffset__", T_PYSSIZET, offsetof(PyCFunctionObject, m_weakreflist), READONLY, 0}, +#endif +#endif + {0, 0, 0, 0, 0} +}; +static PyObject * +__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, PyObject *args) +{ + CYTHON_UNUSED_VAR(args); +#if PY_MAJOR_VERSION >= 3 + Py_INCREF(m->func_qualname); + return m->func_qualname; +#else + return PyString_FromString(((PyCFunctionObject*)m)->m_ml->ml_name); +#endif +} +static PyMethodDef __pyx_CyFunction_methods[] = { + {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0}, + {0, 0, 0, 0} +}; +#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API +#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist) +#else +#define __Pyx_CyFunction_weakreflist(cyfunc) (((PyCFunctionObject*)cyfunc)->m_weakreflist) +#endif +static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject *op, PyMethodDef *ml, int flags, PyObject* qualname, + PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { +#if !CYTHON_COMPILING_IN_LIMITED_API + PyCFunctionObject *cf = (PyCFunctionObject*) op; +#endif + if (unlikely(op == NULL)) + return NULL; +#if CYTHON_COMPILING_IN_LIMITED_API + op->func = PyCFunction_NewEx(ml, (PyObject*)op, module); + if (unlikely(!op->func)) return NULL; +#endif + op->flags = flags; + __Pyx_CyFunction_weakreflist(op) = NULL; +#if !CYTHON_COMPILING_IN_LIMITED_API + cf->m_ml = ml; + cf->m_self = (PyObject *) op; +#endif + Py_XINCREF(closure); + op->func_closure = closure; +#if !CYTHON_COMPILING_IN_LIMITED_API + Py_XINCREF(module); + cf->m_module = module; +#endif + op->func_dict = NULL; + op->func_name = NULL; + Py_INCREF(qualname); + op->func_qualname = qualname; + op->func_doc = NULL; +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + op->func_classobj = NULL; +#else + ((PyCMethodObject*)op)->mm_class = NULL; +#endif + op->func_globals = globals; + Py_INCREF(op->func_globals); + Py_XINCREF(code); + op->func_code = code; + op->defaults_pyobjects = 0; + op->defaults_size = 0; + op->defaults = NULL; + op->defaults_tuple = NULL; + op->defaults_kwdict = NULL; + op->defaults_getter = NULL; + op->func_annotations = NULL; + op->func_is_coroutine = NULL; +#if CYTHON_METH_FASTCALL + switch (ml->ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O | METH_KEYWORDS | METH_METHOD)) { + case METH_NOARGS: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_NOARGS; + break; + case METH_O: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_O; + break; + case METH_METHOD | METH_FASTCALL | METH_KEYWORDS: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD; + break; + case METH_FASTCALL | METH_KEYWORDS: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS; + break; + case METH_VARARGS | METH_KEYWORDS: + __Pyx_CyFunction_func_vectorcall(op) = NULL; + break; + default: + PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction"); + Py_DECREF(op); + return NULL; + } +#endif + return (PyObject *) op; +} +static int +__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m) +{ + Py_CLEAR(m->func_closure); +#if CYTHON_COMPILING_IN_LIMITED_API + Py_CLEAR(m->func); +#else + Py_CLEAR(((PyCFunctionObject*)m)->m_module); +#endif + Py_CLEAR(m->func_dict); + Py_CLEAR(m->func_name); + Py_CLEAR(m->func_qualname); + Py_CLEAR(m->func_doc); + Py_CLEAR(m->func_globals); + Py_CLEAR(m->func_code); +#if !CYTHON_COMPILING_IN_LIMITED_API +#if PY_VERSION_HEX < 0x030900B1 + Py_CLEAR(__Pyx_CyFunction_GetClassObj(m)); +#else + { + PyObject *cls = (PyObject*) ((PyCMethodObject *) (m))->mm_class; + ((PyCMethodObject *) (m))->mm_class = NULL; + Py_XDECREF(cls); + } +#endif +#endif + Py_CLEAR(m->defaults_tuple); + Py_CLEAR(m->defaults_kwdict); + Py_CLEAR(m->func_annotations); + Py_CLEAR(m->func_is_coroutine); + if (m->defaults) { + PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); + int i; + for (i = 0; i < m->defaults_pyobjects; i++) + Py_XDECREF(pydefaults[i]); + PyObject_Free(m->defaults); + m->defaults = NULL; + } + return 0; +} +static void __Pyx__CyFunction_dealloc(__pyx_CyFunctionObject *m) +{ + if (__Pyx_CyFunction_weakreflist(m) != NULL) + PyObject_ClearWeakRefs((PyObject *) m); + __Pyx_CyFunction_clear(m); + __Pyx_PyHeapTypeObject_GC_Del(m); +} +static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m) +{ + PyObject_GC_UnTrack(m); + __Pyx__CyFunction_dealloc(m); +} +static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg) +{ + Py_VISIT(m->func_closure); +#if CYTHON_COMPILING_IN_LIMITED_API + Py_VISIT(m->func); +#else + Py_VISIT(((PyCFunctionObject*)m)->m_module); +#endif + Py_VISIT(m->func_dict); + Py_VISIT(m->func_name); + Py_VISIT(m->func_qualname); + Py_VISIT(m->func_doc); + Py_VISIT(m->func_globals); + Py_VISIT(m->func_code); +#if !CYTHON_COMPILING_IN_LIMITED_API + Py_VISIT(__Pyx_CyFunction_GetClassObj(m)); +#endif + Py_VISIT(m->defaults_tuple); + Py_VISIT(m->defaults_kwdict); + Py_VISIT(m->func_is_coroutine); + if (m->defaults) { + PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); + int i; + for (i = 0; i < m->defaults_pyobjects; i++) + Py_VISIT(pydefaults[i]); + } + return 0; +} +static PyObject* +__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op) +{ +#if PY_MAJOR_VERSION >= 3 + return PyUnicode_FromFormat("", + op->func_qualname, (void *)op); +#else + return PyString_FromFormat("", + PyString_AsString(op->func_qualname), (void *)op); +#endif +} +static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) { +#if CYTHON_COMPILING_IN_LIMITED_API + PyObject *f = ((__pyx_CyFunctionObject*)func)->func; + PyObject *py_name = NULL; + PyCFunction meth; + int flags; + meth = PyCFunction_GetFunction(f); + if (unlikely(!meth)) return NULL; + flags = PyCFunction_GetFlags(f); + if (unlikely(flags < 0)) return NULL; +#else + PyCFunctionObject* f = (PyCFunctionObject*)func; + PyCFunction meth = f->m_ml->ml_meth; + int flags = f->m_ml->ml_flags; +#endif + Py_ssize_t size; + switch (flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) { + case METH_VARARGS: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) + return (*meth)(self, arg); + break; + case METH_VARARGS | METH_KEYWORDS: + return (*(PyCFunctionWithKeywords)(void*)meth)(self, arg, kw); + case METH_NOARGS: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) { +#if CYTHON_ASSUME_SAFE_MACROS + size = PyTuple_GET_SIZE(arg); +#else + size = PyTuple_Size(arg); + if (unlikely(size < 0)) return NULL; +#endif + if (likely(size == 0)) + return (*meth)(self, NULL); +#if CYTHON_COMPILING_IN_LIMITED_API + py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); + if (!py_name) return NULL; + PyErr_Format(PyExc_TypeError, + "%.200S() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + py_name, size); + Py_DECREF(py_name); +#else + PyErr_Format(PyExc_TypeError, + "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + f->m_ml->ml_name, size); +#endif + return NULL; + } + break; + case METH_O: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) { +#if CYTHON_ASSUME_SAFE_MACROS + size = PyTuple_GET_SIZE(arg); +#else + size = PyTuple_Size(arg); + if (unlikely(size < 0)) return NULL; +#endif + if (likely(size == 1)) { + PyObject *result, *arg0; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + arg0 = PyTuple_GET_ITEM(arg, 0); + #else + arg0 = __Pyx_PySequence_ITEM(arg, 0); if (unlikely(!arg0)) return NULL; + #endif + result = (*meth)(self, arg0); + #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) + Py_DECREF(arg0); + #endif + return result; + } +#if CYTHON_COMPILING_IN_LIMITED_API + py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); + if (!py_name) return NULL; + PyErr_Format(PyExc_TypeError, + "%.200S() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + py_name, size); + Py_DECREF(py_name); +#else + PyErr_Format(PyExc_TypeError, + "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + f->m_ml->ml_name, size); +#endif + return NULL; + } + break; + default: + PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction"); + return NULL; + } +#if CYTHON_COMPILING_IN_LIMITED_API + py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); + if (!py_name) return NULL; + PyErr_Format(PyExc_TypeError, "%.200S() takes no keyword arguments", + py_name); + Py_DECREF(py_name); +#else + PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments", + f->m_ml->ml_name); +#endif + return NULL; +} +static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *self, *result; +#if CYTHON_COMPILING_IN_LIMITED_API + self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)func)->func); + if (unlikely(!self) && PyErr_Occurred()) return NULL; +#else + self = ((PyCFunctionObject*)func)->m_self; +#endif + result = __Pyx_CyFunction_CallMethod(func, self, arg, kw); + return result; +} +static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) { + PyObject *result; + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func; +#if CYTHON_METH_FASTCALL + __pyx_vectorcallfunc vc = __Pyx_CyFunction_func_vectorcall(cyfunc); + if (vc) { +#if CYTHON_ASSUME_SAFE_MACROS + return __Pyx_PyVectorcall_FastCallDict(func, vc, &PyTuple_GET_ITEM(args, 0), (size_t)PyTuple_GET_SIZE(args), kw); +#else + (void) &__Pyx_PyVectorcall_FastCallDict; + return PyVectorcall_Call(func, args, kw); +#endif + } +#endif + if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { + Py_ssize_t argc; + PyObject *new_args; + PyObject *self; +#if CYTHON_ASSUME_SAFE_MACROS + argc = PyTuple_GET_SIZE(args); +#else + argc = PyTuple_Size(args); + if (unlikely(!argc) < 0) return NULL; +#endif + new_args = PyTuple_GetSlice(args, 1, argc); + if (unlikely(!new_args)) + return NULL; + self = PyTuple_GetItem(args, 0); + if (unlikely(!self)) { + Py_DECREF(new_args); +#if PY_MAJOR_VERSION > 2 + PyErr_Format(PyExc_TypeError, + "unbound method %.200S() needs an argument", + cyfunc->func_qualname); +#else + PyErr_SetString(PyExc_TypeError, + "unbound method needs an argument"); +#endif + return NULL; + } + result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw); + Py_DECREF(new_args); + } else { + result = __Pyx_CyFunction_Call(func, args, kw); + } + return result; +} +#if CYTHON_METH_FASTCALL +static CYTHON_INLINE int __Pyx_CyFunction_Vectorcall_CheckArgs(__pyx_CyFunctionObject *cyfunc, Py_ssize_t nargs, PyObject *kwnames) +{ + int ret = 0; + if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { + if (unlikely(nargs < 1)) { + PyErr_Format(PyExc_TypeError, "%.200s() needs an argument", + ((PyCFunctionObject*)cyfunc)->m_ml->ml_name); + return -1; + } + ret = 1; + } + if (unlikely(kwnames) && unlikely(PyTuple_GET_SIZE(kwnames))) { + PyErr_Format(PyExc_TypeError, + "%.200s() takes no keyword arguments", ((PyCFunctionObject*)cyfunc)->m_ml->ml_name); + return -1; + } + return ret; +} +static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + if (unlikely(nargs != 0)) { + PyErr_Format(PyExc_TypeError, + "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + def->ml_name, nargs); + return NULL; + } + return def->ml_meth(self, NULL); +} +static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + if (unlikely(nargs != 1)) { + PyErr_Format(PyExc_TypeError, + "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + def->ml_name, nargs); + return NULL; + } + return def->ml_meth(self, args[0]); +} +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + return ((__Pyx_PyCFunctionFastWithKeywords)(void(*)(void))def->ml_meth)(self, args, nargs, kwnames); +} +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; + PyTypeObject *cls = (PyTypeObject *) __Pyx_CyFunction_GetClassObj(cyfunc); +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + return ((__Pyx_PyCMethod)(void(*)(void))def->ml_meth)(self, cls, args, (size_t)nargs, kwnames); +} +#endif +#if CYTHON_USE_TYPE_SPECS +static PyType_Slot __pyx_CyFunctionType_slots[] = { + {Py_tp_dealloc, (void *)__Pyx_CyFunction_dealloc}, + {Py_tp_repr, (void *)__Pyx_CyFunction_repr}, + {Py_tp_call, (void *)__Pyx_CyFunction_CallAsMethod}, + {Py_tp_traverse, (void *)__Pyx_CyFunction_traverse}, + {Py_tp_clear, (void *)__Pyx_CyFunction_clear}, + {Py_tp_methods, (void *)__pyx_CyFunction_methods}, + {Py_tp_members, (void *)__pyx_CyFunction_members}, + {Py_tp_getset, (void *)__pyx_CyFunction_getsets}, + {Py_tp_descr_get, (void *)__Pyx_PyMethod_New}, + {0, 0}, +}; +static PyType_Spec __pyx_CyFunctionType_spec = { + __PYX_TYPE_MODULE_PREFIX "cython_function_or_method", + sizeof(__pyx_CyFunctionObject), + 0, +#ifdef Py_TPFLAGS_METHOD_DESCRIPTOR + Py_TPFLAGS_METHOD_DESCRIPTOR | +#endif +#if (defined(_Py_TPFLAGS_HAVE_VECTORCALL) && CYTHON_METH_FASTCALL) + _Py_TPFLAGS_HAVE_VECTORCALL | +#endif + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, + __pyx_CyFunctionType_slots +}; +#else +static PyTypeObject __pyx_CyFunctionType_type = { + PyVarObject_HEAD_INIT(0, 0) + __PYX_TYPE_MODULE_PREFIX "cython_function_or_method", + sizeof(__pyx_CyFunctionObject), + 0, + (destructor) __Pyx_CyFunction_dealloc, +#if !CYTHON_METH_FASTCALL + 0, +#elif CYTHON_BACKPORT_VECTORCALL + (printfunc)offsetof(__pyx_CyFunctionObject, func_vectorcall), +#else + offsetof(PyCFunctionObject, vectorcall), +#endif + 0, + 0, +#if PY_MAJOR_VERSION < 3 + 0, +#else + 0, +#endif + (reprfunc) __Pyx_CyFunction_repr, + 0, + 0, + 0, + 0, + __Pyx_CyFunction_CallAsMethod, + 0, + 0, + 0, + 0, +#ifdef Py_TPFLAGS_METHOD_DESCRIPTOR + Py_TPFLAGS_METHOD_DESCRIPTOR | +#endif +#if defined(_Py_TPFLAGS_HAVE_VECTORCALL) && CYTHON_METH_FASTCALL + _Py_TPFLAGS_HAVE_VECTORCALL | +#endif + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, + 0, + (traverseproc) __Pyx_CyFunction_traverse, + (inquiry) __Pyx_CyFunction_clear, + 0, +#if PY_VERSION_HEX < 0x030500A0 + offsetof(__pyx_CyFunctionObject, func_weakreflist), +#else + offsetof(PyCFunctionObject, m_weakreflist), +#endif + 0, + 0, + __pyx_CyFunction_methods, + __pyx_CyFunction_members, + __pyx_CyFunction_getsets, + 0, + 0, + __Pyx_PyMethod_New, + 0, + offsetof(__pyx_CyFunctionObject, func_dict), + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +#if PY_VERSION_HEX >= 0x030400a1 + 0, +#endif +#if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) + 0, +#endif +#if __PYX_NEED_TP_PRINT_SLOT + 0, +#endif +#if PY_VERSION_HEX >= 0x030C0000 + 0, +#endif +#if PY_VERSION_HEX >= 0x030d00A4 + 0, +#endif +#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 + 0, +#endif +}; +#endif +static int __pyx_CyFunction_init(PyObject *module) { +#if CYTHON_USE_TYPE_SPECS + __pyx_CyFunctionType = __Pyx_FetchCommonTypeFromSpec(module, &__pyx_CyFunctionType_spec, NULL); +#else + CYTHON_UNUSED_VAR(module); + __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type); +#endif + if (unlikely(__pyx_CyFunctionType == NULL)) { + return -1; + } + return 0; +} +static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults = PyObject_Malloc(size); + if (unlikely(!m->defaults)) + return PyErr_NoMemory(); + memset(m->defaults, 0, size); + m->defaults_pyobjects = pyobjects; + m->defaults_size = size; + return m->defaults; +} +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults_tuple = tuple; + Py_INCREF(tuple); +} +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults_kwdict = dict; + Py_INCREF(dict); +} +static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->func_annotations = dict; + Py_INCREF(dict); +} + +/* CythonFunction */ + static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, int flags, PyObject* qualname, + PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { + PyObject *op = __Pyx_CyFunction_Init( + PyObject_GC_New(__pyx_CyFunctionObject, __pyx_CyFunctionType), + ml, flags, qualname, closure, module, globals, code + ); + if (likely(op)) { + PyObject_GC_Track(op); + } + return op; +} + +/* PyObjectLookupSpecial */ + #if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx__PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name, int with_error) { + PyObject *res; + PyTypeObject *tp = Py_TYPE(obj); +#if PY_MAJOR_VERSION < 3 + if (unlikely(PyInstance_Check(obj))) + return with_error ? __Pyx_PyObject_GetAttrStr(obj, attr_name) : __Pyx_PyObject_GetAttrStrNoError(obj, attr_name); +#endif + res = _PyType_Lookup(tp, attr_name); + if (likely(res)) { + descrgetfunc f = Py_TYPE(res)->tp_descr_get; + if (!f) { + Py_INCREF(res); + } else { + res = f(res, obj, (PyObject *)tp); + } + } else if (with_error) { + PyErr_SetObject(PyExc_AttributeError, attr_name); + } + return res; +} +#endif + +/* Py3ClassCreate */ + static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, + PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc) { + PyObject *ns; + if (metaclass) { + PyObject *prep = __Pyx_PyObject_GetAttrStrNoError(metaclass, __pyx_n_s_prepare); + if (prep) { + PyObject *pargs[3] = {NULL, name, bases}; + ns = __Pyx_PyObject_FastCallDict(prep, pargs+1, 2 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET, mkw); + Py_DECREF(prep); + } else { + if (unlikely(PyErr_Occurred())) + return NULL; + ns = PyDict_New(); + } + } else { + ns = PyDict_New(); + } + if (unlikely(!ns)) + return NULL; + if (unlikely(PyObject_SetItem(ns, __pyx_n_s_module, modname) < 0)) goto bad; +#if PY_VERSION_HEX >= 0x03030000 + if (unlikely(PyObject_SetItem(ns, __pyx_n_s_qualname, qualname) < 0)) goto bad; +#else + CYTHON_MAYBE_UNUSED_VAR(qualname); +#endif + if (unlikely(doc && PyObject_SetItem(ns, __pyx_n_s_doc, doc) < 0)) goto bad; + return ns; +bad: + Py_DECREF(ns); + return NULL; +} +#if PY_VERSION_HEX < 0x030600A4 && CYTHON_PEP487_INIT_SUBCLASS +static int __Pyx_SetNamesPEP487(PyObject *type_obj) { + PyTypeObject *type = (PyTypeObject*) type_obj; + PyObject *names_to_set, *key, *value, *set_name, *tmp; + Py_ssize_t i = 0; +#if CYTHON_USE_TYPE_SLOTS + names_to_set = PyDict_Copy(type->tp_dict); +#else + { + PyObject *d = PyObject_GetAttr(type_obj, __pyx_n_s_dict); + names_to_set = NULL; + if (likely(d)) { + PyObject *names_to_set = PyDict_New(); + int ret = likely(names_to_set) ? PyDict_Update(names_to_set, d) : -1; + Py_DECREF(d); + if (unlikely(ret < 0)) + Py_CLEAR(names_to_set); + } + } +#endif + if (unlikely(names_to_set == NULL)) + goto bad; + while (PyDict_Next(names_to_set, &i, &key, &value)) { + set_name = __Pyx_PyObject_LookupSpecialNoError(value, __pyx_n_s_set_name); + if (unlikely(set_name != NULL)) { + tmp = __Pyx_PyObject_Call2Args(set_name, type_obj, key); + Py_DECREF(set_name); + if (unlikely(tmp == NULL)) { + __Pyx_TypeName value_type_name = + __Pyx_PyType_GetName(Py_TYPE(value)); + __Pyx_TypeName type_name = __Pyx_PyType_GetName(type); + PyErr_Format(PyExc_RuntimeError, +#if PY_MAJOR_VERSION >= 3 + "Error calling __set_name__ on '" __Pyx_FMT_TYPENAME "' instance %R " "in '" __Pyx_FMT_TYPENAME "'", + value_type_name, key, type_name); +#else + "Error calling __set_name__ on '" __Pyx_FMT_TYPENAME "' instance %.100s in '" __Pyx_FMT_TYPENAME "'", + value_type_name, + PyString_Check(key) ? PyString_AS_STRING(key) : "?", + type_name); +#endif + goto bad; + } else { + Py_DECREF(tmp); + } + } + else if (unlikely(PyErr_Occurred())) { + goto bad; + } + } + Py_DECREF(names_to_set); + return 0; +bad: + Py_XDECREF(names_to_set); + return -1; +} +static PyObject *__Pyx_InitSubclassPEP487(PyObject *type_obj, PyObject *mkw) { +#if CYTHON_USE_TYPE_SLOTS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + PyTypeObject *type = (PyTypeObject*) type_obj; + PyObject *mro = type->tp_mro; + Py_ssize_t i, nbases; + if (unlikely(!mro)) goto done; + (void) &__Pyx_GetBuiltinName; + Py_INCREF(mro); + nbases = PyTuple_GET_SIZE(mro); + assert(PyTuple_GET_ITEM(mro, 0) == type_obj); + for (i = 1; i < nbases-1; i++) { + PyObject *base, *dict, *meth; + base = PyTuple_GET_ITEM(mro, i); + dict = ((PyTypeObject *)base)->tp_dict; + meth = __Pyx_PyDict_GetItemStrWithError(dict, __pyx_n_s_init_subclass); + if (unlikely(meth)) { + descrgetfunc f = Py_TYPE(meth)->tp_descr_get; + PyObject *res; + Py_INCREF(meth); + if (likely(f)) { + res = f(meth, NULL, type_obj); + Py_DECREF(meth); + if (unlikely(!res)) goto bad; + meth = res; + } + res = __Pyx_PyObject_FastCallDict(meth, NULL, 0, mkw); + Py_DECREF(meth); + if (unlikely(!res)) goto bad; + Py_DECREF(res); + goto done; + } else if (unlikely(PyErr_Occurred())) { + goto bad; + } + } +done: + Py_XDECREF(mro); + return type_obj; +bad: + Py_XDECREF(mro); + Py_DECREF(type_obj); + return NULL; +#else + PyObject *super_type, *super, *func, *res; +#if CYTHON_COMPILING_IN_PYPY && !defined(PySuper_Type) + super_type = __Pyx_GetBuiltinName(__pyx_n_s_super); +#else + super_type = (PyObject*) &PySuper_Type; + (void) &__Pyx_GetBuiltinName; +#endif + super = likely(super_type) ? __Pyx_PyObject_Call2Args(super_type, type_obj, type_obj) : NULL; +#if CYTHON_COMPILING_IN_PYPY && !defined(PySuper_Type) + Py_XDECREF(super_type); +#endif + if (unlikely(!super)) { + Py_CLEAR(type_obj); + goto done; + } + func = __Pyx_PyObject_GetAttrStrNoError(super, __pyx_n_s_init_subclass); + Py_DECREF(super); + if (likely(!func)) { + if (unlikely(PyErr_Occurred())) + Py_CLEAR(type_obj); + goto done; + } + res = __Pyx_PyObject_FastCallDict(func, NULL, 0, mkw); + Py_DECREF(func); + if (unlikely(!res)) + Py_CLEAR(type_obj); + Py_XDECREF(res); +done: + return type_obj; +#endif +} +#endif +static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, + PyObject *dict, PyObject *mkw, + int calculate_metaclass, int allow_py2_metaclass) { + PyObject *result; + PyObject *owned_metaclass = NULL; + PyObject *margs[4] = {NULL, name, bases, dict}; + if (allow_py2_metaclass) { + owned_metaclass = PyObject_GetItem(dict, __pyx_n_s_metaclass); + if (owned_metaclass) { + metaclass = owned_metaclass; + } else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) { + PyErr_Clear(); + } else { + return NULL; + } + } + if (calculate_metaclass && (!metaclass || PyType_Check(metaclass))) { + metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases); + Py_XDECREF(owned_metaclass); + if (unlikely(!metaclass)) + return NULL; + owned_metaclass = metaclass; + } + result = __Pyx_PyObject_FastCallDict(metaclass, margs+1, 3 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET, +#if PY_VERSION_HEX < 0x030600A4 + (metaclass == (PyObject*)&PyType_Type) ? NULL : mkw +#else + mkw +#endif + ); + Py_XDECREF(owned_metaclass); +#if PY_VERSION_HEX < 0x030600A4 && CYTHON_PEP487_INIT_SUBCLASS + if (likely(result) && likely(PyType_Check(result))) { + if (unlikely(__Pyx_SetNamesPEP487(result) < 0)) { + Py_CLEAR(result); + } else { + result = __Pyx_InitSubclassPEP487(result, mkw); + } + } +#else + (void) &__Pyx_GetBuiltinName; +#endif + return result; +} + +/* CLineInTraceback */ + #ifndef CYTHON_CLINE_IN_TRACEBACK +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line) { + PyObject *use_cline; + PyObject *ptype, *pvalue, *ptraceback; +#if CYTHON_COMPILING_IN_CPYTHON + PyObject **cython_runtime_dict; +#endif + CYTHON_MAYBE_UNUSED_VAR(tstate); + if (unlikely(!__pyx_cython_runtime)) { + return c_line; + } + __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); +#if CYTHON_COMPILING_IN_CPYTHON + cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime); + if (likely(cython_runtime_dict)) { + __PYX_PY_DICT_LOOKUP_IF_MODIFIED( + use_cline, *cython_runtime_dict, + __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback)) + } else +#endif + { + PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStrNoError(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback); + if (use_cline_obj) { + use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True; + Py_DECREF(use_cline_obj); + } else { + PyErr_Clear(); + use_cline = NULL; + } + } + if (!use_cline) { + c_line = 0; + (void) PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False); + } + else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) { + c_line = 0; + } + __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); + return c_line; +} +#endif + +/* CodeObjectCache */ + #if !CYTHON_COMPILING_IN_LIMITED_API +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { + int start = 0, mid = 0, end = count - 1; + if (end >= 0 && code_line > entries[end].code_line) { + return count; + } + while (start < end) { + mid = start + (end - start) / 2; + if (code_line < entries[mid].code_line) { + end = mid; + } else if (code_line > entries[mid].code_line) { + start = mid + 1; + } else { + return mid; + } + } + if (code_line <= entries[mid].code_line) { + return mid; + } else { + return mid + 1; + } +} +static PyCodeObject *__pyx_find_code_object(int code_line) { + PyCodeObject* code_object; + int pos; + if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { + return NULL; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { + return NULL; + } + code_object = __pyx_code_cache.entries[pos].code_object; + Py_INCREF(code_object); + return code_object; +} +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { + int pos, i; + __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; + if (unlikely(!code_line)) { + return; + } + if (unlikely(!entries)) { + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); + if (likely(entries)) { + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = 64; + __pyx_code_cache.count = 1; + entries[0].code_line = code_line; + entries[0].code_object = code_object; + Py_INCREF(code_object); + } + return; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { + PyCodeObject* tmp = entries[pos].code_object; + entries[pos].code_object = code_object; + Py_DECREF(tmp); + return; + } + if (__pyx_code_cache.count == __pyx_code_cache.max_count) { + int new_max = __pyx_code_cache.max_count + 64; + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( + __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry)); + if (unlikely(!entries)) { + return; + } + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = new_max; + } + for (i=__pyx_code_cache.count; i>pos; i--) { + entries[i] = entries[i-1]; + } + entries[pos].code_line = code_line; + entries[pos].code_object = code_object; + __pyx_code_cache.count++; + Py_INCREF(code_object); +} +#endif + +/* AddTraceback */ + #include "compile.h" +#include "frameobject.h" +#include "traceback.h" +#if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API + #ifndef Py_BUILD_CORE + #define Py_BUILD_CORE 1 + #endif + #include "internal/pycore_frame.h" +#endif +#if CYTHON_COMPILING_IN_LIMITED_API +static PyObject *__Pyx_PyCode_Replace_For_AddTraceback(PyObject *code, PyObject *scratch_dict, + PyObject *firstlineno, PyObject *name) { + PyObject *replace = NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "co_firstlineno", firstlineno))) return NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "co_name", name))) return NULL; + replace = PyObject_GetAttrString(code, "replace"); + if (likely(replace)) { + PyObject *result; + result = PyObject_Call(replace, __pyx_empty_tuple, scratch_dict); + Py_DECREF(replace); + return result; + } + PyErr_Clear(); + #if __PYX_LIMITED_VERSION_HEX < 0x030780000 + { + PyObject *compiled = NULL, *result = NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "code", code))) return NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "type", (PyObject*)(&PyType_Type)))) return NULL; + compiled = Py_CompileString( + "out = type(code)(\n" + " code.co_argcount, code.co_kwonlyargcount, code.co_nlocals, code.co_stacksize,\n" + " code.co_flags, code.co_code, code.co_consts, code.co_names,\n" + " code.co_varnames, code.co_filename, co_name, co_firstlineno,\n" + " code.co_lnotab)\n", "", Py_file_input); + if (!compiled) return NULL; + result = PyEval_EvalCode(compiled, scratch_dict, scratch_dict); + Py_DECREF(compiled); + if (!result) PyErr_Print(); + Py_DECREF(result); + result = PyDict_GetItemString(scratch_dict, "out"); + if (result) Py_INCREF(result); + return result; + } + #else + return NULL; + #endif +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyObject *code_object = NULL, *py_py_line = NULL, *py_funcname = NULL, *dict = NULL; + PyObject *replace = NULL, *getframe = NULL, *frame = NULL; + PyObject *exc_type, *exc_value, *exc_traceback; + int success = 0; + if (c_line) { + (void) __pyx_cfilenm; + (void) __Pyx_CLineForTraceback(__Pyx_PyThreadState_Current, c_line); + } + PyErr_Fetch(&exc_type, &exc_value, &exc_traceback); + code_object = Py_CompileString("_getframe()", filename, Py_eval_input); + if (unlikely(!code_object)) goto bad; + py_py_line = PyLong_FromLong(py_line); + if (unlikely(!py_py_line)) goto bad; + py_funcname = PyUnicode_FromString(funcname); + if (unlikely(!py_funcname)) goto bad; + dict = PyDict_New(); + if (unlikely(!dict)) goto bad; + { + PyObject *old_code_object = code_object; + code_object = __Pyx_PyCode_Replace_For_AddTraceback(code_object, dict, py_py_line, py_funcname); + Py_DECREF(old_code_object); + } + if (unlikely(!code_object)) goto bad; + getframe = PySys_GetObject("_getframe"); + if (unlikely(!getframe)) goto bad; + if (unlikely(PyDict_SetItemString(dict, "_getframe", getframe))) goto bad; + frame = PyEval_EvalCode(code_object, dict, dict); + if (unlikely(!frame) || frame == Py_None) goto bad; + success = 1; + bad: + PyErr_Restore(exc_type, exc_value, exc_traceback); + Py_XDECREF(code_object); + Py_XDECREF(py_py_line); + Py_XDECREF(py_funcname); + Py_XDECREF(dict); + Py_XDECREF(replace); + if (success) { + PyTraceBack_Here( + (struct _frame*)frame); + } + Py_XDECREF(frame); +} +#else +static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( + const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = NULL; + PyObject *py_funcname = NULL; + #if PY_MAJOR_VERSION < 3 + PyObject *py_srcfile = NULL; + py_srcfile = PyString_FromString(filename); + if (!py_srcfile) goto bad; + #endif + if (c_line) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + if (!py_funcname) goto bad; + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + if (!py_funcname) goto bad; + funcname = PyUnicode_AsUTF8(py_funcname); + if (!funcname) goto bad; + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + if (!py_funcname) goto bad; + #endif + } + #if PY_MAJOR_VERSION < 3 + py_code = __Pyx_PyCode_New( + 0, + 0, + 0, + 0, + 0, + 0, + __pyx_empty_bytes, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + py_line, + __pyx_empty_bytes /*PyObject *lnotab*/ + ); + Py_DECREF(py_srcfile); + #else + py_code = PyCode_NewEmpty(filename, funcname, py_line); + #endif + Py_XDECREF(py_funcname); + return py_code; +bad: + Py_XDECREF(py_funcname); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(py_srcfile); + #endif + return NULL; +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject *ptype, *pvalue, *ptraceback; + if (c_line) { + c_line = __Pyx_CLineForTraceback(tstate, c_line); + } + py_code = __pyx_find_code_object(c_line ? -c_line : py_line); + if (!py_code) { + __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); + py_code = __Pyx_CreateCodeObjectForTraceback( + funcname, c_line, py_line, filename); + if (!py_code) { + /* If the code object creation fails, then we should clear the + fetched exception references and propagate the new exception */ + Py_XDECREF(ptype); + Py_XDECREF(pvalue); + Py_XDECREF(ptraceback); + goto bad; + } + __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); + __pyx_insert_code_object(c_line ? -c_line : py_line, py_code); + } + py_frame = PyFrame_New( + tstate, /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + __pyx_d, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + __Pyx_PyFrame_SetLineNumber(py_frame, py_line); + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} +#endif + +/* FormatTypeName */ + #if CYTHON_COMPILING_IN_LIMITED_API +static __Pyx_TypeName +__Pyx_PyType_GetName(PyTypeObject* tp) +{ + PyObject *name = __Pyx_PyObject_GetAttrStr((PyObject *)tp, + __pyx_n_s_name); + if (unlikely(name == NULL) || unlikely(!PyUnicode_Check(name))) { + PyErr_Clear(); + Py_XDECREF(name); + name = __Pyx_NewRef(__pyx_n_s__7); + } + return name; +} +#endif + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(long) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(long) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + unsigned char *bytes = (unsigned char *)&value; +#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4 + if (is_unsigned) { + return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1); + } else { + return PyLong_FromNativeBytes(bytes, sizeof(value), -1); + } +#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000 + int one = 1; int little = (int)*(unsigned char *)&one; + return _PyLong_FromByteArray(bytes, sizeof(long), + little, !is_unsigned); +#else + int one = 1; int little = (int)*(unsigned char *)&one; + PyObject *from_bytes, *result = NULL; + PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL; + from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes"); + if (!from_bytes) return NULL; + py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(long)); + if (!py_bytes) goto limited_bad; + order_str = PyUnicode_FromString(little ? "little" : "big"); + if (!order_str) goto limited_bad; + arg_tuple = PyTuple_Pack(2, py_bytes, order_str); + if (!arg_tuple) goto limited_bad; + if (!is_unsigned) { + kwds = PyDict_New(); + if (!kwds) goto limited_bad; + if (PyDict_SetItemString(kwds, "signed", __Pyx_NewRef(Py_True))) goto limited_bad; + } + result = PyObject_Call(from_bytes, arg_tuple, kwds); + limited_bad: + Py_XDECREF(kwds); + Py_XDECREF(arg_tuple); + Py_XDECREF(order_str); + Py_XDECREF(py_bytes); + Py_XDECREF(from_bytes); + return result; +#endif + } +} + +/* CIntFromPyVerify */ + #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) +#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) +#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ + {\ + func_type value = func_value;\ + if (sizeof(target_type) < sizeof(func_type)) {\ + if (unlikely(value != (func_type) (target_type) value)) {\ + func_type zero = 0;\ + if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ + return (target_type) -1;\ + if (is_unsigned && unlikely(value < zero))\ + goto raise_neg_overflow;\ + else\ + goto raise_overflow;\ + }\ + }\ + return (target_type) value;\ + } + +/* CIntFromPy */ + static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if ((sizeof(long) < sizeof(long))) { + __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (long) val; + } + } +#endif + if (unlikely(!PyLong_Check(x))) { + long val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (long) -1; + val = __Pyx_PyInt_As_long(tmp); + Py_DECREF(tmp); + return val; + } + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + if (unlikely(__Pyx_PyLong_IsNeg(x))) { + goto raise_neg_overflow; + } else if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_DigitCount(x)) { + case 2: + if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) >= 2 * PyLong_SHIFT)) { + return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 3: + if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) >= 3 * PyLong_SHIFT)) { + return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 4: + if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) >= 4 * PyLong_SHIFT)) { + return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + } + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7 + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (long) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if ((sizeof(long) <= sizeof(unsigned long))) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(long) <= sizeof(unsigned PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_SignedDigitCount(x)) { + case -2: + if ((8 * sizeof(long) - 1 > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) { + return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 2: + if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) { + return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -3: + if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) { + return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 3: + if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) { + return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -4: + if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) { + return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 4: + if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) { + return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + } + } +#endif + if ((sizeof(long) <= sizeof(long))) { + __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(long) <= sizeof(PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { + long val; + int ret = -1; +#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API + Py_ssize_t bytes_copied = PyLong_AsNativeBytes( + x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0)); + if (unlikely(bytes_copied == -1)) { + } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) { + goto raise_overflow; + } else { + ret = 0; + } +#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray) + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + ret = _PyLong_AsByteArray((PyLongObject *)x, + bytes, sizeof(val), + is_little, !is_unsigned); +#else + PyObject *v; + PyObject *stepval = NULL, *mask = NULL, *shift = NULL; + int bits, remaining_bits, is_negative = 0; + int chunk_size = (sizeof(long) < 8) ? 30 : 62; + if (likely(PyLong_CheckExact(x))) { + v = __Pyx_NewRef(x); + } else { + v = PyNumber_Long(x); + if (unlikely(!v)) return (long) -1; + assert(PyLong_CheckExact(v)); + } + { + int result = PyObject_RichCompareBool(v, Py_False, Py_LT); + if (unlikely(result < 0)) { + Py_DECREF(v); + return (long) -1; + } + is_negative = result == 1; + } + if (is_unsigned && unlikely(is_negative)) { + Py_DECREF(v); + goto raise_neg_overflow; + } else if (is_negative) { + stepval = PyNumber_Invert(v); + Py_DECREF(v); + if (unlikely(!stepval)) + return (long) -1; + } else { + stepval = v; + } + v = NULL; + val = (long) 0; + mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done; + shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done; + for (bits = 0; bits < (int) sizeof(long) * 8 - chunk_size; bits += chunk_size) { + PyObject *tmp, *digit; + long idigit; + digit = PyNumber_And(stepval, mask); + if (unlikely(!digit)) goto done; + idigit = PyLong_AsLong(digit); + Py_DECREF(digit); + if (unlikely(idigit < 0)) goto done; + val |= ((long) idigit) << bits; + tmp = PyNumber_Rshift(stepval, shift); + if (unlikely(!tmp)) goto done; + Py_DECREF(stepval); stepval = tmp; + } + Py_DECREF(shift); shift = NULL; + Py_DECREF(mask); mask = NULL; + { + long idigit = PyLong_AsLong(stepval); + if (unlikely(idigit < 0)) goto done; + remaining_bits = ((int) sizeof(long) * 8) - bits - (is_unsigned ? 0 : 1); + if (unlikely(idigit >= (1L << remaining_bits))) + goto raise_overflow; + val |= ((long) idigit) << bits; + } + if (!is_unsigned) { + if (unlikely(val & (((long) 1) << (sizeof(long) * 8 - 1)))) + goto raise_overflow; + if (is_negative) + val = ~val; + } + ret = 0; + done: + Py_XDECREF(shift); + Py_XDECREF(mask); + Py_XDECREF(stepval); +#endif + if (unlikely(ret)) + return (long) -1; + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to long"); + return (long) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long) -1; +} + +/* CIntFromPy */ + static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const int neg_one = (int) -1, const_zero = (int) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if ((sizeof(int) < sizeof(long))) { + __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (int) val; + } + } +#endif + if (unlikely(!PyLong_Check(x))) { + int val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (int) -1; + val = __Pyx_PyInt_As_int(tmp); + Py_DECREF(tmp); + return val; + } + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + if (unlikely(__Pyx_PyLong_IsNeg(x))) { + goto raise_neg_overflow; + } else if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_DigitCount(x)) { + case 2: + if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) >= 2 * PyLong_SHIFT)) { + return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 3: + if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) >= 3 * PyLong_SHIFT)) { + return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 4: + if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) >= 4 * PyLong_SHIFT)) { + return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + } + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7 + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (int) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if ((sizeof(int) <= sizeof(unsigned long))) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(int) <= sizeof(unsigned PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_SignedDigitCount(x)) { + case -2: + if ((8 * sizeof(int) - 1 > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) { + return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 2: + if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) { + return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -3: + if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) { + return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 3: + if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) { + return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -4: + if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) { + return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 4: + if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) { + return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + } + } +#endif + if ((sizeof(int) <= sizeof(long))) { + __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(int) <= sizeof(PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { + int val; + int ret = -1; +#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API + Py_ssize_t bytes_copied = PyLong_AsNativeBytes( + x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0)); + if (unlikely(bytes_copied == -1)) { + } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) { + goto raise_overflow; + } else { + ret = 0; + } +#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray) + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + ret = _PyLong_AsByteArray((PyLongObject *)x, + bytes, sizeof(val), + is_little, !is_unsigned); +#else + PyObject *v; + PyObject *stepval = NULL, *mask = NULL, *shift = NULL; + int bits, remaining_bits, is_negative = 0; + int chunk_size = (sizeof(long) < 8) ? 30 : 62; + if (likely(PyLong_CheckExact(x))) { + v = __Pyx_NewRef(x); + } else { + v = PyNumber_Long(x); + if (unlikely(!v)) return (int) -1; + assert(PyLong_CheckExact(v)); + } + { + int result = PyObject_RichCompareBool(v, Py_False, Py_LT); + if (unlikely(result < 0)) { + Py_DECREF(v); + return (int) -1; + } + is_negative = result == 1; + } + if (is_unsigned && unlikely(is_negative)) { + Py_DECREF(v); + goto raise_neg_overflow; + } else if (is_negative) { + stepval = PyNumber_Invert(v); + Py_DECREF(v); + if (unlikely(!stepval)) + return (int) -1; + } else { + stepval = v; + } + v = NULL; + val = (int) 0; + mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done; + shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done; + for (bits = 0; bits < (int) sizeof(int) * 8 - chunk_size; bits += chunk_size) { + PyObject *tmp, *digit; + long idigit; + digit = PyNumber_And(stepval, mask); + if (unlikely(!digit)) goto done; + idigit = PyLong_AsLong(digit); + Py_DECREF(digit); + if (unlikely(idigit < 0)) goto done; + val |= ((int) idigit) << bits; + tmp = PyNumber_Rshift(stepval, shift); + if (unlikely(!tmp)) goto done; + Py_DECREF(stepval); stepval = tmp; + } + Py_DECREF(shift); shift = NULL; + Py_DECREF(mask); mask = NULL; + { + long idigit = PyLong_AsLong(stepval); + if (unlikely(idigit < 0)) goto done; + remaining_bits = ((int) sizeof(int) * 8) - bits - (is_unsigned ? 0 : 1); + if (unlikely(idigit >= (1L << remaining_bits))) + goto raise_overflow; + val |= ((int) idigit) << bits; + } + if (!is_unsigned) { + if (unlikely(val & (((int) 1) << (sizeof(int) * 8 - 1)))) + goto raise_overflow; + if (is_negative) + val = ~val; + } + ret = 0; + done: + Py_XDECREF(shift); + Py_XDECREF(mask); + Py_XDECREF(stepval); +#endif + if (unlikely(ret)) + return (int) -1; + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to int"); + return (int) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int"); + return (int) -1; +} + +/* FastTypeChecks */ + #if CYTHON_COMPILING_IN_CPYTHON +static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { + while (a) { + a = __Pyx_PyType_GetSlot(a, tp_base, PyTypeObject*); + if (a == b) + return 1; + } + return b == &PyBaseObject_Type; +} +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { + PyObject *mro; + if (a == b) return 1; + mro = a->tp_mro; + if (likely(mro)) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) + return 1; + } + return 0; + } + return __Pyx_InBases(a, b); +} +static CYTHON_INLINE int __Pyx_IsAnySubtype2(PyTypeObject *cls, PyTypeObject *a, PyTypeObject *b) { + PyObject *mro; + if (cls == a || cls == b) return 1; + mro = cls->tp_mro; + if (likely(mro)) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + PyObject *base = PyTuple_GET_ITEM(mro, i); + if (base == (PyObject *)a || base == (PyObject *)b) + return 1; + } + return 0; + } + return __Pyx_InBases(cls, a) || __Pyx_InBases(cls, b); +} +#if PY_MAJOR_VERSION == 2 +static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { + PyObject *exception, *value, *tb; + int res; + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&exception, &value, &tb); + res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + if (!res) { + res = PyObject_IsSubclass(err, exc_type2); + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + } + __Pyx_ErrRestore(exception, value, tb); + return res; +} +#else +static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { + if (exc_type1) { + return __Pyx_IsAnySubtype2((PyTypeObject*)err, (PyTypeObject*)exc_type1, (PyTypeObject*)exc_type2); + } else { + return __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); + } +} +#endif +static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + assert(PyExceptionClass_Check(exc_type)); + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; i= 0x030B00A4 + return Py_Version & ~0xFFUL; +#else + const char* rt_version = Py_GetVersion(); + unsigned long version = 0; + unsigned long factor = 0x01000000UL; + unsigned int digit = 0; + int i = 0; + while (factor) { + while ('0' <= rt_version[i] && rt_version[i] <= '9') { + digit = digit * 10 + (unsigned int) (rt_version[i] - '0'); + ++i; + } + version += factor * digit; + if (rt_version[i] != '.') + break; + digit = 0; + factor >>= 8; + ++i; + } + return version; +#endif +} +static int __Pyx_check_binary_version(unsigned long ct_version, unsigned long rt_version, int allow_newer) { + const unsigned long MAJOR_MINOR = 0xFFFF0000UL; + if ((rt_version & MAJOR_MINOR) == (ct_version & MAJOR_MINOR)) + return 0; + if (likely(allow_newer && (rt_version & MAJOR_MINOR) > (ct_version & MAJOR_MINOR))) + return 1; + { + char message[200]; + PyOS_snprintf(message, sizeof(message), + "compile time Python version %d.%d " + "of module '%.100s' " + "%s " + "runtime version %d.%d", + (int) (ct_version >> 24), (int) ((ct_version >> 16) & 0xFF), + __Pyx_MODULE_NAME, + (allow_newer) ? "was newer than" : "does not match", + (int) (rt_version >> 24), (int) ((rt_version >> 16) & 0xFF) + ); + return PyErr_WarnEx(NULL, message, 1); + } +} + +/* InitStrings */ + #if PY_MAJOR_VERSION >= 3 +static int __Pyx_InitString(__Pyx_StringTabEntry t, PyObject **str) { + if (t.is_unicode | t.is_str) { + if (t.intern) { + *str = PyUnicode_InternFromString(t.s); + } else if (t.encoding) { + *str = PyUnicode_Decode(t.s, t.n - 1, t.encoding, NULL); + } else { + *str = PyUnicode_FromStringAndSize(t.s, t.n - 1); + } + } else { + *str = PyBytes_FromStringAndSize(t.s, t.n - 1); + } + if (!*str) + return -1; + if (PyObject_Hash(*str) == -1) + return -1; + return 0; +} +#endif +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + #if PY_MAJOR_VERSION >= 3 + __Pyx_InitString(*t, t->p); + #else + if (t->is_unicode) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + if (!*t->p) + return -1; + if (PyObject_Hash(*t->p) == -1) + return -1; + #endif + ++t; + } + return 0; +} + +#include +static CYTHON_INLINE Py_ssize_t __Pyx_ssize_strlen(const char *s) { + size_t len = strlen(s); + if (unlikely(len > (size_t) PY_SSIZE_T_MAX)) { + PyErr_SetString(PyExc_OverflowError, "byte string is too long"); + return -1; + } + return (Py_ssize_t) len; +} +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { + Py_ssize_t len = __Pyx_ssize_strlen(c_str); + if (unlikely(len < 0)) return NULL; + return __Pyx_PyUnicode_FromStringAndSize(c_str, len); +} +static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char* c_str) { + Py_ssize_t len = __Pyx_ssize_strlen(c_str); + if (unlikely(len < 0)) return NULL; + return PyByteArray_FromStringAndSize(c_str, len); +} +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) { + Py_ssize_t ignore; + return __Pyx_PyObject_AsStringAndSize(o, &ignore); +} +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +#if !CYTHON_PEP393_ENABLED +static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + char* defenc_c; + PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); + if (!defenc) return NULL; + defenc_c = PyBytes_AS_STRING(defenc); +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + { + char* end = defenc_c + PyBytes_GET_SIZE(defenc); + char* c; + for (c = defenc_c; c < end; c++) { + if ((unsigned char) (*c) >= 128) { + PyUnicode_AsASCIIString(o); + return NULL; + } + } + } +#endif + *length = PyBytes_GET_SIZE(defenc); + return defenc_c; +} +#else +static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL; +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + if (likely(PyUnicode_IS_ASCII(o))) { + *length = PyUnicode_GET_LENGTH(o); + return PyUnicode_AsUTF8(o); + } else { + PyUnicode_AsASCIIString(o); + return NULL; + } +#else + return PyUnicode_AsUTF8AndSize(o, length); +#endif +} +#endif +#endif +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT + if ( +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + __Pyx_sys_getdefaultencoding_not_ascii && +#endif + PyUnicode_Check(o)) { + return __Pyx_PyUnicode_AsStringAndSize(o, length); + } else +#endif +#if (!CYTHON_COMPILING_IN_PYPY && !CYTHON_COMPILING_IN_LIMITED_API) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) + if (PyByteArray_Check(o)) { + *length = PyByteArray_GET_SIZE(o); + return PyByteArray_AS_STRING(o); + } else +#endif + { + char* result; + int r = PyBytes_AsStringAndSize(o, &result, length); + if (unlikely(r < 0)) { + return NULL; + } else { + return result; + } + } +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + int is_true = x == Py_True; + if (is_true | (x == Py_False) | (x == Py_None)) return is_true; + else return PyObject_IsTrue(x); +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { + int retval; + if (unlikely(!x)) return -1; + retval = __Pyx_PyObject_IsTrue(x); + Py_DECREF(x); + return retval; +} +static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) { + __Pyx_TypeName result_type_name = __Pyx_PyType_GetName(Py_TYPE(result)); +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(result)) { + if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + "__int__ returned non-int (type " __Pyx_FMT_TYPENAME "). " + "The ability to return an instance of a strict subclass of int is deprecated, " + "and may be removed in a future version of Python.", + result_type_name)) { + __Pyx_DECREF_TypeName(result_type_name); + Py_DECREF(result); + return NULL; + } + __Pyx_DECREF_TypeName(result_type_name); + return result; + } +#endif + PyErr_Format(PyExc_TypeError, + "__%.4s__ returned non-%.4s (type " __Pyx_FMT_TYPENAME ")", + type_name, type_name, result_type_name); + __Pyx_DECREF_TypeName(result_type_name); + Py_DECREF(result); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { +#if CYTHON_USE_TYPE_SLOTS + PyNumberMethods *m; +#endif + const char *name = NULL; + PyObject *res = NULL; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x) || PyLong_Check(x))) +#else + if (likely(PyLong_Check(x))) +#endif + return __Pyx_NewRef(x); +#if CYTHON_USE_TYPE_SLOTS + m = Py_TYPE(x)->tp_as_number; + #if PY_MAJOR_VERSION < 3 + if (m && m->nb_int) { + name = "int"; + res = m->nb_int(x); + } + else if (m && m->nb_long) { + name = "long"; + res = m->nb_long(x); + } + #else + if (likely(m && m->nb_int)) { + name = "int"; + res = m->nb_int(x); + } + #endif +#else + if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) { + res = PyNumber_Int(x); + } +#endif + if (likely(res)) { +#if PY_MAJOR_VERSION < 3 + if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) { +#else + if (unlikely(!PyLong_CheckExact(res))) { +#endif + return __Pyx_PyNumber_IntOrLongWrongResultType(res, name); + } + } + else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); + } + return res; +} +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject *x; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(b))) { + if (sizeof(Py_ssize_t) >= sizeof(long)) + return PyInt_AS_LONG(b); + else + return PyInt_AsSsize_t(b); + } +#endif + if (likely(PyLong_CheckExact(b))) { + #if CYTHON_USE_PYLONG_INTERNALS + if (likely(__Pyx_PyLong_IsCompact(b))) { + return __Pyx_PyLong_CompactValue(b); + } else { + const digit* digits = __Pyx_PyLong_Digits(b); + const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount(b); + switch (size) { + case 2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + } + } + #endif + return PyLong_AsSsize_t(b); + } + x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} +static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject* o) { + if (sizeof(Py_hash_t) == sizeof(Py_ssize_t)) { + return (Py_hash_t) __Pyx_PyIndex_AsSsize_t(o); +#if PY_MAJOR_VERSION < 3 + } else if (likely(PyInt_CheckExact(o))) { + return PyInt_AS_LONG(o); +#endif + } else { + Py_ssize_t ival; + PyObject *x; + x = PyNumber_Index(o); + if (!x) return -1; + ival = PyInt_AsLong(x); + Py_DECREF(x); + return ival; + } +} +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) { + return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False); +} +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { + return PyInt_FromSize_t(ival); +} + + +/* #### Code section: utility_code_pragmas_end ### */ +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + + + +/* #### Code section: end ### */ +#endif /* Py_PYTHON_H */ diff --git a/bot/build/cython_code/user_check.c b/bot/build/cython_code/user_check.c new file mode 100644 index 0000000..ffcf092 --- /dev/null +++ b/bot/build/cython_code/user_check.c @@ -0,0 +1,12191 @@ +/* Generated by Cython 3.0.11 */ + +/* BEGIN: Cython Metadata +{ + "distutils": { + "name": "cython_code.user_check", + "sources": [ + "cython_code/user_check.pyx" + ] + }, + "module_name": "cython_code.user_check" +} +END: Cython Metadata */ + +#ifndef PY_SSIZE_T_CLEAN +#define PY_SSIZE_T_CLEAN +#endif /* PY_SSIZE_T_CLEAN */ +#if defined(CYTHON_LIMITED_API) && 0 + #ifndef Py_LIMITED_API + #if CYTHON_LIMITED_API+0 > 0x03030000 + #define Py_LIMITED_API CYTHON_LIMITED_API + #else + #define Py_LIMITED_API 0x03030000 + #endif + #endif +#endif + +#include "Python.h" +#ifndef Py_PYTHON_H + #error Python headers needed to compile C extensions, please install development version of Python. +#elif PY_VERSION_HEX < 0x02070000 || (0x03000000 <= PY_VERSION_HEX && PY_VERSION_HEX < 0x03030000) + #error Cython requires Python 2.7+ or Python 3.3+. +#else +#if defined(CYTHON_LIMITED_API) && CYTHON_LIMITED_API +#define __PYX_EXTRA_ABI_MODULE_NAME "limited" +#else +#define __PYX_EXTRA_ABI_MODULE_NAME "" +#endif +#define CYTHON_ABI "3_0_11" __PYX_EXTRA_ABI_MODULE_NAME +#define __PYX_ABI_MODULE_NAME "_cython_" CYTHON_ABI +#define __PYX_TYPE_MODULE_PREFIX __PYX_ABI_MODULE_NAME "." +#define CYTHON_HEX_VERSION 0x03000BF0 +#define CYTHON_FUTURE_DIVISION 1 +#include +#ifndef offsetof + #define offsetof(type, member) ( (size_t) & ((type*)0) -> member ) +#endif +#if !defined(_WIN32) && !defined(WIN32) && !defined(MS_WINDOWS) + #ifndef __stdcall + #define __stdcall + #endif + #ifndef __cdecl + #define __cdecl + #endif + #ifndef __fastcall + #define __fastcall + #endif +#endif +#ifndef DL_IMPORT + #define DL_IMPORT(t) t +#endif +#ifndef DL_EXPORT + #define DL_EXPORT(t) t +#endif +#define __PYX_COMMA , +#ifndef HAVE_LONG_LONG + #define HAVE_LONG_LONG +#endif +#ifndef PY_LONG_LONG + #define PY_LONG_LONG LONG_LONG +#endif +#ifndef Py_HUGE_VAL + #define Py_HUGE_VAL HUGE_VAL +#endif +#define __PYX_LIMITED_VERSION_HEX PY_VERSION_HEX +#if defined(GRAALVM_PYTHON) + /* For very preliminary testing purposes. Most variables are set the same as PyPy. + The existence of this section does not imply that anything works or is even tested */ + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 1 + #define CYTHON_COMPILING_IN_NOGIL 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #undef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS (PY_MAJOR_VERSION >= 3) + #endif + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #undef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #endif + #undef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 +#elif defined(PYPY_VERSION) + #define CYTHON_COMPILING_IN_PYPY 1 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #ifndef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #undef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 1 + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #undef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS (PY_MAJOR_VERSION >= 3) + #endif + #if PY_VERSION_HEX < 0x03090000 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #elif !defined(CYTHON_PEP489_MULTI_PHASE_INIT) + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #undef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE (PY_VERSION_HEX >= 0x030400a1 && PYPY_VERSION_NUM >= 0x07030C00) + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #endif + #undef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 +#elif defined(CYTHON_LIMITED_API) + #ifdef Py_LIMITED_API + #undef __PYX_LIMITED_VERSION_HEX + #define __PYX_LIMITED_VERSION_HEX Py_LIMITED_API + #endif + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 1 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 0 + #undef CYTHON_CLINE_IN_TRACEBACK + #define CYTHON_CLINE_IN_TRACEBACK 0 + #undef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 0 + #undef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 1 + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #undef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #endif + #undef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #undef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 0 + #undef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 0 + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #undef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 0 + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS 1 + #endif + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #undef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 1 + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #endif + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 0 + #endif + #undef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 +#elif defined(Py_GIL_DISABLED) || defined(Py_NOGIL) + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 0 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 1 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #ifndef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #endif + #undef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 0 + #ifndef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #ifndef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 0 + #endif + #undef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 0 + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #undef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 0 + #undef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL 0 + #ifndef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL 1 + #endif + #undef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 0 + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS 1 + #endif + #ifndef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #ifndef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #endif + #ifndef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 1 + #endif + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 1 + #endif + #ifndef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 0 + #endif +#else + #define CYTHON_COMPILING_IN_PYPY 0 + #define CYTHON_COMPILING_IN_CPYTHON 1 + #define CYTHON_COMPILING_IN_LIMITED_API 0 + #define CYTHON_COMPILING_IN_GRAAL 0 + #define CYTHON_COMPILING_IN_NOGIL 0 + #ifndef CYTHON_USE_TYPE_SLOTS + #define CYTHON_USE_TYPE_SLOTS 1 + #endif + #ifndef CYTHON_USE_TYPE_SPECS + #define CYTHON_USE_TYPE_SPECS 0 + #endif + #ifndef CYTHON_USE_PYTYPE_LOOKUP + #define CYTHON_USE_PYTYPE_LOOKUP 1 + #endif + #if PY_MAJOR_VERSION < 3 + #undef CYTHON_USE_ASYNC_SLOTS + #define CYTHON_USE_ASYNC_SLOTS 0 + #elif !defined(CYTHON_USE_ASYNC_SLOTS) + #define CYTHON_USE_ASYNC_SLOTS 1 + #endif + #ifndef CYTHON_USE_PYLONG_INTERNALS + #define CYTHON_USE_PYLONG_INTERNALS 1 + #endif + #ifndef CYTHON_USE_PYLIST_INTERNALS + #define CYTHON_USE_PYLIST_INTERNALS 1 + #endif + #ifndef CYTHON_USE_UNICODE_INTERNALS + #define CYTHON_USE_UNICODE_INTERNALS 1 + #endif + #if PY_VERSION_HEX < 0x030300F0 || PY_VERSION_HEX >= 0x030B00A2 + #undef CYTHON_USE_UNICODE_WRITER + #define CYTHON_USE_UNICODE_WRITER 0 + #elif !defined(CYTHON_USE_UNICODE_WRITER) + #define CYTHON_USE_UNICODE_WRITER 1 + #endif + #ifndef CYTHON_AVOID_BORROWED_REFS + #define CYTHON_AVOID_BORROWED_REFS 0 + #endif + #ifndef CYTHON_ASSUME_SAFE_MACROS + #define CYTHON_ASSUME_SAFE_MACROS 1 + #endif + #ifndef CYTHON_UNPACK_METHODS + #define CYTHON_UNPACK_METHODS 1 + #endif + #ifndef CYTHON_FAST_THREAD_STATE + #define CYTHON_FAST_THREAD_STATE 1 + #endif + #ifndef CYTHON_FAST_GIL + #define CYTHON_FAST_GIL (PY_MAJOR_VERSION < 3 || PY_VERSION_HEX >= 0x03060000 && PY_VERSION_HEX < 0x030C00A6) + #endif + #ifndef CYTHON_METH_FASTCALL + #define CYTHON_METH_FASTCALL (PY_VERSION_HEX >= 0x030700A1) + #endif + #ifndef CYTHON_FAST_PYCALL + #define CYTHON_FAST_PYCALL 1 + #endif + #ifndef CYTHON_PEP487_INIT_SUBCLASS + #define CYTHON_PEP487_INIT_SUBCLASS 1 + #endif + #if PY_VERSION_HEX < 0x03050000 + #undef CYTHON_PEP489_MULTI_PHASE_INIT + #define CYTHON_PEP489_MULTI_PHASE_INIT 0 + #elif !defined(CYTHON_PEP489_MULTI_PHASE_INIT) + #define CYTHON_PEP489_MULTI_PHASE_INIT 1 + #endif + #ifndef CYTHON_USE_MODULE_STATE + #define CYTHON_USE_MODULE_STATE 0 + #endif + #if PY_VERSION_HEX < 0x030400a1 + #undef CYTHON_USE_TP_FINALIZE + #define CYTHON_USE_TP_FINALIZE 0 + #elif !defined(CYTHON_USE_TP_FINALIZE) + #define CYTHON_USE_TP_FINALIZE 1 + #endif + #if PY_VERSION_HEX < 0x030600B1 + #undef CYTHON_USE_DICT_VERSIONS + #define CYTHON_USE_DICT_VERSIONS 0 + #elif !defined(CYTHON_USE_DICT_VERSIONS) + #define CYTHON_USE_DICT_VERSIONS (PY_VERSION_HEX < 0x030C00A5) + #endif + #if PY_VERSION_HEX < 0x030700A3 + #undef CYTHON_USE_EXC_INFO_STACK + #define CYTHON_USE_EXC_INFO_STACK 0 + #elif !defined(CYTHON_USE_EXC_INFO_STACK) + #define CYTHON_USE_EXC_INFO_STACK 1 + #endif + #ifndef CYTHON_UPDATE_DESCRIPTOR_DOC + #define CYTHON_UPDATE_DESCRIPTOR_DOC 1 + #endif + #ifndef CYTHON_USE_FREELISTS + #define CYTHON_USE_FREELISTS 1 + #endif +#endif +#if !defined(CYTHON_FAST_PYCCALL) +#define CYTHON_FAST_PYCCALL (CYTHON_FAST_PYCALL && PY_VERSION_HEX >= 0x030600B1) +#endif +#if !defined(CYTHON_VECTORCALL) +#define CYTHON_VECTORCALL (CYTHON_FAST_PYCCALL && PY_VERSION_HEX >= 0x030800B1) +#endif +#define CYTHON_BACKPORT_VECTORCALL (CYTHON_METH_FASTCALL && PY_VERSION_HEX < 0x030800B1) +#if CYTHON_USE_PYLONG_INTERNALS + #if PY_MAJOR_VERSION < 3 + #include "longintrepr.h" + #endif + #undef SHIFT + #undef BASE + #undef MASK + #ifdef SIZEOF_VOID_P + enum { __pyx_check_sizeof_voidp = 1 / (int)(SIZEOF_VOID_P == sizeof(void*)) }; + #endif +#endif +#ifndef __has_attribute + #define __has_attribute(x) 0 +#endif +#ifndef __has_cpp_attribute + #define __has_cpp_attribute(x) 0 +#endif +#ifndef CYTHON_RESTRICT + #if defined(__GNUC__) + #define CYTHON_RESTRICT __restrict__ + #elif defined(_MSC_VER) && _MSC_VER >= 1400 + #define CYTHON_RESTRICT __restrict + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_RESTRICT restrict + #else + #define CYTHON_RESTRICT + #endif +#endif +#ifndef CYTHON_UNUSED + #if defined(__cplusplus) + /* for clang __has_cpp_attribute(maybe_unused) is true even before C++17 + * but leads to warnings with -pedantic, since it is a C++17 feature */ + #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) + #if __has_cpp_attribute(maybe_unused) + #define CYTHON_UNUSED [[maybe_unused]] + #endif + #endif + #endif +#endif +#ifndef CYTHON_UNUSED +# if defined(__GNUC__) +# if !(defined(__cplusplus)) || (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 4)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +# elif defined(__ICC) || (defined(__INTEL_COMPILER) && !defined(_MSC_VER)) +# define CYTHON_UNUSED __attribute__ ((__unused__)) +# else +# define CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_UNUSED_VAR +# if defined(__cplusplus) + template void CYTHON_UNUSED_VAR( const T& ) { } +# else +# define CYTHON_UNUSED_VAR(x) (void)(x) +# endif +#endif +#ifndef CYTHON_MAYBE_UNUSED_VAR + #define CYTHON_MAYBE_UNUSED_VAR(x) CYTHON_UNUSED_VAR(x) +#endif +#ifndef CYTHON_NCP_UNUSED +# if CYTHON_COMPILING_IN_CPYTHON +# define CYTHON_NCP_UNUSED +# else +# define CYTHON_NCP_UNUSED CYTHON_UNUSED +# endif +#endif +#ifndef CYTHON_USE_CPP_STD_MOVE + #if defined(__cplusplus) && (\ + __cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1600)) + #define CYTHON_USE_CPP_STD_MOVE 1 + #else + #define CYTHON_USE_CPP_STD_MOVE 0 + #endif +#endif +#define __Pyx_void_to_None(void_result) ((void)(void_result), Py_INCREF(Py_None), Py_None) +#ifdef _MSC_VER + #ifndef _MSC_STDINT_H_ + #if _MSC_VER < 1300 + typedef unsigned char uint8_t; + typedef unsigned short uint16_t; + typedef unsigned int uint32_t; + #else + typedef unsigned __int8 uint8_t; + typedef unsigned __int16 uint16_t; + typedef unsigned __int32 uint32_t; + #endif + #endif + #if _MSC_VER < 1300 + #ifdef _WIN64 + typedef unsigned long long __pyx_uintptr_t; + #else + typedef unsigned int __pyx_uintptr_t; + #endif + #else + #ifdef _WIN64 + typedef unsigned __int64 __pyx_uintptr_t; + #else + typedef unsigned __int32 __pyx_uintptr_t; + #endif + #endif +#else + #include + typedef uintptr_t __pyx_uintptr_t; +#endif +#ifndef CYTHON_FALLTHROUGH + #if defined(__cplusplus) + /* for clang __has_cpp_attribute(fallthrough) is true even before C++17 + * but leads to warnings with -pedantic, since it is a C++17 feature */ + #if ((defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) || __cplusplus >= 201703L) + #if __has_cpp_attribute(fallthrough) + #define CYTHON_FALLTHROUGH [[fallthrough]] + #endif + #endif + #ifndef CYTHON_FALLTHROUGH + #if __has_cpp_attribute(clang::fallthrough) + #define CYTHON_FALLTHROUGH [[clang::fallthrough]] + #elif __has_cpp_attribute(gnu::fallthrough) + #define CYTHON_FALLTHROUGH [[gnu::fallthrough]] + #endif + #endif + #endif + #ifndef CYTHON_FALLTHROUGH + #if __has_attribute(fallthrough) + #define CYTHON_FALLTHROUGH __attribute__((fallthrough)) + #else + #define CYTHON_FALLTHROUGH + #endif + #endif + #if defined(__clang__) && defined(__apple_build_version__) + #if __apple_build_version__ < 7000000 + #undef CYTHON_FALLTHROUGH + #define CYTHON_FALLTHROUGH + #endif + #endif +#endif +#ifdef __cplusplus + template + struct __PYX_IS_UNSIGNED_IMPL {static const bool value = T(0) < T(-1);}; + #define __PYX_IS_UNSIGNED(type) (__PYX_IS_UNSIGNED_IMPL::value) +#else + #define __PYX_IS_UNSIGNED(type) (((type)-1) > 0) +#endif +#if CYTHON_COMPILING_IN_PYPY == 1 + #define __PYX_NEED_TP_PRINT_SLOT (PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x030A0000) +#else + #define __PYX_NEED_TP_PRINT_SLOT (PY_VERSION_HEX >= 0x030800b4 && PY_VERSION_HEX < 0x03090000) +#endif +#define __PYX_REINTERPRET_FUNCION(func_pointer, other_pointer) ((func_pointer)(void(*)(void))(other_pointer)) + +#ifndef CYTHON_INLINE + #if defined(__clang__) + #define CYTHON_INLINE __inline__ __attribute__ ((__unused__)) + #elif defined(__GNUC__) + #define CYTHON_INLINE __inline__ + #elif defined(_MSC_VER) + #define CYTHON_INLINE __inline + #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define CYTHON_INLINE inline + #else + #define CYTHON_INLINE + #endif +#endif + +#define __PYX_BUILD_PY_SSIZE_T "n" +#define CYTHON_FORMAT_SSIZE_T "z" +#if PY_MAJOR_VERSION < 3 + #define __Pyx_BUILTIN_MODULE_NAME "__builtin__" + #define __Pyx_DefaultClassType PyClass_Type + #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a+k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #define __Pyx_BUILTIN_MODULE_NAME "builtins" + #define __Pyx_DefaultClassType PyType_Type +#if CYTHON_COMPILING_IN_LIMITED_API + static CYTHON_INLINE PyObject* __Pyx_PyCode_New(int a, int p, int k, int l, int s, int f, + PyObject *code, PyObject *c, PyObject* n, PyObject *v, + PyObject *fv, PyObject *cell, PyObject* fn, + PyObject *name, int fline, PyObject *lnos) { + PyObject *exception_table = NULL; + PyObject *types_module=NULL, *code_type=NULL, *result=NULL; + #if __PYX_LIMITED_VERSION_HEX < 0x030B0000 + PyObject *version_info; + PyObject *py_minor_version = NULL; + #endif + long minor_version = 0; + PyObject *type, *value, *traceback; + PyErr_Fetch(&type, &value, &traceback); + #if __PYX_LIMITED_VERSION_HEX >= 0x030B0000 + minor_version = 11; + #else + if (!(version_info = PySys_GetObject("version_info"))) goto end; + if (!(py_minor_version = PySequence_GetItem(version_info, 1))) goto end; + minor_version = PyLong_AsLong(py_minor_version); + Py_DECREF(py_minor_version); + if (minor_version == -1 && PyErr_Occurred()) goto end; + #endif + if (!(types_module = PyImport_ImportModule("types"))) goto end; + if (!(code_type = PyObject_GetAttrString(types_module, "CodeType"))) goto end; + if (minor_version <= 7) { + (void)p; + result = PyObject_CallFunction(code_type, "iiiiiOOOOOOiOO", a, k, l, s, f, code, + c, n, v, fn, name, fline, lnos, fv, cell); + } else if (minor_version <= 10) { + result = PyObject_CallFunction(code_type, "iiiiiiOOOOOOiOO", a,p, k, l, s, f, code, + c, n, v, fn, name, fline, lnos, fv, cell); + } else { + if (!(exception_table = PyBytes_FromStringAndSize(NULL, 0))) goto end; + result = PyObject_CallFunction(code_type, "iiiiiiOOOOOOOiOO", a,p, k, l, s, f, code, + c, n, v, fn, name, name, fline, lnos, exception_table, fv, cell); + } + end: + Py_XDECREF(code_type); + Py_XDECREF(exception_table); + Py_XDECREF(types_module); + if (type) { + PyErr_Restore(type, value, traceback); + } + return result; + } + #ifndef CO_OPTIMIZED + #define CO_OPTIMIZED 0x0001 + #endif + #ifndef CO_NEWLOCALS + #define CO_NEWLOCALS 0x0002 + #endif + #ifndef CO_VARARGS + #define CO_VARARGS 0x0004 + #endif + #ifndef CO_VARKEYWORDS + #define CO_VARKEYWORDS 0x0008 + #endif + #ifndef CO_ASYNC_GENERATOR + #define CO_ASYNC_GENERATOR 0x0200 + #endif + #ifndef CO_GENERATOR + #define CO_GENERATOR 0x0020 + #endif + #ifndef CO_COROUTINE + #define CO_COROUTINE 0x0080 + #endif +#elif PY_VERSION_HEX >= 0x030B0000 + static CYTHON_INLINE PyCodeObject* __Pyx_PyCode_New(int a, int p, int k, int l, int s, int f, + PyObject *code, PyObject *c, PyObject* n, PyObject *v, + PyObject *fv, PyObject *cell, PyObject* fn, + PyObject *name, int fline, PyObject *lnos) { + PyCodeObject *result; + PyObject *empty_bytes = PyBytes_FromStringAndSize("", 0); + if (!empty_bytes) return NULL; + result = + #if PY_VERSION_HEX >= 0x030C0000 + PyUnstable_Code_NewWithPosOnlyArgs + #else + PyCode_NewWithPosOnlyArgs + #endif + (a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, name, fline, lnos, empty_bytes); + Py_DECREF(empty_bytes); + return result; + } +#elif PY_VERSION_HEX >= 0x030800B2 && !CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_NewWithPosOnlyArgs(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#else + #define __Pyx_PyCode_New(a, p, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos)\ + PyCode_New(a, k, l, s, f, code, c, n, v, fv, cell, fn, name, fline, lnos) +#endif +#endif +#if PY_VERSION_HEX >= 0x030900A4 || defined(Py_IS_TYPE) + #define __Pyx_IS_TYPE(ob, type) Py_IS_TYPE(ob, type) +#else + #define __Pyx_IS_TYPE(ob, type) (((const PyObject*)ob)->ob_type == (type)) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_Is) + #define __Pyx_Py_Is(x, y) Py_Is(x, y) +#else + #define __Pyx_Py_Is(x, y) ((x) == (y)) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsNone) + #define __Pyx_Py_IsNone(ob) Py_IsNone(ob) +#else + #define __Pyx_Py_IsNone(ob) __Pyx_Py_Is((ob), Py_None) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsTrue) + #define __Pyx_Py_IsTrue(ob) Py_IsTrue(ob) +#else + #define __Pyx_Py_IsTrue(ob) __Pyx_Py_Is((ob), Py_True) +#endif +#if PY_VERSION_HEX >= 0x030A00B1 || defined(Py_IsFalse) + #define __Pyx_Py_IsFalse(ob) Py_IsFalse(ob) +#else + #define __Pyx_Py_IsFalse(ob) __Pyx_Py_Is((ob), Py_False) +#endif +#define __Pyx_NoneAsNull(obj) (__Pyx_Py_IsNone(obj) ? NULL : (obj)) +#if PY_VERSION_HEX >= 0x030900F0 && !CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyObject_GC_IsFinalized(o) PyObject_GC_IsFinalized(o) +#else + #define __Pyx_PyObject_GC_IsFinalized(o) _PyGC_FINALIZED(o) +#endif +#ifndef CO_COROUTINE + #define CO_COROUTINE 0x80 +#endif +#ifndef CO_ASYNC_GENERATOR + #define CO_ASYNC_GENERATOR 0x200 +#endif +#ifndef Py_TPFLAGS_CHECKTYPES + #define Py_TPFLAGS_CHECKTYPES 0 +#endif +#ifndef Py_TPFLAGS_HAVE_INDEX + #define Py_TPFLAGS_HAVE_INDEX 0 +#endif +#ifndef Py_TPFLAGS_HAVE_NEWBUFFER + #define Py_TPFLAGS_HAVE_NEWBUFFER 0 +#endif +#ifndef Py_TPFLAGS_HAVE_FINALIZE + #define Py_TPFLAGS_HAVE_FINALIZE 0 +#endif +#ifndef Py_TPFLAGS_SEQUENCE + #define Py_TPFLAGS_SEQUENCE 0 +#endif +#ifndef Py_TPFLAGS_MAPPING + #define Py_TPFLAGS_MAPPING 0 +#endif +#ifndef METH_STACKLESS + #define METH_STACKLESS 0 +#endif +#if PY_VERSION_HEX <= 0x030700A3 || !defined(METH_FASTCALL) + #ifndef METH_FASTCALL + #define METH_FASTCALL 0x80 + #endif + typedef PyObject *(*__Pyx_PyCFunctionFast) (PyObject *self, PyObject *const *args, Py_ssize_t nargs); + typedef PyObject *(*__Pyx_PyCFunctionFastWithKeywords) (PyObject *self, PyObject *const *args, + Py_ssize_t nargs, PyObject *kwnames); +#else + #if PY_VERSION_HEX >= 0x030d00A4 + # define __Pyx_PyCFunctionFast PyCFunctionFast + # define __Pyx_PyCFunctionFastWithKeywords PyCFunctionFastWithKeywords + #else + # define __Pyx_PyCFunctionFast _PyCFunctionFast + # define __Pyx_PyCFunctionFastWithKeywords _PyCFunctionFastWithKeywords + #endif +#endif +#if CYTHON_METH_FASTCALL + #define __Pyx_METH_FASTCALL METH_FASTCALL + #define __Pyx_PyCFunction_FastCall __Pyx_PyCFunctionFast + #define __Pyx_PyCFunction_FastCallWithKeywords __Pyx_PyCFunctionFastWithKeywords +#else + #define __Pyx_METH_FASTCALL METH_VARARGS + #define __Pyx_PyCFunction_FastCall PyCFunction + #define __Pyx_PyCFunction_FastCallWithKeywords PyCFunctionWithKeywords +#endif +#if CYTHON_VECTORCALL + #define __pyx_vectorcallfunc vectorcallfunc + #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET PY_VECTORCALL_ARGUMENTS_OFFSET + #define __Pyx_PyVectorcall_NARGS(n) PyVectorcall_NARGS((size_t)(n)) +#elif CYTHON_BACKPORT_VECTORCALL + typedef PyObject *(*__pyx_vectorcallfunc)(PyObject *callable, PyObject *const *args, + size_t nargsf, PyObject *kwnames); + #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET ((size_t)1 << (8 * sizeof(size_t) - 1)) + #define __Pyx_PyVectorcall_NARGS(n) ((Py_ssize_t)(((size_t)(n)) & ~__Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET)) +#else + #define __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET 0 + #define __Pyx_PyVectorcall_NARGS(n) ((Py_ssize_t)(n)) +#endif +#if PY_MAJOR_VERSION >= 0x030900B1 +#define __Pyx_PyCFunction_CheckExact(func) PyCFunction_CheckExact(func) +#else +#define __Pyx_PyCFunction_CheckExact(func) PyCFunction_Check(func) +#endif +#define __Pyx_CyOrPyCFunction_Check(func) PyCFunction_Check(func) +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_CyOrPyCFunction_GET_FUNCTION(func) (((PyCFunctionObject*)(func))->m_ml->ml_meth) +#elif !CYTHON_COMPILING_IN_LIMITED_API +#define __Pyx_CyOrPyCFunction_GET_FUNCTION(func) PyCFunction_GET_FUNCTION(func) +#endif +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_CyOrPyCFunction_GET_FLAGS(func) (((PyCFunctionObject*)(func))->m_ml->ml_flags) +static CYTHON_INLINE PyObject* __Pyx_CyOrPyCFunction_GET_SELF(PyObject *func) { + return (__Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_STATIC) ? NULL : ((PyCFunctionObject*)func)->m_self; +} +#endif +static CYTHON_INLINE int __Pyx__IsSameCFunction(PyObject *func, void *cfunc) { +#if CYTHON_COMPILING_IN_LIMITED_API + return PyCFunction_Check(func) && PyCFunction_GetFunction(func) == (PyCFunction) cfunc; +#else + return PyCFunction_Check(func) && PyCFunction_GET_FUNCTION(func) == (PyCFunction) cfunc; +#endif +} +#define __Pyx_IsSameCFunction(func, cfunc) __Pyx__IsSameCFunction(func, cfunc) +#if __PYX_LIMITED_VERSION_HEX < 0x030900B1 + #define __Pyx_PyType_FromModuleAndSpec(m, s, b) ((void)m, PyType_FromSpecWithBases(s, b)) + typedef PyObject *(*__Pyx_PyCMethod)(PyObject *, PyTypeObject *, PyObject *const *, size_t, PyObject *); +#else + #define __Pyx_PyType_FromModuleAndSpec(m, s, b) PyType_FromModuleAndSpec(m, s, b) + #define __Pyx_PyCMethod PyCMethod +#endif +#ifndef METH_METHOD + #define METH_METHOD 0x200 +#endif +#if CYTHON_COMPILING_IN_PYPY && !defined(PyObject_Malloc) + #define PyObject_Malloc(s) PyMem_Malloc(s) + #define PyObject_Free(p) PyMem_Free(p) + #define PyObject_Realloc(p) PyMem_Realloc(p) +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) +#else + #define __Pyx_PyCode_HasFreeVars(co) (PyCode_GetNumFree(co) > 0) + #define __Pyx_PyFrame_SetLineNumber(frame, lineno) (frame)->f_lineno = (lineno) +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_PyThreadState_Current PyThreadState_Get() +#elif !CYTHON_FAST_THREAD_STATE + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#elif PY_VERSION_HEX >= 0x030d00A1 + #define __Pyx_PyThreadState_Current PyThreadState_GetUnchecked() +#elif PY_VERSION_HEX >= 0x03060000 + #define __Pyx_PyThreadState_Current _PyThreadState_UncheckedGet() +#elif PY_VERSION_HEX >= 0x03000000 + #define __Pyx_PyThreadState_Current PyThreadState_GET() +#else + #define __Pyx_PyThreadState_Current _PyThreadState_Current +#endif +#if CYTHON_COMPILING_IN_LIMITED_API +static CYTHON_INLINE void *__Pyx_PyModule_GetState(PyObject *op) +{ + void *result; + result = PyModule_GetState(op); + if (!result) + Py_FatalError("Couldn't find the module state"); + return result; +} +#endif +#define __Pyx_PyObject_GetSlot(obj, name, func_ctype) __Pyx_PyType_GetSlot(Py_TYPE(obj), name, func_ctype) +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_PyType_GetSlot(type, name, func_ctype) ((func_ctype) PyType_GetSlot((type), Py_##name)) +#else + #define __Pyx_PyType_GetSlot(type, name, func_ctype) ((type)->name) +#endif +#if PY_VERSION_HEX < 0x030700A2 && !defined(PyThread_tss_create) && !defined(Py_tss_NEEDS_INIT) +#include "pythread.h" +#define Py_tss_NEEDS_INIT 0 +typedef int Py_tss_t; +static CYTHON_INLINE int PyThread_tss_create(Py_tss_t *key) { + *key = PyThread_create_key(); + return 0; +} +static CYTHON_INLINE Py_tss_t * PyThread_tss_alloc(void) { + Py_tss_t *key = (Py_tss_t *)PyObject_Malloc(sizeof(Py_tss_t)); + *key = Py_tss_NEEDS_INIT; + return key; +} +static CYTHON_INLINE void PyThread_tss_free(Py_tss_t *key) { + PyObject_Free(key); +} +static CYTHON_INLINE int PyThread_tss_is_created(Py_tss_t *key) { + return *key != Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE void PyThread_tss_delete(Py_tss_t *key) { + PyThread_delete_key(*key); + *key = Py_tss_NEEDS_INIT; +} +static CYTHON_INLINE int PyThread_tss_set(Py_tss_t *key, void *value) { + return PyThread_set_key_value(*key, value); +} +static CYTHON_INLINE void * PyThread_tss_get(Py_tss_t *key) { + return PyThread_get_key_value(*key); +} +#endif +#if PY_MAJOR_VERSION < 3 + #if CYTHON_COMPILING_IN_PYPY + #if PYPY_VERSION_NUM < 0x07030600 + #if defined(__cplusplus) && __cplusplus >= 201402L + [[deprecated("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6")]] + #elif defined(__GNUC__) || defined(__clang__) + __attribute__ ((__deprecated__("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6"))) + #elif defined(_MSC_VER) + __declspec(deprecated("`with nogil:` inside a nogil function will not release the GIL in PyPy2 < 7.3.6")) + #endif + static CYTHON_INLINE int PyGILState_Check(void) { + return 0; + } + #else // PYPY_VERSION_NUM < 0x07030600 + #endif // PYPY_VERSION_NUM < 0x07030600 + #else + static CYTHON_INLINE int PyGILState_Check(void) { + PyThreadState * tstate = _PyThreadState_Current; + return tstate && (tstate == PyGILState_GetThisThreadState()); + } + #endif +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030d0000 || defined(_PyDict_NewPresized) +#define __Pyx_PyDict_NewPresized(n) ((n <= 8) ? PyDict_New() : _PyDict_NewPresized(n)) +#else +#define __Pyx_PyDict_NewPresized(n) PyDict_New() +#endif +#if PY_MAJOR_VERSION >= 3 || CYTHON_FUTURE_DIVISION + #define __Pyx_PyNumber_Divide(x,y) PyNumber_TrueDivide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceTrueDivide(x,y) +#else + #define __Pyx_PyNumber_Divide(x,y) PyNumber_Divide(x,y) + #define __Pyx_PyNumber_InPlaceDivide(x,y) PyNumber_InPlaceDivide(x,y) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX > 0x030600B4 && PY_VERSION_HEX < 0x030d0000 && CYTHON_USE_UNICODE_INTERNALS +#define __Pyx_PyDict_GetItemStrWithError(dict, name) _PyDict_GetItem_KnownHash(dict, name, ((PyASCIIObject *) name)->hash) +static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStr(PyObject *dict, PyObject *name) { + PyObject *res = __Pyx_PyDict_GetItemStrWithError(dict, name); + if (res == NULL) PyErr_Clear(); + return res; +} +#elif PY_MAJOR_VERSION >= 3 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07020000) +#define __Pyx_PyDict_GetItemStrWithError PyDict_GetItemWithError +#define __Pyx_PyDict_GetItemStr PyDict_GetItem +#else +static CYTHON_INLINE PyObject * __Pyx_PyDict_GetItemStrWithError(PyObject *dict, PyObject *name) { +#if CYTHON_COMPILING_IN_PYPY + return PyDict_GetItem(dict, name); +#else + PyDictEntry *ep; + PyDictObject *mp = (PyDictObject*) dict; + long hash = ((PyStringObject *) name)->ob_shash; + assert(hash != -1); + ep = (mp->ma_lookup)(mp, name, hash); + if (ep == NULL) { + return NULL; + } + return ep->me_value; +#endif +} +#define __Pyx_PyDict_GetItemStr PyDict_GetItem +#endif +#if CYTHON_USE_TYPE_SLOTS + #define __Pyx_PyType_GetFlags(tp) (((PyTypeObject *)tp)->tp_flags) + #define __Pyx_PyType_HasFeature(type, feature) ((__Pyx_PyType_GetFlags(type) & (feature)) != 0) + #define __Pyx_PyObject_GetIterNextFunc(obj) (Py_TYPE(obj)->tp_iternext) +#else + #define __Pyx_PyType_GetFlags(tp) (PyType_GetFlags((PyTypeObject *)tp)) + #define __Pyx_PyType_HasFeature(type, feature) PyType_HasFeature(type, feature) + #define __Pyx_PyObject_GetIterNextFunc(obj) PyIter_Next +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_SetItemOnTypeDict(tp, k, v) PyObject_GenericSetAttr((PyObject*)tp, k, v) +#else + #define __Pyx_SetItemOnTypeDict(tp, k, v) PyDict_SetItem(tp->tp_dict, k, v) +#endif +#if CYTHON_USE_TYPE_SPECS && PY_VERSION_HEX >= 0x03080000 +#define __Pyx_PyHeapTypeObject_GC_Del(obj) {\ + PyTypeObject *type = Py_TYPE((PyObject*)obj);\ + assert(__Pyx_PyType_HasFeature(type, Py_TPFLAGS_HEAPTYPE));\ + PyObject_GC_Del(obj);\ + Py_DECREF(type);\ +} +#else +#define __Pyx_PyHeapTypeObject_GC_Del(obj) PyObject_GC_Del(obj) +#endif +#if CYTHON_COMPILING_IN_LIMITED_API + #define CYTHON_PEP393_ENABLED 1 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GetLength(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_ReadChar(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((void)u, 1114111U) + #define __Pyx_PyUnicode_KIND(u) ((void)u, (0)) + #define __Pyx_PyUnicode_DATA(u) ((void*)u) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)k, PyUnicode_ReadChar((PyObject*)(d), i)) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GetLength(u)) +#elif PY_VERSION_HEX > 0x03030000 && defined(PyUnicode_KIND) + #define CYTHON_PEP393_ENABLED 1 + #if PY_VERSION_HEX >= 0x030C0000 + #define __Pyx_PyUnicode_READY(op) (0) + #else + #define __Pyx_PyUnicode_READY(op) (likely(PyUnicode_IS_READY(op)) ?\ + 0 : _PyUnicode_Ready((PyObject *)(op))) + #endif + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_LENGTH(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) PyUnicode_READ_CHAR(u, i) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) PyUnicode_MAX_CHAR_VALUE(u) + #define __Pyx_PyUnicode_KIND(u) ((int)PyUnicode_KIND(u)) + #define __Pyx_PyUnicode_DATA(u) PyUnicode_DATA(u) + #define __Pyx_PyUnicode_READ(k, d, i) PyUnicode_READ(k, d, i) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) PyUnicode_WRITE(k, d, i, (Py_UCS4) ch) + #if PY_VERSION_HEX >= 0x030C0000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_LENGTH(u)) + #else + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03090000 + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : ((PyCompactUnicodeObject *)(u))->wstr_length)) + #else + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != (likely(PyUnicode_IS_READY(u)) ? PyUnicode_GET_LENGTH(u) : PyUnicode_GET_SIZE(u))) + #endif + #endif +#else + #define CYTHON_PEP393_ENABLED 0 + #define PyUnicode_1BYTE_KIND 1 + #define PyUnicode_2BYTE_KIND 2 + #define PyUnicode_4BYTE_KIND 4 + #define __Pyx_PyUnicode_READY(op) (0) + #define __Pyx_PyUnicode_GET_LENGTH(u) PyUnicode_GET_SIZE(u) + #define __Pyx_PyUnicode_READ_CHAR(u, i) ((Py_UCS4)(PyUnicode_AS_UNICODE(u)[i])) + #define __Pyx_PyUnicode_MAX_CHAR_VALUE(u) ((sizeof(Py_UNICODE) == 2) ? 65535U : 1114111U) + #define __Pyx_PyUnicode_KIND(u) ((int)sizeof(Py_UNICODE)) + #define __Pyx_PyUnicode_DATA(u) ((void*)PyUnicode_AS_UNICODE(u)) + #define __Pyx_PyUnicode_READ(k, d, i) ((void)(k), (Py_UCS4)(((Py_UNICODE*)d)[i])) + #define __Pyx_PyUnicode_WRITE(k, d, i, ch) (((void)(k)), ((Py_UNICODE*)d)[i] = (Py_UNICODE) ch) + #define __Pyx_PyUnicode_IS_TRUE(u) (0 != PyUnicode_GET_SIZE(u)) +#endif +#if CYTHON_COMPILING_IN_PYPY + #define __Pyx_PyUnicode_Concat(a, b) PyNumber_Add(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) PyNumber_Add(a, b) +#else + #define __Pyx_PyUnicode_Concat(a, b) PyUnicode_Concat(a, b) + #define __Pyx_PyUnicode_ConcatSafe(a, b) ((unlikely((a) == Py_None) || unlikely((b) == Py_None)) ?\ + PyNumber_Add(a, b) : __Pyx_PyUnicode_Concat(a, b)) +#endif +#if CYTHON_COMPILING_IN_PYPY + #if !defined(PyUnicode_DecodeUnicodeEscape) + #define PyUnicode_DecodeUnicodeEscape(s, size, errors) PyUnicode_Decode(s, size, "unicode_escape", errors) + #endif + #if !defined(PyUnicode_Contains) || (PY_MAJOR_VERSION == 2 && PYPY_VERSION_NUM < 0x07030500) + #undef PyUnicode_Contains + #define PyUnicode_Contains(u, s) PySequence_Contains(u, s) + #endif + #if !defined(PyByteArray_Check) + #define PyByteArray_Check(obj) PyObject_TypeCheck(obj, &PyByteArray_Type) + #endif + #if !defined(PyObject_Format) + #define PyObject_Format(obj, fmt) PyObject_CallMethod(obj, "__format__", "O", fmt) + #endif +#endif +#define __Pyx_PyString_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyString_Check(b) && !PyString_CheckExact(b)))) ? PyNumber_Remainder(a, b) : __Pyx_PyString_Format(a, b)) +#define __Pyx_PyUnicode_FormatSafe(a, b) ((unlikely((a) == Py_None || (PyUnicode_Check(b) && !PyUnicode_CheckExact(b)))) ? PyNumber_Remainder(a, b) : PyUnicode_Format(a, b)) +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyString_Format(a, b) PyUnicode_Format(a, b) +#else + #define __Pyx_PyString_Format(a, b) PyString_Format(a, b) +#endif +#if PY_MAJOR_VERSION < 3 && !defined(PyObject_ASCII) + #define PyObject_ASCII(o) PyObject_Repr(o) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBaseString_Type PyUnicode_Type + #define PyStringObject PyUnicodeObject + #define PyString_Type PyUnicode_Type + #define PyString_Check PyUnicode_Check + #define PyString_CheckExact PyUnicode_CheckExact +#ifndef PyObject_Unicode + #define PyObject_Unicode PyObject_Str +#endif +#endif +#if PY_MAJOR_VERSION >= 3 + #define __Pyx_PyBaseString_Check(obj) PyUnicode_Check(obj) + #define __Pyx_PyBaseString_CheckExact(obj) PyUnicode_CheckExact(obj) +#else + #define __Pyx_PyBaseString_Check(obj) (PyString_Check(obj) || PyUnicode_Check(obj)) + #define __Pyx_PyBaseString_CheckExact(obj) (PyString_CheckExact(obj) || PyUnicode_CheckExact(obj)) +#endif +#if CYTHON_COMPILING_IN_CPYTHON + #define __Pyx_PySequence_ListKeepNew(obj)\ + (likely(PyList_CheckExact(obj) && Py_REFCNT(obj) == 1) ? __Pyx_NewRef(obj) : PySequence_List(obj)) +#else + #define __Pyx_PySequence_ListKeepNew(obj) PySequence_List(obj) +#endif +#ifndef PySet_CheckExact + #define PySet_CheckExact(obj) __Pyx_IS_TYPE(obj, &PySet_Type) +#endif +#if PY_VERSION_HEX >= 0x030900A4 + #define __Pyx_SET_REFCNT(obj, refcnt) Py_SET_REFCNT(obj, refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SET_SIZE(obj, size) +#else + #define __Pyx_SET_REFCNT(obj, refcnt) Py_REFCNT(obj) = (refcnt) + #define __Pyx_SET_SIZE(obj, size) Py_SIZE(obj) = (size) +#endif +#if CYTHON_ASSUME_SAFE_MACROS + #define __Pyx_PySequence_ITEM(o, i) PySequence_ITEM(o, i) + #define __Pyx_PySequence_SIZE(seq) Py_SIZE(seq) + #define __Pyx_PyTuple_SET_ITEM(o, i, v) (PyTuple_SET_ITEM(o, i, v), (0)) + #define __Pyx_PyList_SET_ITEM(o, i, v) (PyList_SET_ITEM(o, i, v), (0)) + #define __Pyx_PyTuple_GET_SIZE(o) PyTuple_GET_SIZE(o) + #define __Pyx_PyList_GET_SIZE(o) PyList_GET_SIZE(o) + #define __Pyx_PySet_GET_SIZE(o) PySet_GET_SIZE(o) + #define __Pyx_PyBytes_GET_SIZE(o) PyBytes_GET_SIZE(o) + #define __Pyx_PyByteArray_GET_SIZE(o) PyByteArray_GET_SIZE(o) +#else + #define __Pyx_PySequence_ITEM(o, i) PySequence_GetItem(o, i) + #define __Pyx_PySequence_SIZE(seq) PySequence_Size(seq) + #define __Pyx_PyTuple_SET_ITEM(o, i, v) PyTuple_SetItem(o, i, v) + #define __Pyx_PyList_SET_ITEM(o, i, v) PyList_SetItem(o, i, v) + #define __Pyx_PyTuple_GET_SIZE(o) PyTuple_Size(o) + #define __Pyx_PyList_GET_SIZE(o) PyList_Size(o) + #define __Pyx_PySet_GET_SIZE(o) PySet_Size(o) + #define __Pyx_PyBytes_GET_SIZE(o) PyBytes_Size(o) + #define __Pyx_PyByteArray_GET_SIZE(o) PyByteArray_Size(o) +#endif +#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1 + #define __Pyx_PyImport_AddModuleRef(name) PyImport_AddModuleRef(name) +#else + static CYTHON_INLINE PyObject *__Pyx_PyImport_AddModuleRef(const char *name) { + PyObject *module = PyImport_AddModule(name); + Py_XINCREF(module); + return module; + } +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyIntObject PyLongObject + #define PyInt_Type PyLong_Type + #define PyInt_Check(op) PyLong_Check(op) + #define PyInt_CheckExact(op) PyLong_CheckExact(op) + #define __Pyx_Py3Int_Check(op) PyLong_Check(op) + #define __Pyx_Py3Int_CheckExact(op) PyLong_CheckExact(op) + #define PyInt_FromString PyLong_FromString + #define PyInt_FromUnicode PyLong_FromUnicode + #define PyInt_FromLong PyLong_FromLong + #define PyInt_FromSize_t PyLong_FromSize_t + #define PyInt_FromSsize_t PyLong_FromSsize_t + #define PyInt_AsLong PyLong_AsLong + #define PyInt_AS_LONG PyLong_AS_LONG + #define PyInt_AsSsize_t PyLong_AsSsize_t + #define PyInt_AsUnsignedLongMask PyLong_AsUnsignedLongMask + #define PyInt_AsUnsignedLongLongMask PyLong_AsUnsignedLongLongMask + #define PyNumber_Int PyNumber_Long +#else + #define __Pyx_Py3Int_Check(op) (PyLong_Check(op) || PyInt_Check(op)) + #define __Pyx_Py3Int_CheckExact(op) (PyLong_CheckExact(op) || PyInt_CheckExact(op)) +#endif +#if PY_MAJOR_VERSION >= 3 + #define PyBoolObject PyLongObject +#endif +#if PY_MAJOR_VERSION >= 3 && CYTHON_COMPILING_IN_PYPY + #ifndef PyUnicode_InternFromString + #define PyUnicode_InternFromString(s) PyUnicode_FromString(s) + #endif +#endif +#if PY_VERSION_HEX < 0x030200A4 + typedef long Py_hash_t; + #define __Pyx_PyInt_FromHash_t PyInt_FromLong + #define __Pyx_PyInt_AsHash_t __Pyx_PyIndex_AsHash_t +#else + #define __Pyx_PyInt_FromHash_t PyInt_FromSsize_t + #define __Pyx_PyInt_AsHash_t __Pyx_PyIndex_AsSsize_t +#endif +#if CYTHON_USE_ASYNC_SLOTS + #if PY_VERSION_HEX >= 0x030500B1 + #define __Pyx_PyAsyncMethodsStruct PyAsyncMethods + #define __Pyx_PyType_AsAsync(obj) (Py_TYPE(obj)->tp_as_async) + #else + #define __Pyx_PyType_AsAsync(obj) ((__Pyx_PyAsyncMethodsStruct*) (Py_TYPE(obj)->tp_reserved)) + #endif +#else + #define __Pyx_PyType_AsAsync(obj) NULL +#endif +#ifndef __Pyx_PyAsyncMethodsStruct + typedef struct { + unaryfunc am_await; + unaryfunc am_aiter; + unaryfunc am_anext; + } __Pyx_PyAsyncMethodsStruct; +#endif + +#if defined(_WIN32) || defined(WIN32) || defined(MS_WINDOWS) + #if !defined(_USE_MATH_DEFINES) + #define _USE_MATH_DEFINES + #endif +#endif +#include +#ifdef NAN +#define __PYX_NAN() ((float) NAN) +#else +static CYTHON_INLINE float __PYX_NAN() { + float value; + memset(&value, 0xFF, sizeof(value)); + return value; +} +#endif +#if defined(__CYGWIN__) && defined(_LDBL_EQ_DBL) +#define __Pyx_truncl trunc +#else +#define __Pyx_truncl truncl +#endif + +#define __PYX_MARK_ERR_POS(f_index, lineno) \ + { __pyx_filename = __pyx_f[f_index]; (void)__pyx_filename; __pyx_lineno = lineno; (void)__pyx_lineno; __pyx_clineno = __LINE__; (void)__pyx_clineno; } +#define __PYX_ERR(f_index, lineno, Ln_error) \ + { __PYX_MARK_ERR_POS(f_index, lineno) goto Ln_error; } + +#ifdef CYTHON_EXTERN_C + #undef __PYX_EXTERN_C + #define __PYX_EXTERN_C CYTHON_EXTERN_C +#elif defined(__PYX_EXTERN_C) + #ifdef _MSC_VER + #pragma message ("Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead.") + #else + #warning Please do not define the '__PYX_EXTERN_C' macro externally. Use 'CYTHON_EXTERN_C' instead. + #endif +#else + #ifdef __cplusplus + #define __PYX_EXTERN_C extern "C" + #else + #define __PYX_EXTERN_C extern + #endif +#endif + +#define __PYX_HAVE__cython_code__user_check +#define __PYX_HAVE_API__cython_code__user_check +/* Early includes */ +#ifdef _OPENMP +#include +#endif /* _OPENMP */ + +#if defined(PYREX_WITHOUT_ASSERTIONS) && !defined(CYTHON_WITHOUT_ASSERTIONS) +#define CYTHON_WITHOUT_ASSERTIONS +#endif + +typedef struct {PyObject **p; const char *s; const Py_ssize_t n; const char* encoding; + const char is_unicode; const char is_str; const char intern; } __Pyx_StringTabEntry; + +#define __PYX_DEFAULT_STRING_ENCODING_IS_ASCII 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_UTF8 0 +#define __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT (PY_MAJOR_VERSION >= 3 && __PYX_DEFAULT_STRING_ENCODING_IS_UTF8) +#define __PYX_DEFAULT_STRING_ENCODING "" +#define __Pyx_PyObject_FromString __Pyx_PyBytes_FromString +#define __Pyx_PyObject_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#define __Pyx_uchar_cast(c) ((unsigned char)c) +#define __Pyx_long_cast(x) ((long)x) +#define __Pyx_fits_Py_ssize_t(v, type, is_signed) (\ + (sizeof(type) < sizeof(Py_ssize_t)) ||\ + (sizeof(type) > sizeof(Py_ssize_t) &&\ + likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX) &&\ + (!is_signed || likely(v > (type)PY_SSIZE_T_MIN ||\ + v == (type)PY_SSIZE_T_MIN))) ||\ + (sizeof(type) == sizeof(Py_ssize_t) &&\ + (is_signed || likely(v < (type)PY_SSIZE_T_MAX ||\ + v == (type)PY_SSIZE_T_MAX))) ) +static CYTHON_INLINE int __Pyx_is_valid_index(Py_ssize_t i, Py_ssize_t limit) { + return (size_t) i < (size_t) limit; +} +#if defined (__cplusplus) && __cplusplus >= 201103L + #include + #define __Pyx_sst_abs(value) std::abs(value) +#elif SIZEOF_INT >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) abs(value) +#elif SIZEOF_LONG >= SIZEOF_SIZE_T + #define __Pyx_sst_abs(value) labs(value) +#elif defined (_MSC_VER) + #define __Pyx_sst_abs(value) ((Py_ssize_t)_abs64(value)) +#elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + #define __Pyx_sst_abs(value) llabs(value) +#elif defined (__GNUC__) + #define __Pyx_sst_abs(value) __builtin_llabs(value) +#else + #define __Pyx_sst_abs(value) ((value<0) ? -value : value) +#endif +static CYTHON_INLINE Py_ssize_t __Pyx_ssize_strlen(const char *s); +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject*); +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject*, Py_ssize_t* length); +static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char*); +#define __Pyx_PyByteArray_FromStringAndSize(s, l) PyByteArray_FromStringAndSize((const char*)s, l) +#define __Pyx_PyBytes_FromString PyBytes_FromString +#define __Pyx_PyBytes_FromStringAndSize PyBytes_FromStringAndSize +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char*); +#if PY_MAJOR_VERSION < 3 + #define __Pyx_PyStr_FromString __Pyx_PyBytes_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyBytes_FromStringAndSize +#else + #define __Pyx_PyStr_FromString __Pyx_PyUnicode_FromString + #define __Pyx_PyStr_FromStringAndSize __Pyx_PyUnicode_FromStringAndSize +#endif +#define __Pyx_PyBytes_AsWritableString(s) ((char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableSString(s) ((signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsWritableUString(s) ((unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsString(s) ((const char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsSString(s) ((const signed char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyBytes_AsUString(s) ((const unsigned char*) PyBytes_AS_STRING(s)) +#define __Pyx_PyObject_AsWritableString(s) ((char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableSString(s) ((signed char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsWritableUString(s) ((unsigned char*)(__pyx_uintptr_t) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsSString(s) ((const signed char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_AsUString(s) ((const unsigned char*) __Pyx_PyObject_AsString(s)) +#define __Pyx_PyObject_FromCString(s) __Pyx_PyObject_FromString((const char*)s) +#define __Pyx_PyBytes_FromCString(s) __Pyx_PyBytes_FromString((const char*)s) +#define __Pyx_PyByteArray_FromCString(s) __Pyx_PyByteArray_FromString((const char*)s) +#define __Pyx_PyStr_FromCString(s) __Pyx_PyStr_FromString((const char*)s) +#define __Pyx_PyUnicode_FromCString(s) __Pyx_PyUnicode_FromString((const char*)s) +#define __Pyx_PyUnicode_FromOrdinal(o) PyUnicode_FromOrdinal((int)o) +#define __Pyx_PyUnicode_AsUnicode PyUnicode_AsUnicode +#define __Pyx_NewRef(obj) (Py_INCREF(obj), obj) +#define __Pyx_Owned_Py_None(b) __Pyx_NewRef(Py_None) +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b); +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject*); +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject*); +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x); +#define __Pyx_PySequence_Tuple(obj)\ + (likely(PyTuple_CheckExact(obj)) ? __Pyx_NewRef(obj) : PySequence_Tuple(obj)) +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject*); +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t); +static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject*); +#if CYTHON_ASSUME_SAFE_MACROS +#define __pyx_PyFloat_AsDouble(x) (PyFloat_CheckExact(x) ? PyFloat_AS_DOUBLE(x) : PyFloat_AsDouble(x)) +#else +#define __pyx_PyFloat_AsDouble(x) PyFloat_AsDouble(x) +#endif +#define __pyx_PyFloat_AsFloat(x) ((float) __pyx_PyFloat_AsDouble(x)) +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyNumber_Int(x) (PyLong_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Long(x)) +#else +#define __Pyx_PyNumber_Int(x) (PyInt_CheckExact(x) ? __Pyx_NewRef(x) : PyNumber_Int(x)) +#endif +#if CYTHON_USE_PYLONG_INTERNALS + #if PY_VERSION_HEX >= 0x030C00A7 + #ifndef _PyLong_SIGN_MASK + #define _PyLong_SIGN_MASK 3 + #endif + #ifndef _PyLong_NON_SIZE_BITS + #define _PyLong_NON_SIZE_BITS 3 + #endif + #define __Pyx_PyLong_Sign(x) (((PyLongObject*)x)->long_value.lv_tag & _PyLong_SIGN_MASK) + #define __Pyx_PyLong_IsNeg(x) ((__Pyx_PyLong_Sign(x) & 2) != 0) + #define __Pyx_PyLong_IsNonNeg(x) (!__Pyx_PyLong_IsNeg(x)) + #define __Pyx_PyLong_IsZero(x) (__Pyx_PyLong_Sign(x) & 1) + #define __Pyx_PyLong_IsPos(x) (__Pyx_PyLong_Sign(x) == 0) + #define __Pyx_PyLong_CompactValueUnsigned(x) (__Pyx_PyLong_Digits(x)[0]) + #define __Pyx_PyLong_DigitCount(x) ((Py_ssize_t) (((PyLongObject*)x)->long_value.lv_tag >> _PyLong_NON_SIZE_BITS)) + #define __Pyx_PyLong_SignedDigitCount(x)\ + ((1 - (Py_ssize_t) __Pyx_PyLong_Sign(x)) * __Pyx_PyLong_DigitCount(x)) + #if defined(PyUnstable_Long_IsCompact) && defined(PyUnstable_Long_CompactValue) + #define __Pyx_PyLong_IsCompact(x) PyUnstable_Long_IsCompact((PyLongObject*) x) + #define __Pyx_PyLong_CompactValue(x) PyUnstable_Long_CompactValue((PyLongObject*) x) + #else + #define __Pyx_PyLong_IsCompact(x) (((PyLongObject*)x)->long_value.lv_tag < (2 << _PyLong_NON_SIZE_BITS)) + #define __Pyx_PyLong_CompactValue(x) ((1 - (Py_ssize_t) __Pyx_PyLong_Sign(x)) * (Py_ssize_t) __Pyx_PyLong_Digits(x)[0]) + #endif + typedef Py_ssize_t __Pyx_compact_pylong; + typedef size_t __Pyx_compact_upylong; + #else + #define __Pyx_PyLong_IsNeg(x) (Py_SIZE(x) < 0) + #define __Pyx_PyLong_IsNonNeg(x) (Py_SIZE(x) >= 0) + #define __Pyx_PyLong_IsZero(x) (Py_SIZE(x) == 0) + #define __Pyx_PyLong_IsPos(x) (Py_SIZE(x) > 0) + #define __Pyx_PyLong_CompactValueUnsigned(x) ((Py_SIZE(x) == 0) ? 0 : __Pyx_PyLong_Digits(x)[0]) + #define __Pyx_PyLong_DigitCount(x) __Pyx_sst_abs(Py_SIZE(x)) + #define __Pyx_PyLong_SignedDigitCount(x) Py_SIZE(x) + #define __Pyx_PyLong_IsCompact(x) (Py_SIZE(x) == 0 || Py_SIZE(x) == 1 || Py_SIZE(x) == -1) + #define __Pyx_PyLong_CompactValue(x)\ + ((Py_SIZE(x) == 0) ? (sdigit) 0 : ((Py_SIZE(x) < 0) ? -(sdigit)__Pyx_PyLong_Digits(x)[0] : (sdigit)__Pyx_PyLong_Digits(x)[0])) + typedef sdigit __Pyx_compact_pylong; + typedef digit __Pyx_compact_upylong; + #endif + #if PY_VERSION_HEX >= 0x030C00A5 + #define __Pyx_PyLong_Digits(x) (((PyLongObject*)x)->long_value.ob_digit) + #else + #define __Pyx_PyLong_Digits(x) (((PyLongObject*)x)->ob_digit) + #endif +#endif +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII +#include +static int __Pyx_sys_getdefaultencoding_not_ascii; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + PyObject* ascii_chars_u = NULL; + PyObject* ascii_chars_b = NULL; + const char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + if (strcmp(default_encoding_c, "ascii") == 0) { + __Pyx_sys_getdefaultencoding_not_ascii = 0; + } else { + char ascii_chars[128]; + int c; + for (c = 0; c < 128; c++) { + ascii_chars[c] = (char) c; + } + __Pyx_sys_getdefaultencoding_not_ascii = 1; + ascii_chars_u = PyUnicode_DecodeASCII(ascii_chars, 128, NULL); + if (!ascii_chars_u) goto bad; + ascii_chars_b = PyUnicode_AsEncodedString(ascii_chars_u, default_encoding_c, NULL); + if (!ascii_chars_b || !PyBytes_Check(ascii_chars_b) || memcmp(ascii_chars, PyBytes_AS_STRING(ascii_chars_b), 128) != 0) { + PyErr_Format( + PyExc_ValueError, + "This module compiled with c_string_encoding=ascii, but default encoding '%.200s' is not a superset of ascii.", + default_encoding_c); + goto bad; + } + Py_DECREF(ascii_chars_u); + Py_DECREF(ascii_chars_b); + } + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + Py_XDECREF(ascii_chars_u); + Py_XDECREF(ascii_chars_b); + return -1; +} +#endif +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT && PY_MAJOR_VERSION >= 3 +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_DecodeUTF8(c_str, size, NULL) +#else +#define __Pyx_PyUnicode_FromStringAndSize(c_str, size) PyUnicode_Decode(c_str, size, __PYX_DEFAULT_STRING_ENCODING, NULL) +#if __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +#include +static char* __PYX_DEFAULT_STRING_ENCODING; +static int __Pyx_init_sys_getdefaultencoding_params(void) { + PyObject* sys; + PyObject* default_encoding = NULL; + char* default_encoding_c; + sys = PyImport_ImportModule("sys"); + if (!sys) goto bad; + default_encoding = PyObject_CallMethod(sys, (char*) (const char*) "getdefaultencoding", NULL); + Py_DECREF(sys); + if (!default_encoding) goto bad; + default_encoding_c = PyBytes_AsString(default_encoding); + if (!default_encoding_c) goto bad; + __PYX_DEFAULT_STRING_ENCODING = (char*) malloc(strlen(default_encoding_c) + 1); + if (!__PYX_DEFAULT_STRING_ENCODING) goto bad; + strcpy(__PYX_DEFAULT_STRING_ENCODING, default_encoding_c); + Py_DECREF(default_encoding); + return 0; +bad: + Py_XDECREF(default_encoding); + return -1; +} +#endif +#endif + + +/* Test for GCC > 2.95 */ +#if defined(__GNUC__) && (__GNUC__ > 2 || (__GNUC__ == 2 && (__GNUC_MINOR__ > 95))) + #define likely(x) __builtin_expect(!!(x), 1) + #define unlikely(x) __builtin_expect(!!(x), 0) +#else /* !__GNUC__ or GCC < 2.95 */ + #define likely(x) (x) + #define unlikely(x) (x) +#endif /* __GNUC__ */ +static CYTHON_INLINE void __Pyx_pretend_to_initialize(void* ptr) { (void)ptr; } + +#if !CYTHON_USE_MODULE_STATE +static PyObject *__pyx_m = NULL; +#endif +static int __pyx_lineno; +static int __pyx_clineno = 0; +static const char * __pyx_cfilenm = __FILE__; +static const char *__pyx_filename; + +/* #### Code section: filename_table ### */ + +static const char *__pyx_f[] = { + "cython_code/user_check.pyx", +}; +/* #### Code section: utility_code_proto_before_types ### */ +/* ForceInitThreads.proto */ +#ifndef __PYX_FORCE_INIT_THREADS + #define __PYX_FORCE_INIT_THREADS 0 +#endif + +/* #### Code section: numeric_typedefs ### */ +/* #### Code section: complex_type_declarations ### */ +/* #### Code section: type_declarations ### */ + +/*--- Type declarations ---*/ +struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__; + +/* "cython_code/user_check.pyx":28 + * self.ADMIN = ADMIN + * + * async def __call__(self, message: Message, call: CallbackQuery = None) -> bool: # <<<<<<<<<<<<<< + * """ + * Checks if the user is a member of required channels. + */ +struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__ { + PyObject_HEAD + PyObject *__pyx_v_call; + PyObject *__pyx_v_cid; + PyObject *__pyx_v_data; + PyObject *__pyx_v_err; + int __pyx_v_force; + PyObject *__pyx_v_ids; + PyObject *__pyx_v_message; + PyObject *__pyx_v_res; + PyObject *__pyx_v_result; + PyObject *__pyx_v_self; + PyObject *__pyx_v_x; + PyObject *__pyx_t_0; + PyObject *__pyx_t_1; + PyObject *__pyx_t_2; + PyObject *__pyx_t_3; + PyObject *__pyx_t_4; + PyObject *__pyx_t_5; + PyObject *__pyx_t_6; + Py_ssize_t __pyx_t_7; + PyObject *(*__pyx_t_8)(PyObject *); + PyObject *__pyx_t_9; + PyObject *__pyx_t_10; + PyObject *__pyx_t_11; +}; + +/* #### Code section: utility_code_proto ### */ + +/* --- Runtime support code (head) --- */ +/* Refnanny.proto */ +#ifndef CYTHON_REFNANNY + #define CYTHON_REFNANNY 0 +#endif +#if CYTHON_REFNANNY + typedef struct { + void (*INCREF)(void*, PyObject*, Py_ssize_t); + void (*DECREF)(void*, PyObject*, Py_ssize_t); + void (*GOTREF)(void*, PyObject*, Py_ssize_t); + void (*GIVEREF)(void*, PyObject*, Py_ssize_t); + void* (*SetupContext)(const char*, Py_ssize_t, const char*); + void (*FinishContext)(void**); + } __Pyx_RefNannyAPIStruct; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNanny = NULL; + static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname); + #define __Pyx_RefNannyDeclarations void *__pyx_refnanny = NULL; +#ifdef WITH_THREAD + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + if (acquire_gil) {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__));\ + PyGILState_Release(__pyx_gilstate_save);\ + } else {\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__));\ + } + #define __Pyx_RefNannyFinishContextNogil() {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __Pyx_RefNannyFinishContext();\ + PyGILState_Release(__pyx_gilstate_save);\ + } +#else + #define __Pyx_RefNannySetupContext(name, acquire_gil)\ + __pyx_refnanny = __Pyx_RefNanny->SetupContext((name), (__LINE__), (__FILE__)) + #define __Pyx_RefNannyFinishContextNogil() __Pyx_RefNannyFinishContext() +#endif + #define __Pyx_RefNannyFinishContextNogil() {\ + PyGILState_STATE __pyx_gilstate_save = PyGILState_Ensure();\ + __Pyx_RefNannyFinishContext();\ + PyGILState_Release(__pyx_gilstate_save);\ + } + #define __Pyx_RefNannyFinishContext()\ + __Pyx_RefNanny->FinishContext(&__pyx_refnanny) + #define __Pyx_INCREF(r) __Pyx_RefNanny->INCREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_DECREF(r) __Pyx_RefNanny->DECREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_GOTREF(r) __Pyx_RefNanny->GOTREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_GIVEREF(r) __Pyx_RefNanny->GIVEREF(__pyx_refnanny, (PyObject *)(r), (__LINE__)) + #define __Pyx_XINCREF(r) do { if((r) == NULL); else {__Pyx_INCREF(r); }} while(0) + #define __Pyx_XDECREF(r) do { if((r) == NULL); else {__Pyx_DECREF(r); }} while(0) + #define __Pyx_XGOTREF(r) do { if((r) == NULL); else {__Pyx_GOTREF(r); }} while(0) + #define __Pyx_XGIVEREF(r) do { if((r) == NULL); else {__Pyx_GIVEREF(r);}} while(0) +#else + #define __Pyx_RefNannyDeclarations + #define __Pyx_RefNannySetupContext(name, acquire_gil) + #define __Pyx_RefNannyFinishContextNogil() + #define __Pyx_RefNannyFinishContext() + #define __Pyx_INCREF(r) Py_INCREF(r) + #define __Pyx_DECREF(r) Py_DECREF(r) + #define __Pyx_GOTREF(r) + #define __Pyx_GIVEREF(r) + #define __Pyx_XINCREF(r) Py_XINCREF(r) + #define __Pyx_XDECREF(r) Py_XDECREF(r) + #define __Pyx_XGOTREF(r) + #define __Pyx_XGIVEREF(r) +#endif +#define __Pyx_Py_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; Py_XDECREF(tmp);\ + } while (0) +#define __Pyx_XDECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_XDECREF(tmp);\ + } while (0) +#define __Pyx_DECREF_SET(r, v) do {\ + PyObject *tmp = (PyObject *) r;\ + r = v; __Pyx_DECREF(tmp);\ + } while (0) +#define __Pyx_CLEAR(r) do { PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);} while(0) +#define __Pyx_XCLEAR(r) do { if((r) != NULL) {PyObject* tmp = ((PyObject*)(r)); r = NULL; __Pyx_DECREF(tmp);}} while(0) + +/* TupleAndListFromArray.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n); +static CYTHON_INLINE PyObject* __Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n); +#endif + +/* IncludeStringH.proto */ +#include + +/* BytesEquals.proto */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals); + +/* UnicodeEquals.proto */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals); + +/* fastcall.proto */ +#if CYTHON_AVOID_BORROWED_REFS + #define __Pyx_Arg_VARARGS(args, i) PySequence_GetItem(args, i) +#elif CYTHON_ASSUME_SAFE_MACROS + #define __Pyx_Arg_VARARGS(args, i) PyTuple_GET_ITEM(args, i) +#else + #define __Pyx_Arg_VARARGS(args, i) PyTuple_GetItem(args, i) +#endif +#if CYTHON_AVOID_BORROWED_REFS + #define __Pyx_Arg_NewRef_VARARGS(arg) __Pyx_NewRef(arg) + #define __Pyx_Arg_XDECREF_VARARGS(arg) Py_XDECREF(arg) +#else + #define __Pyx_Arg_NewRef_VARARGS(arg) arg + #define __Pyx_Arg_XDECREF_VARARGS(arg) +#endif +#define __Pyx_NumKwargs_VARARGS(kwds) PyDict_Size(kwds) +#define __Pyx_KwValues_VARARGS(args, nargs) NULL +#define __Pyx_GetKwValue_VARARGS(kw, kwvalues, s) __Pyx_PyDict_GetItemStrWithError(kw, s) +#define __Pyx_KwargsAsDict_VARARGS(kw, kwvalues) PyDict_Copy(kw) +#if CYTHON_METH_FASTCALL + #define __Pyx_Arg_FASTCALL(args, i) args[i] + #define __Pyx_NumKwargs_FASTCALL(kwds) PyTuple_GET_SIZE(kwds) + #define __Pyx_KwValues_FASTCALL(args, nargs) ((args) + (nargs)) + static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s); +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000 + CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues); + #else + #define __Pyx_KwargsAsDict_FASTCALL(kw, kwvalues) _PyStack_AsDict(kwvalues, kw) + #endif + #define __Pyx_Arg_NewRef_FASTCALL(arg) arg /* no-op, __Pyx_Arg_FASTCALL is direct and this needs + to have the same reference counting */ + #define __Pyx_Arg_XDECREF_FASTCALL(arg) +#else + #define __Pyx_Arg_FASTCALL __Pyx_Arg_VARARGS + #define __Pyx_NumKwargs_FASTCALL __Pyx_NumKwargs_VARARGS + #define __Pyx_KwValues_FASTCALL __Pyx_KwValues_VARARGS + #define __Pyx_GetKwValue_FASTCALL __Pyx_GetKwValue_VARARGS + #define __Pyx_KwargsAsDict_FASTCALL __Pyx_KwargsAsDict_VARARGS + #define __Pyx_Arg_NewRef_FASTCALL(arg) __Pyx_Arg_NewRef_VARARGS(arg) + #define __Pyx_Arg_XDECREF_FASTCALL(arg) __Pyx_Arg_XDECREF_VARARGS(arg) +#endif +#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS +#define __Pyx_ArgsSlice_VARARGS(args, start, stop) __Pyx_PyTuple_FromArray(&__Pyx_Arg_VARARGS(args, start), stop - start) +#define __Pyx_ArgsSlice_FASTCALL(args, start, stop) __Pyx_PyTuple_FromArray(&__Pyx_Arg_FASTCALL(args, start), stop - start) +#else +#define __Pyx_ArgsSlice_VARARGS(args, start, stop) PyTuple_GetSlice(args, start, stop) +#define __Pyx_ArgsSlice_FASTCALL(args, start, stop) PyTuple_GetSlice(args, start, stop) +#endif + +/* RaiseDoubleKeywords.proto */ +static void __Pyx_RaiseDoubleKeywordsError(const char* func_name, PyObject* kw_name); + +/* ParseKeywords.proto */ +static int __Pyx_ParseOptionalKeywords(PyObject *kwds, PyObject *const *kwvalues, + PyObject **argnames[], + PyObject *kwds2, PyObject *values[], Py_ssize_t num_pos_args, + const char* function_name); + +/* RaiseArgTupleInvalid.proto */ +static void __Pyx_RaiseArgtupleInvalid(const char* func_name, int exact, + Py_ssize_t num_min, Py_ssize_t num_max, Py_ssize_t num_found); + +/* PyErrExceptionMatches.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_ExceptionMatches(err) __Pyx_PyErr_ExceptionMatchesInState(__pyx_tstate, err) +static CYTHON_INLINE int __Pyx_PyErr_ExceptionMatchesInState(PyThreadState* tstate, PyObject* err); +#else +#define __Pyx_PyErr_ExceptionMatches(err) PyErr_ExceptionMatches(err) +#endif + +/* PyThreadStateGet.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyThreadState_declare PyThreadState *__pyx_tstate; +#define __Pyx_PyThreadState_assign __pyx_tstate = __Pyx_PyThreadState_Current; +#if PY_VERSION_HEX >= 0x030C00A6 +#define __Pyx_PyErr_Occurred() (__pyx_tstate->current_exception != NULL) +#define __Pyx_PyErr_CurrentExceptionType() (__pyx_tstate->current_exception ? (PyObject*) Py_TYPE(__pyx_tstate->current_exception) : (PyObject*) NULL) +#else +#define __Pyx_PyErr_Occurred() (__pyx_tstate->curexc_type != NULL) +#define __Pyx_PyErr_CurrentExceptionType() (__pyx_tstate->curexc_type) +#endif +#else +#define __Pyx_PyThreadState_declare +#define __Pyx_PyThreadState_assign +#define __Pyx_PyErr_Occurred() (PyErr_Occurred() != NULL) +#define __Pyx_PyErr_CurrentExceptionType() PyErr_Occurred() +#endif + +/* PyErrFetchRestore.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyErr_Clear() __Pyx_ErrRestore(NULL, NULL, NULL) +#define __Pyx_ErrRestoreWithState(type, value, tb) __Pyx_ErrRestoreInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) __Pyx_ErrFetchInState(PyThreadState_GET(), type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) __Pyx_ErrRestoreInState(__pyx_tstate, type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) __Pyx_ErrFetchInState(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A6 +#define __Pyx_PyErr_SetNone(exc) (Py_INCREF(exc), __Pyx_ErrRestore((exc), NULL, NULL)) +#else +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#endif +#else +#define __Pyx_PyErr_Clear() PyErr_Clear() +#define __Pyx_PyErr_SetNone(exc) PyErr_SetNone(exc) +#define __Pyx_ErrRestoreWithState(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchWithState(type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestoreInState(tstate, type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetchInState(tstate, type, value, tb) PyErr_Fetch(type, value, tb) +#define __Pyx_ErrRestore(type, value, tb) PyErr_Restore(type, value, tb) +#define __Pyx_ErrFetch(type, value, tb) PyErr_Fetch(type, value, tb) +#endif + +/* PyObjectGetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GetAttrStr(o,n) PyObject_GetAttr(o,n) +#endif + +/* PyObjectGetAttrStrNoError.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name); + +/* GetBuiltinName.proto */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name); + +/* PyDictVersioning.proto */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +#define __PYX_DICT_VERSION_INIT ((PY_UINT64_T) -1) +#define __PYX_GET_DICT_VERSION(dict) (((PyDictObject*)(dict))->ma_version_tag) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var)\ + (version_var) = __PYX_GET_DICT_VERSION(dict);\ + (cache_var) = (value); +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + if (likely(__PYX_GET_DICT_VERSION(DICT) == __pyx_dict_version)) {\ + (VAR) = __pyx_dict_cached_value;\ + } else {\ + (VAR) = __pyx_dict_cached_value = (LOOKUP);\ + __pyx_dict_version = __PYX_GET_DICT_VERSION(DICT);\ + }\ +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj); +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj); +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version); +#else +#define __PYX_GET_DICT_VERSION(dict) (0) +#define __PYX_UPDATE_DICT_CACHE(dict, value, cache_var, version_var) +#define __PYX_PY_DICT_LOOKUP_IF_MODIFIED(VAR, DICT, LOOKUP) (VAR) = (LOOKUP); +#endif + +/* GetModuleGlobalName.proto */ +#if CYTHON_USE_DICT_VERSIONS +#define __Pyx_GetModuleGlobalName(var, name) do {\ + static PY_UINT64_T __pyx_dict_version = 0;\ + static PyObject *__pyx_dict_cached_value = NULL;\ + (var) = (likely(__pyx_dict_version == __PYX_GET_DICT_VERSION(__pyx_d))) ?\ + (likely(__pyx_dict_cached_value) ? __Pyx_NewRef(__pyx_dict_cached_value) : __Pyx_GetBuiltinName(name)) :\ + __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} while(0) +#define __Pyx_GetModuleGlobalNameUncached(var, name) do {\ + PY_UINT64_T __pyx_dict_version;\ + PyObject *__pyx_dict_cached_value;\ + (var) = __Pyx__GetModuleGlobalName(name, &__pyx_dict_version, &__pyx_dict_cached_value);\ +} while(0) +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value); +#else +#define __Pyx_GetModuleGlobalName(var, name) (var) = __Pyx__GetModuleGlobalName(name) +#define __Pyx_GetModuleGlobalNameUncached(var, name) (var) = __Pyx__GetModuleGlobalName(name) +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name); +#endif + +/* PyObjectSetAttrStr.proto */ +#if CYTHON_USE_TYPE_SLOTS +#define __Pyx_PyObject_DelAttrStr(o,n) __Pyx_PyObject_SetAttrStr(o, n, NULL) +static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value); +#else +#define __Pyx_PyObject_DelAttrStr(o,n) PyObject_DelAttr(o,n) +#define __Pyx_PyObject_SetAttrStr(o,n,v) PyObject_SetAttr(o,n,v) +#endif + +/* PyFunctionFastCall.proto */ +#if CYTHON_FAST_PYCALL +#if !CYTHON_VECTORCALL +#define __Pyx_PyFunction_FastCall(func, args, nargs)\ + __Pyx_PyFunction_FastCallDict((func), (args), (nargs), NULL) +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs); +#endif +#define __Pyx_BUILD_ASSERT_EXPR(cond)\ + (sizeof(char [1 - 2*!(cond)]) - 1) +#ifndef Py_MEMBER_SIZE +#define Py_MEMBER_SIZE(type, member) sizeof(((type *)0)->member) +#endif +#if !CYTHON_VECTORCALL +#if PY_VERSION_HEX >= 0x03080000 + #include "frameobject.h" +#if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API + #ifndef Py_BUILD_CORE + #define Py_BUILD_CORE 1 + #endif + #include "internal/pycore_frame.h" +#endif + #define __Pxy_PyFrame_Initialize_Offsets() + #define __Pyx_PyFrame_GetLocalsplus(frame) ((frame)->f_localsplus) +#else + static size_t __pyx_pyframe_localsplus_offset = 0; + #include "frameobject.h" + #define __Pxy_PyFrame_Initialize_Offsets()\ + ((void)__Pyx_BUILD_ASSERT_EXPR(sizeof(PyFrameObject) == offsetof(PyFrameObject, f_localsplus) + Py_MEMBER_SIZE(PyFrameObject, f_localsplus)),\ + (void)(__pyx_pyframe_localsplus_offset = ((size_t)PyFrame_Type.tp_basicsize) - Py_MEMBER_SIZE(PyFrameObject, f_localsplus))) + #define __Pyx_PyFrame_GetLocalsplus(frame)\ + (assert(__pyx_pyframe_localsplus_offset), (PyObject **)(((char *)(frame)) + __pyx_pyframe_localsplus_offset)) +#endif +#endif +#endif + +/* PyObjectCall.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw); +#else +#define __Pyx_PyObject_Call(func, arg, kw) PyObject_Call(func, arg, kw) +#endif + +/* PyObjectCallMethO.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg); +#endif + +/* PyObjectFastCall.proto */ +#define __Pyx_PyObject_FastCall(func, args, nargs) __Pyx_PyObject_FastCallDict(func, args, (size_t)(nargs), NULL) +static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject **args, size_t nargs, PyObject *kwargs); + +/* DictGetItem.proto */ +#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY +static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key); +#define __Pyx_PyObject_Dict_GetItem(obj, name)\ + (likely(PyDict_CheckExact(obj)) ?\ + __Pyx_PyDict_GetItem(obj, name) : PyObject_GetItem(obj, name)) +#else +#define __Pyx_PyDict_GetItem(d, key) PyObject_GetItem(d, key) +#define __Pyx_PyObject_Dict_GetItem(obj, name) PyObject_GetItem(obj, name) +#endif + +/* GetTopmostException.proto */ +#if CYTHON_USE_EXC_INFO_STACK && CYTHON_FAST_THREAD_STATE +static _PyErr_StackItem * __Pyx_PyErr_GetTopmostException(PyThreadState *tstate); +#endif + +/* SaveResetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSave(type, value, tb) __Pyx__ExceptionSave(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#define __Pyx_ExceptionReset(type, value, tb) __Pyx__ExceptionReset(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb); +#else +#define __Pyx_ExceptionSave(type, value, tb) PyErr_GetExcInfo(type, value, tb) +#define __Pyx_ExceptionReset(type, value, tb) PyErr_SetExcInfo(type, value, tb) +#endif + +/* GetException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_GetException(type, value, tb) __Pyx__GetException(__pyx_tstate, type, value, tb) +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* SwapException.proto */ +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_ExceptionSwap(type, value, tb) __Pyx__ExceptionSwap(__pyx_tstate, type, value, tb) +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb); +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb); +#endif + +/* PyObject_Unicode.proto */ +#if PY_MAJOR_VERSION >= 3 +#define __Pyx_PyObject_Unicode(obj)\ + (likely(PyUnicode_CheckExact(obj)) ? __Pyx_NewRef(obj) : PyObject_Str(obj)) +#else +#define __Pyx_PyObject_Unicode(obj)\ + (likely(PyUnicode_CheckExact(obj)) ? __Pyx_NewRef(obj) : PyObject_Unicode(obj)) +#endif + +/* GetItemInt.proto */ +#define __Pyx_GetItemInt(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_Fast(o, (Py_ssize_t)i, is_list, wraparound, boundscheck) :\ + (is_list ? (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL) :\ + __Pyx_GetItemInt_Generic(o, to_py_func(i)))) +#define __Pyx_GetItemInt_List(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_List_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ + (PyErr_SetString(PyExc_IndexError, "list index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +#define __Pyx_GetItemInt_Tuple(o, i, type, is_signed, to_py_func, is_list, wraparound, boundscheck)\ + (__Pyx_fits_Py_ssize_t(i, type, is_signed) ?\ + __Pyx_GetItemInt_Tuple_Fast(o, (Py_ssize_t)i, wraparound, boundscheck) :\ + (PyErr_SetString(PyExc_IndexError, "tuple index out of range"), (PyObject*)NULL)) +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + int wraparound, int boundscheck); +static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j); +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, + int is_list, int wraparound, int boundscheck); + +/* UnicodeConcatInPlace.proto */ +# if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 + #if CYTHON_REFNANNY + #define __Pyx_PyUnicode_ConcatInPlace(left, right) __Pyx_PyUnicode_ConcatInPlaceImpl(&left, right, __pyx_refnanny) + #else + #define __Pyx_PyUnicode_ConcatInPlace(left, right) __Pyx_PyUnicode_ConcatInPlaceImpl(&left, right) + #endif + static CYTHON_INLINE PyObject *__Pyx_PyUnicode_ConcatInPlaceImpl(PyObject **p_left, PyObject *right + #if CYTHON_REFNANNY + , void* __pyx_refnanny + #endif + ); +#else +#define __Pyx_PyUnicode_ConcatInPlace __Pyx_PyUnicode_Concat +#endif +#define __Pyx_PyUnicode_ConcatInPlaceSafe(left, right) ((unlikely((left) == Py_None) || unlikely((right) == Py_None)) ?\ + PyNumber_InPlaceAdd(left, right) : __Pyx_PyUnicode_ConcatInPlace(left, right)) + +/* IncludeStructmemberH.proto */ +#include + +/* FixUpExtensionType.proto */ +#if CYTHON_USE_TYPE_SPECS +static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type); +#endif + +/* FetchSharedCythonModule.proto */ +static PyObject *__Pyx_FetchSharedCythonABIModule(void); + +/* FetchCommonType.proto */ +#if !CYTHON_USE_TYPE_SPECS +static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type); +#else +static PyTypeObject* __Pyx_FetchCommonTypeFromSpec(PyObject *module, PyType_Spec *spec, PyObject *bases); +#endif + +/* RaiseException.proto */ +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause); + +/* PyObjectCall2Args.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2); + +/* PyObjectCallOneArg.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg); + +/* PyObjectGetMethod.proto */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method); + +/* PyObjectCallMethod1.proto */ +static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg); + +/* PyObjectCallNoArg.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func); + +/* CoroutineBase.proto */ +struct __pyx_CoroutineObject; +typedef PyObject *(*__pyx_coroutine_body_t)(struct __pyx_CoroutineObject *, PyThreadState *, PyObject *); +#if CYTHON_USE_EXC_INFO_STACK +#define __Pyx_ExcInfoStruct _PyErr_StackItem +#else +typedef struct { + PyObject *exc_type; + PyObject *exc_value; + PyObject *exc_traceback; +} __Pyx_ExcInfoStruct; +#endif +typedef struct __pyx_CoroutineObject { + PyObject_HEAD + __pyx_coroutine_body_t body; + PyObject *closure; + __Pyx_ExcInfoStruct gi_exc_state; + PyObject *gi_weakreflist; + PyObject *classobj; + PyObject *yieldfrom; + PyObject *gi_name; + PyObject *gi_qualname; + PyObject *gi_modulename; + PyObject *gi_code; + PyObject *gi_frame; + int resume_label; + char is_running; +} __pyx_CoroutineObject; +static __pyx_CoroutineObject *__Pyx__Coroutine_New( + PyTypeObject *type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, + PyObject *name, PyObject *qualname, PyObject *module_name); +static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit( + __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, + PyObject *name, PyObject *qualname, PyObject *module_name); +static CYTHON_INLINE void __Pyx_Coroutine_ExceptionClear(__Pyx_ExcInfoStruct *self); +static int __Pyx_Coroutine_clear(PyObject *self); +static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value); +static PyObject *__Pyx_Coroutine_Close(PyObject *self); +static PyObject *__Pyx_Coroutine_Throw(PyObject *gen, PyObject *args); +#if CYTHON_USE_EXC_INFO_STACK +#define __Pyx_Coroutine_SwapException(self) +#define __Pyx_Coroutine_ResetAndClearException(self) __Pyx_Coroutine_ExceptionClear(&(self)->gi_exc_state) +#else +#define __Pyx_Coroutine_SwapException(self) {\ + __Pyx_ExceptionSwap(&(self)->gi_exc_state.exc_type, &(self)->gi_exc_state.exc_value, &(self)->gi_exc_state.exc_traceback);\ + __Pyx_Coroutine_ResetFrameBackpointer(&(self)->gi_exc_state);\ + } +#define __Pyx_Coroutine_ResetAndClearException(self) {\ + __Pyx_ExceptionReset((self)->gi_exc_state.exc_type, (self)->gi_exc_state.exc_value, (self)->gi_exc_state.exc_traceback);\ + (self)->gi_exc_state.exc_type = (self)->gi_exc_state.exc_value = (self)->gi_exc_state.exc_traceback = NULL;\ + } +#endif +#if CYTHON_FAST_THREAD_STATE +#define __Pyx_PyGen_FetchStopIterationValue(pvalue)\ + __Pyx_PyGen__FetchStopIterationValue(__pyx_tstate, pvalue) +#else +#define __Pyx_PyGen_FetchStopIterationValue(pvalue)\ + __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, pvalue) +#endif +static int __Pyx_PyGen__FetchStopIterationValue(PyThreadState *tstate, PyObject **pvalue); +static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__Pyx_ExcInfoStruct *exc_state); + +/* PyObject_GenericGetAttrNoDict.proto */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name); +#else +#define __Pyx_PyObject_GenericGetAttrNoDict PyObject_GenericGetAttr +#endif + +/* PatchModuleWithCoroutine.proto */ +static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code); + +/* PatchGeneratorABC.proto */ +static int __Pyx_patch_abc(void); + +/* Coroutine.proto */ +#define __Pyx_Coroutine_USED +#define __Pyx_Coroutine_CheckExact(obj) __Pyx_IS_TYPE(obj, __pyx_CoroutineType) +#define __Pyx_Coroutine_Check(obj) __Pyx_Coroutine_CheckExact(obj) +#define __Pyx_CoroutineAwait_CheckExact(obj) __Pyx_IS_TYPE(obj, __pyx_CoroutineAwaitType) +#define __Pyx_Coroutine_New(body, code, closure, name, qualname, module_name)\ + __Pyx__Coroutine_New(__pyx_CoroutineType, body, code, closure, name, qualname, module_name) +static int __pyx_Coroutine_init(PyObject *module); +static PyObject *__Pyx__Coroutine_await(PyObject *coroutine); +typedef struct { + PyObject_HEAD + PyObject *coroutine; +} __pyx_CoroutineAwaitObject; +static PyObject *__Pyx_CoroutineAwait_Close(__pyx_CoroutineAwaitObject *self, PyObject *arg); +static PyObject *__Pyx_CoroutineAwait_Throw(__pyx_CoroutineAwaitObject *self, PyObject *args); + +/* GetAwaitIter.proto */ +static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAwaitableIter(PyObject *o); +static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *o); + +/* CoroutineYieldFrom.proto */ +static CYTHON_INLINE PyObject* __Pyx_Coroutine_Yield_From(__pyx_CoroutineObject *gen, PyObject *source); + +/* ReturnWithStopIteration.proto */ +#define __Pyx_ReturnWithStopIteration(value)\ + if (value == Py_None) PyErr_SetNone(PyExc_StopIteration); else __Pyx__ReturnWithStopIteration(value) +static void __Pyx__ReturnWithStopIteration(PyObject* value); + +/* pep479.proto */ +static void __Pyx_Generator_Replace_StopIteration(int in_async_gen); + +/* PyObjectCallMethod0.proto */ +static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name); + +/* ValidateBasesTuple.proto */ +#if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS +static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases); +#endif + +/* PyType_Ready.proto */ +CYTHON_UNUSED static int __Pyx_PyType_Ready(PyTypeObject *t); + +/* Import.proto */ +static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level); + +/* ImportDottedModule.proto */ +static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple); +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple); +#endif + +/* ImportFrom.proto */ +static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name); + +/* Py3UpdateBases.proto */ +static PyObject* __Pyx_PEP560_update_bases(PyObject *bases); + +/* CalculateMetaclass.proto */ +static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases); + +/* PyMethodNew.proto */ +#if CYTHON_COMPILING_IN_LIMITED_API +static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) { + PyObject *typesModule=NULL, *methodType=NULL, *result=NULL; + CYTHON_UNUSED_VAR(typ); + if (!self) + return __Pyx_NewRef(func); + typesModule = PyImport_ImportModule("types"); + if (!typesModule) return NULL; + methodType = PyObject_GetAttrString(typesModule, "MethodType"); + Py_DECREF(typesModule); + if (!methodType) return NULL; + result = PyObject_CallFunctionObjArgs(methodType, func, self, NULL); + Py_DECREF(methodType); + return result; +} +#elif PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_PyMethod_New(PyObject *func, PyObject *self, PyObject *typ) { + CYTHON_UNUSED_VAR(typ); + if (!self) + return __Pyx_NewRef(func); + return PyMethod_New(func, self); +} +#else + #define __Pyx_PyMethod_New PyMethod_New +#endif + +/* PyVectorcallFastCallDict.proto */ +#if CYTHON_METH_FASTCALL +static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw); +#endif + +/* CythonFunctionShared.proto */ +#define __Pyx_CyFunction_USED +#define __Pyx_CYFUNCTION_STATICMETHOD 0x01 +#define __Pyx_CYFUNCTION_CLASSMETHOD 0x02 +#define __Pyx_CYFUNCTION_CCLASS 0x04 +#define __Pyx_CYFUNCTION_COROUTINE 0x08 +#define __Pyx_CyFunction_GetClosure(f)\ + (((__pyx_CyFunctionObject *) (f))->func_closure) +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + #define __Pyx_CyFunction_GetClassObj(f)\ + (((__pyx_CyFunctionObject *) (f))->func_classobj) +#else + #define __Pyx_CyFunction_GetClassObj(f)\ + ((PyObject*) ((PyCMethodObject *) (f))->mm_class) +#endif +#define __Pyx_CyFunction_SetClassObj(f, classobj)\ + __Pyx__CyFunction_SetClassObj((__pyx_CyFunctionObject *) (f), (classobj)) +#define __Pyx_CyFunction_Defaults(type, f)\ + ((type *)(((__pyx_CyFunctionObject *) (f))->defaults)) +#define __Pyx_CyFunction_SetDefaultsGetter(f, g)\ + ((__pyx_CyFunctionObject *) (f))->defaults_getter = (g) +typedef struct { +#if CYTHON_COMPILING_IN_LIMITED_API + PyObject_HEAD + PyObject *func; +#elif PY_VERSION_HEX < 0x030900B1 + PyCFunctionObject func; +#else + PyCMethodObject func; +#endif +#if CYTHON_BACKPORT_VECTORCALL + __pyx_vectorcallfunc func_vectorcall; +#endif +#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API + PyObject *func_weakreflist; +#endif + PyObject *func_dict; + PyObject *func_name; + PyObject *func_qualname; + PyObject *func_doc; + PyObject *func_globals; + PyObject *func_code; + PyObject *func_closure; +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + PyObject *func_classobj; +#endif + void *defaults; + int defaults_pyobjects; + size_t defaults_size; + int flags; + PyObject *defaults_tuple; + PyObject *defaults_kwdict; + PyObject *(*defaults_getter)(PyObject *); + PyObject *func_annotations; + PyObject *func_is_coroutine; +} __pyx_CyFunctionObject; +#undef __Pyx_CyOrPyCFunction_Check +#define __Pyx_CyFunction_Check(obj) __Pyx_TypeCheck(obj, __pyx_CyFunctionType) +#define __Pyx_CyOrPyCFunction_Check(obj) __Pyx_TypeCheck2(obj, __pyx_CyFunctionType, &PyCFunction_Type) +#define __Pyx_CyFunction_CheckExact(obj) __Pyx_IS_TYPE(obj, __pyx_CyFunctionType) +static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc); +#undef __Pyx_IsSameCFunction +#define __Pyx_IsSameCFunction(func, cfunc) __Pyx__IsSameCyOrCFunction(func, cfunc) +static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject* op, PyMethodDef *ml, + int flags, PyObject* qualname, + PyObject *closure, + PyObject *module, PyObject *globals, + PyObject* code); +static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj); +static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *m, + size_t size, + int pyobjects); +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *m, + PyObject *tuple); +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *m, + PyObject *dict); +static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *m, + PyObject *dict); +static int __pyx_CyFunction_init(PyObject *module); +#if CYTHON_METH_FASTCALL +static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames); +#if CYTHON_BACKPORT_VECTORCALL +#define __Pyx_CyFunction_func_vectorcall(f) (((__pyx_CyFunctionObject*)f)->func_vectorcall) +#else +#define __Pyx_CyFunction_func_vectorcall(f) (((PyCFunctionObject*)f)->vectorcall) +#endif +#endif + +/* CythonFunction.proto */ +static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, + int flags, PyObject* qualname, + PyObject *closure, + PyObject *module, PyObject *globals, + PyObject* code); + +/* SetNameInClass.proto */ +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && PY_VERSION_HEX < 0x030d0000 +#define __Pyx_SetNameInClass(ns, name, value)\ + (likely(PyDict_CheckExact(ns)) ? _PyDict_SetItem_KnownHash(ns, name, value, ((PyASCIIObject *) name)->hash) : PyObject_SetItem(ns, name, value)) +#elif CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_SetNameInClass(ns, name, value)\ + (likely(PyDict_CheckExact(ns)) ? PyDict_SetItem(ns, name, value) : PyObject_SetItem(ns, name, value)) +#else +#define __Pyx_SetNameInClass(ns, name, value) PyObject_SetItem(ns, name, value) +#endif + +/* PyObjectLookupSpecial.proto */ +#if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS +#define __Pyx_PyObject_LookupSpecialNoError(obj, attr_name) __Pyx__PyObject_LookupSpecial(obj, attr_name, 0) +#define __Pyx_PyObject_LookupSpecial(obj, attr_name) __Pyx__PyObject_LookupSpecial(obj, attr_name, 1) +static CYTHON_INLINE PyObject* __Pyx__PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name, int with_error); +#else +#define __Pyx_PyObject_LookupSpecialNoError(o,n) __Pyx_PyObject_GetAttrStrNoError(o,n) +#define __Pyx_PyObject_LookupSpecial(o,n) __Pyx_PyObject_GetAttrStr(o,n) +#endif + +/* Py3ClassCreate.proto */ +static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, PyObject *qualname, + PyObject *mkw, PyObject *modname, PyObject *doc); +static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, PyObject *dict, + PyObject *mkw, int calculate_metaclass, int allow_py2_metaclass); + +/* CLineInTraceback.proto */ +#ifdef CYTHON_CLINE_IN_TRACEBACK +#define __Pyx_CLineForTraceback(tstate, c_line) (((CYTHON_CLINE_IN_TRACEBACK)) ? c_line : 0) +#else +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line); +#endif + +/* CodeObjectCache.proto */ +#if !CYTHON_COMPILING_IN_LIMITED_API +typedef struct { + PyCodeObject* code_object; + int code_line; +} __Pyx_CodeObjectCacheEntry; +struct __Pyx_CodeObjectCache { + int count; + int max_count; + __Pyx_CodeObjectCacheEntry* entries; +}; +static struct __Pyx_CodeObjectCache __pyx_code_cache = {0,0,NULL}; +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line); +static PyCodeObject *__pyx_find_code_object(int code_line); +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object); +#endif + +/* AddTraceback.proto */ +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename); + +/* GCCDiagnostics.proto */ +#if !defined(__INTEL_COMPILER) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +#define __Pyx_HAS_GCC_DIAGNOSTIC +#endif + +/* CIntToPy.proto */ +static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value); + +/* FormatTypeName.proto */ +#if CYTHON_COMPILING_IN_LIMITED_API +typedef PyObject *__Pyx_TypeName; +#define __Pyx_FMT_TYPENAME "%U" +static __Pyx_TypeName __Pyx_PyType_GetName(PyTypeObject* tp); +#define __Pyx_DECREF_TypeName(obj) Py_XDECREF(obj) +#else +typedef const char *__Pyx_TypeName; +#define __Pyx_FMT_TYPENAME "%.200s" +#define __Pyx_PyType_GetName(tp) ((tp)->tp_name) +#define __Pyx_DECREF_TypeName(obj) +#endif + +/* CIntFromPy.proto */ +static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *); + +/* CIntFromPy.proto */ +static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *); + +/* FastTypeChecks.proto */ +#if CYTHON_COMPILING_IN_CPYTHON +#define __Pyx_TypeCheck(obj, type) __Pyx_IsSubtype(Py_TYPE(obj), (PyTypeObject *)type) +#define __Pyx_TypeCheck2(obj, type1, type2) __Pyx_IsAnySubtype2(Py_TYPE(obj), (PyTypeObject *)type1, (PyTypeObject *)type2) +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b); +static CYTHON_INLINE int __Pyx_IsAnySubtype2(PyTypeObject *cls, PyTypeObject *a, PyTypeObject *b); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches(PyObject *err, PyObject *type); +static CYTHON_INLINE int __Pyx_PyErr_GivenExceptionMatches2(PyObject *err, PyObject *type1, PyObject *type2); +#else +#define __Pyx_TypeCheck(obj, type) PyObject_TypeCheck(obj, (PyTypeObject *)type) +#define __Pyx_TypeCheck2(obj, type1, type2) (PyObject_TypeCheck(obj, (PyTypeObject *)type1) || PyObject_TypeCheck(obj, (PyTypeObject *)type2)) +#define __Pyx_PyErr_GivenExceptionMatches(err, type) PyErr_GivenExceptionMatches(err, type) +#define __Pyx_PyErr_GivenExceptionMatches2(err, type1, type2) (PyErr_GivenExceptionMatches(err, type1) || PyErr_GivenExceptionMatches(err, type2)) +#endif +#define __Pyx_PyErr_ExceptionMatches2(err1, err2) __Pyx_PyErr_GivenExceptionMatches2(__Pyx_PyErr_CurrentExceptionType(), err1, err2) +#define __Pyx_PyException_Check(obj) __Pyx_TypeCheck(obj, PyExc_Exception) + +/* CheckBinaryVersion.proto */ +static unsigned long __Pyx_get_runtime_version(void); +static int __Pyx_check_binary_version(unsigned long ct_version, unsigned long rt_version, int allow_newer); + +/* InitStrings.proto */ +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t); + +/* #### Code section: module_declarations ### */ + +/* Module declarations from "cython_code.user_check" */ +/* #### Code section: typeinfo ### */ +/* #### Code section: before_global_var ### */ +#define __Pyx_MODULE_NAME "cython_code.user_check" +extern int __pyx_module_is_main_cython_code__user_check; +int __pyx_module_is_main_cython_code__user_check = 0; + +/* Implementation of "cython_code.user_check" */ +/* #### Code section: global_var ### */ +/* #### Code section: string_decls ### */ +static const char __pyx_k_x[] = "x"; +static const char __pyx_k_DB[] = "DB"; +static const char __pyx_k__2[] = "*"; +static const char __pyx_k__3[] = "."; +static const char __pyx_k__8[] = "?"; +static const char __pyx_k_db[] = "db"; +static const char __pyx_k_gc[] = "gc"; +static const char __pyx_k_id[] = "id"; +static const char __pyx_k_bot[] = "bot"; +static const char __pyx_k_cid[] = "cid"; +static const char __pyx_k_doc[] = "__doc__"; +static const char __pyx_k_err[] = "err"; +static const char __pyx_k_ids[] = "ids"; +static const char __pyx_k_res[] = "res"; +static const char __pyx_k_args[] = "args"; +static const char __pyx_k_bool[] = "bool"; +static const char __pyx_k_call[] = "call"; +static const char __pyx_k_data[] = "data"; +static const char __pyx_k_dict[] = "__dict__"; +static const char __pyx_k_init[] = "__init__"; +static const char __pyx_k_main[] = "__main__"; +static const char __pyx_k_name[] = "__name__"; +static const char __pyx_k_self[] = "self"; +static const char __pyx_k_send[] = "send"; +static const char __pyx_k_spec[] = "__spec__"; +static const char __pyx_k_test[] = "__test__"; +static const char __pyx_k_ADMIN[] = "ADMIN"; +static const char __pyx_k_await[] = "__await__"; +static const char __pyx_k_close[] = "close"; +static const char __pyx_k_error[] = "error"; +static const char __pyx_k_force[] = "force"; +static const char __pyx_k_super[] = "super"; +static const char __pyx_k_throw[] = "throw"; +static const char __pyx_k_call_2[] = "__call__"; +static const char __pyx_k_enable[] = "enable"; +static const char __pyx_k_import[] = "__import__"; +static const char __pyx_k_loader[] = "loader"; +static const char __pyx_k_member[] = "member"; +static const char __pyx_k_module[] = "__module__"; +static const char __pyx_k_result[] = "result"; +static const char __pyx_k_return[] = "return"; +static const char __pyx_k_status[] = "status"; +static const char __pyx_k_Message[] = "Message"; +static const char __pyx_k_aiogram[] = "aiogram"; +static const char __pyx_k_chat_id[] = "chat_id"; +static const char __pyx_k_creator[] = "creator"; +static const char __pyx_k_disable[] = "disable"; +static const char __pyx_k_logging[] = "logging"; +static const char __pyx_k_message[] = "message"; +static const char __pyx_k_prepare[] = "__prepare__"; +static const char __pyx_k_user_id[] = "user_id"; +static const char __pyx_k_get_chat[] = "get_chat"; +static const char __pyx_k_qualname[] = "__qualname__"; +static const char __pyx_k_set_name[] = "__set_name__"; +static const char __pyx_k_from_user[] = "from_user"; +static const char __pyx_k_isenabled[] = "isenabled"; +static const char __pyx_k_metaclass[] = "__metaclass__"; +static const char __pyx_k_BaseFilter[] = "BaseFilter"; +static const char __pyx_k_User_Check[] = "User_Check"; +static const char __pyx_k_reading_db[] = "reading_db"; +static const char __pyx_k_data_config[] = "data.config"; +static const char __pyx_k_mro_entries[] = "__mro_entries__"; +static const char __pyx_k_initializing[] = "_initializing"; +static const char __pyx_k_is_coroutine[] = "_is_coroutine"; +static const char __pyx_k_join_channel[] = "join_channel"; +static const char __pyx_k_CallbackQuery[] = "CallbackQuery"; +static const char __pyx_k_administrator[] = "administrator"; +static const char __pyx_k_aiogram_types[] = "aiogram.types"; +static const char __pyx_k_init_subclass[] = "__init_subclass__"; +static const char __pyx_k_BaseMiddleware[] = "BaseMiddleware"; +static const char __pyx_k_aiogram_filters[] = "aiogram.filters"; +static const char __pyx_k_get_chat_member[] = "get_chat_member"; +static const char __pyx_k_select_channels[] = "select_channels"; +static const char __pyx_k_User_Check___call[] = "User_Check.__call__"; +static const char __pyx_k_User_Check___init[] = "User_Check.__init__"; +static const char __pyx_k_asyncio_coroutines[] = "asyncio.coroutines"; +static const char __pyx_k_cline_in_traceback[] = "cline_in_traceback"; +static const char __pyx_k_cython_code_user_check[] = "cython_code.user_check"; +static const char __pyx_k_cython_code_user_check_pyx[] = "cython_code/user_check.pyx"; +static const char __pyx_k_Middleware_and_filter_class_to[] = "\n Middleware and filter class to check if a user is a member of required channels.\n\n This class combines the functionality of a filter and middleware to ensure that users\n are members of specified channels before they can access certain bot features.\n "; +/* #### Code section: decls ### */ +static PyObject *__pyx_pf_11cython_code_10user_check_10User_Check___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self); /* proto */ +static PyObject *__pyx_pf_11cython_code_10user_check_10User_Check_2__call__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_message, PyObject *__pyx_v_call); /* proto */ +static PyObject *__pyx_tp_new_11cython_code_10user_check___pyx_scope_struct____call__(PyTypeObject *t, PyObject *a, PyObject *k); /*proto*/ +/* #### Code section: late_includes ### */ +/* #### Code section: module_state ### */ +typedef struct { + PyObject *__pyx_d; + PyObject *__pyx_b; + PyObject *__pyx_cython_runtime; + PyObject *__pyx_empty_tuple; + PyObject *__pyx_empty_bytes; + PyObject *__pyx_empty_unicode; + #ifdef __Pyx_CyFunction_USED + PyTypeObject *__pyx_CyFunctionType; + #endif + #ifdef __Pyx_FusedFunction_USED + PyTypeObject *__pyx_FusedFunctionType; + #endif + #ifdef __Pyx_Generator_USED + PyTypeObject *__pyx_GeneratorType; + #endif + #ifdef __Pyx_IterableCoroutine_USED + PyTypeObject *__pyx_IterableCoroutineType; + #endif + #ifdef __Pyx_Coroutine_USED + PyTypeObject *__pyx_CoroutineAwaitType; + #endif + #ifdef __Pyx_Coroutine_USED + PyTypeObject *__pyx_CoroutineType; + #endif + #if CYTHON_USE_MODULE_STATE + PyObject *__pyx_type_11cython_code_10user_check___pyx_scope_struct____call__; + #endif + PyTypeObject *__pyx_ptype_11cython_code_10user_check___pyx_scope_struct____call__; + PyObject *__pyx_n_s_ADMIN; + PyObject *__pyx_n_s_BaseFilter; + PyObject *__pyx_n_s_BaseMiddleware; + PyObject *__pyx_n_s_CallbackQuery; + PyObject *__pyx_n_s_DB; + PyObject *__pyx_n_s_Message; + PyObject *__pyx_kp_s_Middleware_and_filter_class_to; + PyObject *__pyx_n_s_User_Check; + PyObject *__pyx_n_s_User_Check___call; + PyObject *__pyx_n_s_User_Check___init; + PyObject *__pyx_n_s__2; + PyObject *__pyx_kp_u__3; + PyObject *__pyx_n_s__8; + PyObject *__pyx_n_u_administrator; + PyObject *__pyx_n_s_aiogram; + PyObject *__pyx_n_s_aiogram_filters; + PyObject *__pyx_n_s_aiogram_types; + PyObject *__pyx_n_s_args; + PyObject *__pyx_n_s_asyncio_coroutines; + PyObject *__pyx_n_s_await; + PyObject *__pyx_n_s_bool; + PyObject *__pyx_n_s_bot; + PyObject *__pyx_n_s_call; + PyObject *__pyx_n_s_call_2; + PyObject *__pyx_n_s_chat_id; + PyObject *__pyx_n_s_cid; + PyObject *__pyx_n_s_cline_in_traceback; + PyObject *__pyx_n_s_close; + PyObject *__pyx_n_u_creator; + PyObject *__pyx_n_s_cython_code_user_check; + PyObject *__pyx_kp_s_cython_code_user_check_pyx; + PyObject *__pyx_n_s_data; + PyObject *__pyx_n_s_data_config; + PyObject *__pyx_n_s_db; + PyObject *__pyx_n_s_dict; + PyObject *__pyx_kp_u_disable; + PyObject *__pyx_n_s_doc; + PyObject *__pyx_kp_u_enable; + PyObject *__pyx_n_s_err; + PyObject *__pyx_n_s_error; + PyObject *__pyx_n_s_force; + PyObject *__pyx_n_s_from_user; + PyObject *__pyx_kp_u_gc; + PyObject *__pyx_n_s_get_chat; + PyObject *__pyx_n_s_get_chat_member; + PyObject *__pyx_n_s_id; + PyObject *__pyx_n_s_ids; + PyObject *__pyx_n_s_import; + PyObject *__pyx_n_s_init; + PyObject *__pyx_n_s_init_subclass; + PyObject *__pyx_n_s_initializing; + PyObject *__pyx_n_s_is_coroutine; + PyObject *__pyx_kp_u_isenabled; + PyObject *__pyx_n_u_join_channel; + PyObject *__pyx_n_s_loader; + PyObject *__pyx_n_s_logging; + PyObject *__pyx_n_s_main; + PyObject *__pyx_n_u_member; + PyObject *__pyx_n_s_message; + PyObject *__pyx_n_s_metaclass; + PyObject *__pyx_n_s_module; + PyObject *__pyx_n_s_mro_entries; + PyObject *__pyx_n_s_name; + PyObject *__pyx_n_s_prepare; + PyObject *__pyx_n_s_qualname; + PyObject *__pyx_n_s_reading_db; + PyObject *__pyx_n_s_res; + PyObject *__pyx_n_s_result; + PyObject *__pyx_n_s_return; + PyObject *__pyx_n_s_select_channels; + PyObject *__pyx_n_s_self; + PyObject *__pyx_n_s_send; + PyObject *__pyx_n_s_set_name; + PyObject *__pyx_n_s_spec; + PyObject *__pyx_n_s_status; + PyObject *__pyx_n_s_super; + PyObject *__pyx_n_s_test; + PyObject *__pyx_n_s_throw; + PyObject *__pyx_n_s_user_id; + PyObject *__pyx_n_s_x; + PyObject *__pyx_int_neg_100; + PyObject *__pyx_codeobj_; + PyObject *__pyx_tuple__4; + PyObject *__pyx_tuple__6; + PyObject *__pyx_tuple__7; + PyObject *__pyx_codeobj__5; +} __pyx_mstate; + +#if CYTHON_USE_MODULE_STATE +#ifdef __cplusplus +namespace { + extern struct PyModuleDef __pyx_moduledef; +} /* anonymous namespace */ +#else +static struct PyModuleDef __pyx_moduledef; +#endif + +#define __pyx_mstate(o) ((__pyx_mstate *)__Pyx_PyModule_GetState(o)) + +#define __pyx_mstate_global (__pyx_mstate(PyState_FindModule(&__pyx_moduledef))) + +#define __pyx_m (PyState_FindModule(&__pyx_moduledef)) +#else +static __pyx_mstate __pyx_mstate_global_static = +#ifdef __cplusplus + {}; +#else + {0}; +#endif +static __pyx_mstate *__pyx_mstate_global = &__pyx_mstate_global_static; +#endif +/* #### Code section: module_state_clear ### */ +#if CYTHON_USE_MODULE_STATE +static int __pyx_m_clear(PyObject *m) { + __pyx_mstate *clear_module_state = __pyx_mstate(m); + if (!clear_module_state) return 0; + Py_CLEAR(clear_module_state->__pyx_d); + Py_CLEAR(clear_module_state->__pyx_b); + Py_CLEAR(clear_module_state->__pyx_cython_runtime); + Py_CLEAR(clear_module_state->__pyx_empty_tuple); + Py_CLEAR(clear_module_state->__pyx_empty_bytes); + Py_CLEAR(clear_module_state->__pyx_empty_unicode); + #ifdef __Pyx_CyFunction_USED + Py_CLEAR(clear_module_state->__pyx_CyFunctionType); + #endif + #ifdef __Pyx_FusedFunction_USED + Py_CLEAR(clear_module_state->__pyx_FusedFunctionType); + #endif + Py_CLEAR(clear_module_state->__pyx_ptype_11cython_code_10user_check___pyx_scope_struct____call__); + Py_CLEAR(clear_module_state->__pyx_type_11cython_code_10user_check___pyx_scope_struct____call__); + Py_CLEAR(clear_module_state->__pyx_n_s_ADMIN); + Py_CLEAR(clear_module_state->__pyx_n_s_BaseFilter); + Py_CLEAR(clear_module_state->__pyx_n_s_BaseMiddleware); + Py_CLEAR(clear_module_state->__pyx_n_s_CallbackQuery); + Py_CLEAR(clear_module_state->__pyx_n_s_DB); + Py_CLEAR(clear_module_state->__pyx_n_s_Message); + Py_CLEAR(clear_module_state->__pyx_kp_s_Middleware_and_filter_class_to); + Py_CLEAR(clear_module_state->__pyx_n_s_User_Check); + Py_CLEAR(clear_module_state->__pyx_n_s_User_Check___call); + Py_CLEAR(clear_module_state->__pyx_n_s_User_Check___init); + Py_CLEAR(clear_module_state->__pyx_n_s__2); + Py_CLEAR(clear_module_state->__pyx_kp_u__3); + Py_CLEAR(clear_module_state->__pyx_n_s__8); + Py_CLEAR(clear_module_state->__pyx_n_u_administrator); + Py_CLEAR(clear_module_state->__pyx_n_s_aiogram); + Py_CLEAR(clear_module_state->__pyx_n_s_aiogram_filters); + Py_CLEAR(clear_module_state->__pyx_n_s_aiogram_types); + Py_CLEAR(clear_module_state->__pyx_n_s_args); + Py_CLEAR(clear_module_state->__pyx_n_s_asyncio_coroutines); + Py_CLEAR(clear_module_state->__pyx_n_s_await); + Py_CLEAR(clear_module_state->__pyx_n_s_bool); + Py_CLEAR(clear_module_state->__pyx_n_s_bot); + Py_CLEAR(clear_module_state->__pyx_n_s_call); + Py_CLEAR(clear_module_state->__pyx_n_s_call_2); + Py_CLEAR(clear_module_state->__pyx_n_s_chat_id); + Py_CLEAR(clear_module_state->__pyx_n_s_cid); + Py_CLEAR(clear_module_state->__pyx_n_s_cline_in_traceback); + Py_CLEAR(clear_module_state->__pyx_n_s_close); + Py_CLEAR(clear_module_state->__pyx_n_u_creator); + Py_CLEAR(clear_module_state->__pyx_n_s_cython_code_user_check); + Py_CLEAR(clear_module_state->__pyx_kp_s_cython_code_user_check_pyx); + Py_CLEAR(clear_module_state->__pyx_n_s_data); + Py_CLEAR(clear_module_state->__pyx_n_s_data_config); + Py_CLEAR(clear_module_state->__pyx_n_s_db); + Py_CLEAR(clear_module_state->__pyx_n_s_dict); + Py_CLEAR(clear_module_state->__pyx_kp_u_disable); + Py_CLEAR(clear_module_state->__pyx_n_s_doc); + Py_CLEAR(clear_module_state->__pyx_kp_u_enable); + Py_CLEAR(clear_module_state->__pyx_n_s_err); + Py_CLEAR(clear_module_state->__pyx_n_s_error); + Py_CLEAR(clear_module_state->__pyx_n_s_force); + Py_CLEAR(clear_module_state->__pyx_n_s_from_user); + Py_CLEAR(clear_module_state->__pyx_kp_u_gc); + Py_CLEAR(clear_module_state->__pyx_n_s_get_chat); + Py_CLEAR(clear_module_state->__pyx_n_s_get_chat_member); + Py_CLEAR(clear_module_state->__pyx_n_s_id); + Py_CLEAR(clear_module_state->__pyx_n_s_ids); + Py_CLEAR(clear_module_state->__pyx_n_s_import); + Py_CLEAR(clear_module_state->__pyx_n_s_init); + Py_CLEAR(clear_module_state->__pyx_n_s_init_subclass); + Py_CLEAR(clear_module_state->__pyx_n_s_initializing); + Py_CLEAR(clear_module_state->__pyx_n_s_is_coroutine); + Py_CLEAR(clear_module_state->__pyx_kp_u_isenabled); + Py_CLEAR(clear_module_state->__pyx_n_u_join_channel); + Py_CLEAR(clear_module_state->__pyx_n_s_loader); + Py_CLEAR(clear_module_state->__pyx_n_s_logging); + Py_CLEAR(clear_module_state->__pyx_n_s_main); + Py_CLEAR(clear_module_state->__pyx_n_u_member); + Py_CLEAR(clear_module_state->__pyx_n_s_message); + Py_CLEAR(clear_module_state->__pyx_n_s_metaclass); + Py_CLEAR(clear_module_state->__pyx_n_s_module); + Py_CLEAR(clear_module_state->__pyx_n_s_mro_entries); + Py_CLEAR(clear_module_state->__pyx_n_s_name); + Py_CLEAR(clear_module_state->__pyx_n_s_prepare); + Py_CLEAR(clear_module_state->__pyx_n_s_qualname); + Py_CLEAR(clear_module_state->__pyx_n_s_reading_db); + Py_CLEAR(clear_module_state->__pyx_n_s_res); + Py_CLEAR(clear_module_state->__pyx_n_s_result); + Py_CLEAR(clear_module_state->__pyx_n_s_return); + Py_CLEAR(clear_module_state->__pyx_n_s_select_channels); + Py_CLEAR(clear_module_state->__pyx_n_s_self); + Py_CLEAR(clear_module_state->__pyx_n_s_send); + Py_CLEAR(clear_module_state->__pyx_n_s_set_name); + Py_CLEAR(clear_module_state->__pyx_n_s_spec); + Py_CLEAR(clear_module_state->__pyx_n_s_status); + Py_CLEAR(clear_module_state->__pyx_n_s_super); + Py_CLEAR(clear_module_state->__pyx_n_s_test); + Py_CLEAR(clear_module_state->__pyx_n_s_throw); + Py_CLEAR(clear_module_state->__pyx_n_s_user_id); + Py_CLEAR(clear_module_state->__pyx_n_s_x); + Py_CLEAR(clear_module_state->__pyx_int_neg_100); + Py_CLEAR(clear_module_state->__pyx_codeobj_); + Py_CLEAR(clear_module_state->__pyx_tuple__4); + Py_CLEAR(clear_module_state->__pyx_tuple__6); + Py_CLEAR(clear_module_state->__pyx_tuple__7); + Py_CLEAR(clear_module_state->__pyx_codeobj__5); + return 0; +} +#endif +/* #### Code section: module_state_traverse ### */ +#if CYTHON_USE_MODULE_STATE +static int __pyx_m_traverse(PyObject *m, visitproc visit, void *arg) { + __pyx_mstate *traverse_module_state = __pyx_mstate(m); + if (!traverse_module_state) return 0; + Py_VISIT(traverse_module_state->__pyx_d); + Py_VISIT(traverse_module_state->__pyx_b); + Py_VISIT(traverse_module_state->__pyx_cython_runtime); + Py_VISIT(traverse_module_state->__pyx_empty_tuple); + Py_VISIT(traverse_module_state->__pyx_empty_bytes); + Py_VISIT(traverse_module_state->__pyx_empty_unicode); + #ifdef __Pyx_CyFunction_USED + Py_VISIT(traverse_module_state->__pyx_CyFunctionType); + #endif + #ifdef __Pyx_FusedFunction_USED + Py_VISIT(traverse_module_state->__pyx_FusedFunctionType); + #endif + Py_VISIT(traverse_module_state->__pyx_ptype_11cython_code_10user_check___pyx_scope_struct____call__); + Py_VISIT(traverse_module_state->__pyx_type_11cython_code_10user_check___pyx_scope_struct____call__); + Py_VISIT(traverse_module_state->__pyx_n_s_ADMIN); + Py_VISIT(traverse_module_state->__pyx_n_s_BaseFilter); + Py_VISIT(traverse_module_state->__pyx_n_s_BaseMiddleware); + Py_VISIT(traverse_module_state->__pyx_n_s_CallbackQuery); + Py_VISIT(traverse_module_state->__pyx_n_s_DB); + Py_VISIT(traverse_module_state->__pyx_n_s_Message); + Py_VISIT(traverse_module_state->__pyx_kp_s_Middleware_and_filter_class_to); + Py_VISIT(traverse_module_state->__pyx_n_s_User_Check); + Py_VISIT(traverse_module_state->__pyx_n_s_User_Check___call); + Py_VISIT(traverse_module_state->__pyx_n_s_User_Check___init); + Py_VISIT(traverse_module_state->__pyx_n_s__2); + Py_VISIT(traverse_module_state->__pyx_kp_u__3); + Py_VISIT(traverse_module_state->__pyx_n_s__8); + Py_VISIT(traverse_module_state->__pyx_n_u_administrator); + Py_VISIT(traverse_module_state->__pyx_n_s_aiogram); + Py_VISIT(traverse_module_state->__pyx_n_s_aiogram_filters); + Py_VISIT(traverse_module_state->__pyx_n_s_aiogram_types); + Py_VISIT(traverse_module_state->__pyx_n_s_args); + Py_VISIT(traverse_module_state->__pyx_n_s_asyncio_coroutines); + Py_VISIT(traverse_module_state->__pyx_n_s_await); + Py_VISIT(traverse_module_state->__pyx_n_s_bool); + Py_VISIT(traverse_module_state->__pyx_n_s_bot); + Py_VISIT(traverse_module_state->__pyx_n_s_call); + Py_VISIT(traverse_module_state->__pyx_n_s_call_2); + Py_VISIT(traverse_module_state->__pyx_n_s_chat_id); + Py_VISIT(traverse_module_state->__pyx_n_s_cid); + Py_VISIT(traverse_module_state->__pyx_n_s_cline_in_traceback); + Py_VISIT(traverse_module_state->__pyx_n_s_close); + Py_VISIT(traverse_module_state->__pyx_n_u_creator); + Py_VISIT(traverse_module_state->__pyx_n_s_cython_code_user_check); + Py_VISIT(traverse_module_state->__pyx_kp_s_cython_code_user_check_pyx); + Py_VISIT(traverse_module_state->__pyx_n_s_data); + Py_VISIT(traverse_module_state->__pyx_n_s_data_config); + Py_VISIT(traverse_module_state->__pyx_n_s_db); + Py_VISIT(traverse_module_state->__pyx_n_s_dict); + Py_VISIT(traverse_module_state->__pyx_kp_u_disable); + Py_VISIT(traverse_module_state->__pyx_n_s_doc); + Py_VISIT(traverse_module_state->__pyx_kp_u_enable); + Py_VISIT(traverse_module_state->__pyx_n_s_err); + Py_VISIT(traverse_module_state->__pyx_n_s_error); + Py_VISIT(traverse_module_state->__pyx_n_s_force); + Py_VISIT(traverse_module_state->__pyx_n_s_from_user); + Py_VISIT(traverse_module_state->__pyx_kp_u_gc); + Py_VISIT(traverse_module_state->__pyx_n_s_get_chat); + Py_VISIT(traverse_module_state->__pyx_n_s_get_chat_member); + Py_VISIT(traverse_module_state->__pyx_n_s_id); + Py_VISIT(traverse_module_state->__pyx_n_s_ids); + Py_VISIT(traverse_module_state->__pyx_n_s_import); + Py_VISIT(traverse_module_state->__pyx_n_s_init); + Py_VISIT(traverse_module_state->__pyx_n_s_init_subclass); + Py_VISIT(traverse_module_state->__pyx_n_s_initializing); + Py_VISIT(traverse_module_state->__pyx_n_s_is_coroutine); + Py_VISIT(traverse_module_state->__pyx_kp_u_isenabled); + Py_VISIT(traverse_module_state->__pyx_n_u_join_channel); + Py_VISIT(traverse_module_state->__pyx_n_s_loader); + Py_VISIT(traverse_module_state->__pyx_n_s_logging); + Py_VISIT(traverse_module_state->__pyx_n_s_main); + Py_VISIT(traverse_module_state->__pyx_n_u_member); + Py_VISIT(traverse_module_state->__pyx_n_s_message); + Py_VISIT(traverse_module_state->__pyx_n_s_metaclass); + Py_VISIT(traverse_module_state->__pyx_n_s_module); + Py_VISIT(traverse_module_state->__pyx_n_s_mro_entries); + Py_VISIT(traverse_module_state->__pyx_n_s_name); + Py_VISIT(traverse_module_state->__pyx_n_s_prepare); + Py_VISIT(traverse_module_state->__pyx_n_s_qualname); + Py_VISIT(traverse_module_state->__pyx_n_s_reading_db); + Py_VISIT(traverse_module_state->__pyx_n_s_res); + Py_VISIT(traverse_module_state->__pyx_n_s_result); + Py_VISIT(traverse_module_state->__pyx_n_s_return); + Py_VISIT(traverse_module_state->__pyx_n_s_select_channels); + Py_VISIT(traverse_module_state->__pyx_n_s_self); + Py_VISIT(traverse_module_state->__pyx_n_s_send); + Py_VISIT(traverse_module_state->__pyx_n_s_set_name); + Py_VISIT(traverse_module_state->__pyx_n_s_spec); + Py_VISIT(traverse_module_state->__pyx_n_s_status); + Py_VISIT(traverse_module_state->__pyx_n_s_super); + Py_VISIT(traverse_module_state->__pyx_n_s_test); + Py_VISIT(traverse_module_state->__pyx_n_s_throw); + Py_VISIT(traverse_module_state->__pyx_n_s_user_id); + Py_VISIT(traverse_module_state->__pyx_n_s_x); + Py_VISIT(traverse_module_state->__pyx_int_neg_100); + Py_VISIT(traverse_module_state->__pyx_codeobj_); + Py_VISIT(traverse_module_state->__pyx_tuple__4); + Py_VISIT(traverse_module_state->__pyx_tuple__6); + Py_VISIT(traverse_module_state->__pyx_tuple__7); + Py_VISIT(traverse_module_state->__pyx_codeobj__5); + return 0; +} +#endif +/* #### Code section: module_state_defines ### */ +#define __pyx_d __pyx_mstate_global->__pyx_d +#define __pyx_b __pyx_mstate_global->__pyx_b +#define __pyx_cython_runtime __pyx_mstate_global->__pyx_cython_runtime +#define __pyx_empty_tuple __pyx_mstate_global->__pyx_empty_tuple +#define __pyx_empty_bytes __pyx_mstate_global->__pyx_empty_bytes +#define __pyx_empty_unicode __pyx_mstate_global->__pyx_empty_unicode +#ifdef __Pyx_CyFunction_USED +#define __pyx_CyFunctionType __pyx_mstate_global->__pyx_CyFunctionType +#endif +#ifdef __Pyx_FusedFunction_USED +#define __pyx_FusedFunctionType __pyx_mstate_global->__pyx_FusedFunctionType +#endif +#ifdef __Pyx_Generator_USED +#define __pyx_GeneratorType __pyx_mstate_global->__pyx_GeneratorType +#endif +#ifdef __Pyx_IterableCoroutine_USED +#define __pyx_IterableCoroutineType __pyx_mstate_global->__pyx_IterableCoroutineType +#endif +#ifdef __Pyx_Coroutine_USED +#define __pyx_CoroutineAwaitType __pyx_mstate_global->__pyx_CoroutineAwaitType +#endif +#ifdef __Pyx_Coroutine_USED +#define __pyx_CoroutineType __pyx_mstate_global->__pyx_CoroutineType +#endif +#if CYTHON_USE_MODULE_STATE +#define __pyx_type_11cython_code_10user_check___pyx_scope_struct____call__ __pyx_mstate_global->__pyx_type_11cython_code_10user_check___pyx_scope_struct____call__ +#endif +#define __pyx_ptype_11cython_code_10user_check___pyx_scope_struct____call__ __pyx_mstate_global->__pyx_ptype_11cython_code_10user_check___pyx_scope_struct____call__ +#define __pyx_n_s_ADMIN __pyx_mstate_global->__pyx_n_s_ADMIN +#define __pyx_n_s_BaseFilter __pyx_mstate_global->__pyx_n_s_BaseFilter +#define __pyx_n_s_BaseMiddleware __pyx_mstate_global->__pyx_n_s_BaseMiddleware +#define __pyx_n_s_CallbackQuery __pyx_mstate_global->__pyx_n_s_CallbackQuery +#define __pyx_n_s_DB __pyx_mstate_global->__pyx_n_s_DB +#define __pyx_n_s_Message __pyx_mstate_global->__pyx_n_s_Message +#define __pyx_kp_s_Middleware_and_filter_class_to __pyx_mstate_global->__pyx_kp_s_Middleware_and_filter_class_to +#define __pyx_n_s_User_Check __pyx_mstate_global->__pyx_n_s_User_Check +#define __pyx_n_s_User_Check___call __pyx_mstate_global->__pyx_n_s_User_Check___call +#define __pyx_n_s_User_Check___init __pyx_mstate_global->__pyx_n_s_User_Check___init +#define __pyx_n_s__2 __pyx_mstate_global->__pyx_n_s__2 +#define __pyx_kp_u__3 __pyx_mstate_global->__pyx_kp_u__3 +#define __pyx_n_s__8 __pyx_mstate_global->__pyx_n_s__8 +#define __pyx_n_u_administrator __pyx_mstate_global->__pyx_n_u_administrator +#define __pyx_n_s_aiogram __pyx_mstate_global->__pyx_n_s_aiogram +#define __pyx_n_s_aiogram_filters __pyx_mstate_global->__pyx_n_s_aiogram_filters +#define __pyx_n_s_aiogram_types __pyx_mstate_global->__pyx_n_s_aiogram_types +#define __pyx_n_s_args __pyx_mstate_global->__pyx_n_s_args +#define __pyx_n_s_asyncio_coroutines __pyx_mstate_global->__pyx_n_s_asyncio_coroutines +#define __pyx_n_s_await __pyx_mstate_global->__pyx_n_s_await +#define __pyx_n_s_bool __pyx_mstate_global->__pyx_n_s_bool +#define __pyx_n_s_bot __pyx_mstate_global->__pyx_n_s_bot +#define __pyx_n_s_call __pyx_mstate_global->__pyx_n_s_call +#define __pyx_n_s_call_2 __pyx_mstate_global->__pyx_n_s_call_2 +#define __pyx_n_s_chat_id __pyx_mstate_global->__pyx_n_s_chat_id +#define __pyx_n_s_cid __pyx_mstate_global->__pyx_n_s_cid +#define __pyx_n_s_cline_in_traceback __pyx_mstate_global->__pyx_n_s_cline_in_traceback +#define __pyx_n_s_close __pyx_mstate_global->__pyx_n_s_close +#define __pyx_n_u_creator __pyx_mstate_global->__pyx_n_u_creator +#define __pyx_n_s_cython_code_user_check __pyx_mstate_global->__pyx_n_s_cython_code_user_check +#define __pyx_kp_s_cython_code_user_check_pyx __pyx_mstate_global->__pyx_kp_s_cython_code_user_check_pyx +#define __pyx_n_s_data __pyx_mstate_global->__pyx_n_s_data +#define __pyx_n_s_data_config __pyx_mstate_global->__pyx_n_s_data_config +#define __pyx_n_s_db __pyx_mstate_global->__pyx_n_s_db +#define __pyx_n_s_dict __pyx_mstate_global->__pyx_n_s_dict +#define __pyx_kp_u_disable __pyx_mstate_global->__pyx_kp_u_disable +#define __pyx_n_s_doc __pyx_mstate_global->__pyx_n_s_doc +#define __pyx_kp_u_enable __pyx_mstate_global->__pyx_kp_u_enable +#define __pyx_n_s_err __pyx_mstate_global->__pyx_n_s_err +#define __pyx_n_s_error __pyx_mstate_global->__pyx_n_s_error +#define __pyx_n_s_force __pyx_mstate_global->__pyx_n_s_force +#define __pyx_n_s_from_user __pyx_mstate_global->__pyx_n_s_from_user +#define __pyx_kp_u_gc __pyx_mstate_global->__pyx_kp_u_gc +#define __pyx_n_s_get_chat __pyx_mstate_global->__pyx_n_s_get_chat +#define __pyx_n_s_get_chat_member __pyx_mstate_global->__pyx_n_s_get_chat_member +#define __pyx_n_s_id __pyx_mstate_global->__pyx_n_s_id +#define __pyx_n_s_ids __pyx_mstate_global->__pyx_n_s_ids +#define __pyx_n_s_import __pyx_mstate_global->__pyx_n_s_import +#define __pyx_n_s_init __pyx_mstate_global->__pyx_n_s_init +#define __pyx_n_s_init_subclass __pyx_mstate_global->__pyx_n_s_init_subclass +#define __pyx_n_s_initializing __pyx_mstate_global->__pyx_n_s_initializing +#define __pyx_n_s_is_coroutine __pyx_mstate_global->__pyx_n_s_is_coroutine +#define __pyx_kp_u_isenabled __pyx_mstate_global->__pyx_kp_u_isenabled +#define __pyx_n_u_join_channel __pyx_mstate_global->__pyx_n_u_join_channel +#define __pyx_n_s_loader __pyx_mstate_global->__pyx_n_s_loader +#define __pyx_n_s_logging __pyx_mstate_global->__pyx_n_s_logging +#define __pyx_n_s_main __pyx_mstate_global->__pyx_n_s_main +#define __pyx_n_u_member __pyx_mstate_global->__pyx_n_u_member +#define __pyx_n_s_message __pyx_mstate_global->__pyx_n_s_message +#define __pyx_n_s_metaclass __pyx_mstate_global->__pyx_n_s_metaclass +#define __pyx_n_s_module __pyx_mstate_global->__pyx_n_s_module +#define __pyx_n_s_mro_entries __pyx_mstate_global->__pyx_n_s_mro_entries +#define __pyx_n_s_name __pyx_mstate_global->__pyx_n_s_name +#define __pyx_n_s_prepare __pyx_mstate_global->__pyx_n_s_prepare +#define __pyx_n_s_qualname __pyx_mstate_global->__pyx_n_s_qualname +#define __pyx_n_s_reading_db __pyx_mstate_global->__pyx_n_s_reading_db +#define __pyx_n_s_res __pyx_mstate_global->__pyx_n_s_res +#define __pyx_n_s_result __pyx_mstate_global->__pyx_n_s_result +#define __pyx_n_s_return __pyx_mstate_global->__pyx_n_s_return +#define __pyx_n_s_select_channels __pyx_mstate_global->__pyx_n_s_select_channels +#define __pyx_n_s_self __pyx_mstate_global->__pyx_n_s_self +#define __pyx_n_s_send __pyx_mstate_global->__pyx_n_s_send +#define __pyx_n_s_set_name __pyx_mstate_global->__pyx_n_s_set_name +#define __pyx_n_s_spec __pyx_mstate_global->__pyx_n_s_spec +#define __pyx_n_s_status __pyx_mstate_global->__pyx_n_s_status +#define __pyx_n_s_super __pyx_mstate_global->__pyx_n_s_super +#define __pyx_n_s_test __pyx_mstate_global->__pyx_n_s_test +#define __pyx_n_s_throw __pyx_mstate_global->__pyx_n_s_throw +#define __pyx_n_s_user_id __pyx_mstate_global->__pyx_n_s_user_id +#define __pyx_n_s_x __pyx_mstate_global->__pyx_n_s_x +#define __pyx_int_neg_100 __pyx_mstate_global->__pyx_int_neg_100 +#define __pyx_codeobj_ __pyx_mstate_global->__pyx_codeobj_ +#define __pyx_tuple__4 __pyx_mstate_global->__pyx_tuple__4 +#define __pyx_tuple__6 __pyx_mstate_global->__pyx_tuple__6 +#define __pyx_tuple__7 __pyx_mstate_global->__pyx_tuple__7 +#define __pyx_codeobj__5 __pyx_mstate_global->__pyx_codeobj__5 +/* #### Code section: module_code ### */ + +/* "cython_code/user_check.pyx":17 + * """ + * + * def __init__(self): # <<<<<<<<<<<<<< + * """ + * Initializes the User_Check class. + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_10user_check_10User_Check_1__init__(PyObject *__pyx_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +PyDoc_STRVAR(__pyx_doc_11cython_code_10user_check_10User_Check___init__, "\n Initializes the User_Check class.\n\n Parameters:\n - None\n\n This constructor sets up the ADMIN variable from the configuration.\n "); +static PyMethodDef __pyx_mdef_11cython_code_10user_check_10User_Check_1__init__ = {"__init__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_10user_check_10User_Check_1__init__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_11cython_code_10user_check_10User_Check___init__}; +static PyObject *__pyx_pw_11cython_code_10user_check_10User_Check_1__init__(PyObject *__pyx_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + PyObject *__pyx_v_self = 0; + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[1] = {0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__init__ (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,0}; + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_self)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 17, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__init__") < 0)) __PYX_ERR(0, 17, __pyx_L3_error) + } + } else if (unlikely(__pyx_nargs != 1)) { + goto __pyx_L5_argtuple_error; + } else { + values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + } + __pyx_v_self = values[0]; + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__init__", 1, 1, 1, __pyx_nargs); __PYX_ERR(0, 17, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.user_check.User_Check.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_11cython_code_10user_check_10User_Check___init__(__pyx_self, __pyx_v_self); + + /* function exit code */ + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_10user_check_10User_Check___init__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self) { + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + PyObject *__pyx_t_1 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__init__", 1); + + /* "cython_code/user_check.pyx":26 + * This constructor sets up the ADMIN variable from the configuration. + * """ + * self.ADMIN = ADMIN # <<<<<<<<<<<<<< + * + * async def __call__(self, message: Message, call: CallbackQuery = None) -> bool: + */ + __Pyx_GetModuleGlobalName(__pyx_t_1, __pyx_n_s_ADMIN); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 26, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_1); + if (__Pyx_PyObject_SetAttrStr(__pyx_v_self, __pyx_n_s_ADMIN, __pyx_t_1) < 0) __PYX_ERR(0, 26, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_1); __pyx_t_1 = 0; + + /* "cython_code/user_check.pyx":17 + * """ + * + * def __init__(self): # <<<<<<<<<<<<<< + * """ + * Initializes the User_Check class. + */ + + /* function exit code */ + __pyx_r = Py_None; __Pyx_INCREF(Py_None); + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_1); + __Pyx_AddTraceback("cython_code.user_check.User_Check.__init__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __pyx_L0:; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} +static PyObject *__pyx_gb_11cython_code_10user_check_10User_Check_4generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value); /* proto */ + +/* "cython_code/user_check.pyx":28 + * self.ADMIN = ADMIN + * + * async def __call__(self, message: Message, call: CallbackQuery = None) -> bool: # <<<<<<<<<<<<<< + * """ + * Checks if the user is a member of required channels. + */ + +/* Python wrapper */ +static PyObject *__pyx_pw_11cython_code_10user_check_10User_Check_3__call__(PyObject *__pyx_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +); /*proto*/ +PyDoc_STRVAR(__pyx_doc_11cython_code_10user_check_10User_Check_2__call__, "\n Checks if the user is a member of required channels.\n\n Parameters:\n - message (Message): The incoming message object. This is used to obtain user information.\n - call (CallbackQuery): The incoming callback query object. This is used if the message object is not available.\n\n Returns:\n - bool: Returns True if the user is not a member of the required channels and False otherwise.\n\n This method:\n - Reads the database to check if channel membership verification is required.\n - If required, verifies the user's membership status in each specified channel.\n - Logs errors if any exceptions occur during the check.\n "); +static PyMethodDef __pyx_mdef_11cython_code_10user_check_10User_Check_3__call__ = {"__call__", (PyCFunction)(void*)(__Pyx_PyCFunction_FastCallWithKeywords)__pyx_pw_11cython_code_10user_check_10User_Check_3__call__, __Pyx_METH_FASTCALL|METH_KEYWORDS, __pyx_doc_11cython_code_10user_check_10User_Check_2__call__}; +static PyObject *__pyx_pw_11cython_code_10user_check_10User_Check_3__call__(PyObject *__pyx_self, +#if CYTHON_METH_FASTCALL +PyObject *const *__pyx_args, Py_ssize_t __pyx_nargs, PyObject *__pyx_kwds +#else +PyObject *__pyx_args, PyObject *__pyx_kwds +#endif +) { + PyObject *__pyx_v_self = 0; + PyObject *__pyx_v_message = 0; + PyObject *__pyx_v_call = 0; + #if !CYTHON_METH_FASTCALL + CYTHON_UNUSED Py_ssize_t __pyx_nargs; + #endif + CYTHON_UNUSED PyObject *const *__pyx_kwvalues; + PyObject* values[3] = {0,0,0}; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + PyObject *__pyx_r = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__call__ (wrapper)", 0); + #if !CYTHON_METH_FASTCALL + #if CYTHON_ASSUME_SAFE_MACROS + __pyx_nargs = PyTuple_GET_SIZE(__pyx_args); + #else + __pyx_nargs = PyTuple_Size(__pyx_args); if (unlikely(__pyx_nargs < 0)) return NULL; + #endif + #endif + __pyx_kwvalues = __Pyx_KwValues_FASTCALL(__pyx_args, __pyx_nargs); + { + PyObject **__pyx_pyargnames[] = {&__pyx_n_s_self,&__pyx_n_s_message,&__pyx_n_s_call,0}; + values[2] = __Pyx_Arg_NewRef_FASTCALL(((PyObject *)Py_None)); + if (__pyx_kwds) { + Py_ssize_t kw_args; + switch (__pyx_nargs) { + case 3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + CYTHON_FALLTHROUGH; + case 1: values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + CYTHON_FALLTHROUGH; + case 0: break; + default: goto __pyx_L5_argtuple_error; + } + kw_args = __Pyx_NumKwargs_FASTCALL(__pyx_kwds); + switch (__pyx_nargs) { + case 0: + if (likely((values[0] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_self)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[0]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 28, __pyx_L3_error) + else goto __pyx_L5_argtuple_error; + CYTHON_FALLTHROUGH; + case 1: + if (likely((values[1] = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_message)) != 0)) { + (void)__Pyx_Arg_NewRef_FASTCALL(values[1]); + kw_args--; + } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 28, __pyx_L3_error) + else { + __Pyx_RaiseArgtupleInvalid("__call__", 0, 2, 3, 1); __PYX_ERR(0, 28, __pyx_L3_error) + } + CYTHON_FALLTHROUGH; + case 2: + if (kw_args > 0) { + PyObject* value = __Pyx_GetKwValue_FASTCALL(__pyx_kwds, __pyx_kwvalues, __pyx_n_s_call); + if (value) { values[2] = __Pyx_Arg_NewRef_FASTCALL(value); kw_args--; } + else if (unlikely(PyErr_Occurred())) __PYX_ERR(0, 28, __pyx_L3_error) + } + } + if (unlikely(kw_args > 0)) { + const Py_ssize_t kwd_pos_args = __pyx_nargs; + if (unlikely(__Pyx_ParseOptionalKeywords(__pyx_kwds, __pyx_kwvalues, __pyx_pyargnames, 0, values + 0, kwd_pos_args, "__call__") < 0)) __PYX_ERR(0, 28, __pyx_L3_error) + } + } else { + switch (__pyx_nargs) { + case 3: values[2] = __Pyx_Arg_FASTCALL(__pyx_args, 2); + CYTHON_FALLTHROUGH; + case 2: values[1] = __Pyx_Arg_FASTCALL(__pyx_args, 1); + values[0] = __Pyx_Arg_FASTCALL(__pyx_args, 0); + break; + default: goto __pyx_L5_argtuple_error; + } + } + __pyx_v_self = values[0]; + __pyx_v_message = values[1]; + __pyx_v_call = values[2]; + } + goto __pyx_L6_skip; + __pyx_L5_argtuple_error:; + __Pyx_RaiseArgtupleInvalid("__call__", 0, 2, 3, __pyx_nargs); __PYX_ERR(0, 28, __pyx_L3_error) + __pyx_L6_skip:; + goto __pyx_L4_argument_unpacking_done; + __pyx_L3_error:; + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_AddTraceback("cython_code.user_check.User_Check.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __Pyx_RefNannyFinishContext(); + return NULL; + __pyx_L4_argument_unpacking_done:; + __pyx_r = __pyx_pf_11cython_code_10user_check_10User_Check_2__call__(__pyx_self, __pyx_v_self, __pyx_v_message, __pyx_v_call); + + /* function exit code */ + { + Py_ssize_t __pyx_temp; + for (__pyx_temp=0; __pyx_temp < (Py_ssize_t)(sizeof(values)/sizeof(values[0])); ++__pyx_temp) { + __Pyx_Arg_XDECREF_FASTCALL(values[__pyx_temp]); + } + } + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_pf_11cython_code_10user_check_10User_Check_2__call__(CYTHON_UNUSED PyObject *__pyx_self, PyObject *__pyx_v_self, PyObject *__pyx_v_message, PyObject *__pyx_v_call) { + struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__ *__pyx_cur_scope; + PyObject *__pyx_r = NULL; + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__call__", 0); + __pyx_cur_scope = (struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__ *)__pyx_tp_new_11cython_code_10user_check___pyx_scope_struct____call__(__pyx_ptype_11cython_code_10user_check___pyx_scope_struct____call__, __pyx_empty_tuple, NULL); + if (unlikely(!__pyx_cur_scope)) { + __pyx_cur_scope = ((struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__ *)Py_None); + __Pyx_INCREF(Py_None); + __PYX_ERR(0, 28, __pyx_L1_error) + } else { + __Pyx_GOTREF((PyObject *)__pyx_cur_scope); + } + __pyx_cur_scope->__pyx_v_self = __pyx_v_self; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_self); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_self); + __pyx_cur_scope->__pyx_v_message = __pyx_v_message; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_message); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_message); + __pyx_cur_scope->__pyx_v_call = __pyx_v_call; + __Pyx_INCREF(__pyx_cur_scope->__pyx_v_call); + __Pyx_GIVEREF(__pyx_cur_scope->__pyx_v_call); + { + __pyx_CoroutineObject *gen = __Pyx_Coroutine_New((__pyx_coroutine_body_t) __pyx_gb_11cython_code_10user_check_10User_Check_4generator, __pyx_codeobj_, (PyObject *) __pyx_cur_scope, __pyx_n_s_call_2, __pyx_n_s_User_Check___call, __pyx_n_s_cython_code_user_check); if (unlikely(!gen)) __PYX_ERR(0, 28, __pyx_L1_error) + __Pyx_DECREF(__pyx_cur_scope); + __Pyx_RefNannyFinishContext(); + return (PyObject *) gen; + } + + /* function exit code */ + __pyx_L1_error:; + __Pyx_AddTraceback("cython_code.user_check.User_Check.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_r = NULL; + __Pyx_DECREF((PyObject *)__pyx_cur_scope); + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +static PyObject *__pyx_gb_11cython_code_10user_check_10User_Check_4generator(__pyx_CoroutineObject *__pyx_generator, CYTHON_UNUSED PyThreadState *__pyx_tstate, PyObject *__pyx_sent_value) /* generator body */ +{ + struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__ *__pyx_cur_scope = ((struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__ *)__pyx_generator->closure); + PyObject *__pyx_r = NULL; + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + unsigned int __pyx_t_7; + int __pyx_t_8; + PyObject *__pyx_t_9 = NULL; + PyObject *__pyx_t_10 = NULL; + PyObject *__pyx_t_11 = NULL; + int __pyx_t_12; + PyObject *__pyx_t_13 = NULL; + PyObject *__pyx_t_14 = NULL; + PyObject *__pyx_t_15 = NULL; + int __pyx_t_16; + char const *__pyx_t_17; + PyObject *__pyx_t_18 = NULL; + PyObject *__pyx_t_19 = NULL; + PyObject *__pyx_t_20 = NULL; + PyObject *__pyx_t_21 = NULL; + PyObject *__pyx_t_22 = NULL; + PyObject *__pyx_t_23 = NULL; + Py_ssize_t __pyx_t_24; + PyObject *(*__pyx_t_25)(PyObject *); + int __pyx_t_26; + PyObject *__pyx_t_27 = NULL; + char const *__pyx_t_28; + char const *__pyx_t_29; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__call__", 0); + switch (__pyx_generator->resume_label) { + case 0: goto __pyx_L3_first_run; + case 1: goto __pyx_L39_resume_from_await; + case 2: goto __pyx_L48_resume_from_await; + default: /* CPython raises the right error here */ + __Pyx_RefNannyFinishContext(); + return NULL; + } + __pyx_L3_first_run:; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 28, __pyx_L1_error) + + /* "cython_code/user_check.pyx":44 + * - Logs errors if any exceptions occur during the check. + * """ + * try: # <<<<<<<<<<<<<< + * # Retrieve the channel membership check requirement from the database + * data = DB.reading_db() + */ + { + __Pyx_ExceptionSave(&__pyx_t_1, &__pyx_t_2, &__pyx_t_3); + __Pyx_XGOTREF(__pyx_t_1); + __Pyx_XGOTREF(__pyx_t_2); + __Pyx_XGOTREF(__pyx_t_3); + /*try:*/ { + + /* "cython_code/user_check.pyx":46 + * try: + * # Retrieve the channel membership check requirement from the database + * data = DB.reading_db() # <<<<<<<<<<<<<< + * if data['join_channel']: + * try: + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_DB); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 46, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_reading_db); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 46, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 46, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_GIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_v_data = __pyx_t_4; + __pyx_t_4 = 0; + + /* "cython_code/user_check.pyx":47 + * # Retrieve the channel membership check requirement from the database + * data = DB.reading_db() + * if data['join_channel']: # <<<<<<<<<<<<<< + * try: + * # Try to get the user ID from the message object + */ + __pyx_t_4 = __Pyx_PyObject_Dict_GetItem(__pyx_cur_scope->__pyx_v_data, __pyx_n_u_join_channel); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 47, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 47, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_8) { + + /* "cython_code/user_check.pyx":48 + * data = DB.reading_db() + * if data['join_channel']: + * try: # <<<<<<<<<<<<<< + * # Try to get the user ID from the message object + * cid = message.from_user.id + */ + { + __Pyx_ExceptionSave(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + /*try:*/ { + + /* "cython_code/user_check.pyx":50 + * try: + * # Try to get the user ID from the message object + * cid = message.from_user.id # <<<<<<<<<<<<<< + * except Exception as err: + * # If message object is not available, use callback query object + */ + __pyx_t_4 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_message, __pyx_n_s_from_user); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 50, __pyx_L11_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_4, __pyx_n_s_id); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 50, __pyx_L11_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_GIVEREF(__pyx_t_6); + __pyx_cur_scope->__pyx_v_cid = __pyx_t_6; + __pyx_t_6 = 0; + + /* "cython_code/user_check.pyx":48 + * data = DB.reading_db() + * if data['join_channel']: + * try: # <<<<<<<<<<<<<< + * # Try to get the user ID from the message object + * cid = message.from_user.id + */ + } + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + goto __pyx_L16_try_end; + __pyx_L11_error:; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "cython_code/user_check.pyx":51 + * # Try to get the user ID from the message object + * cid = message.from_user.id + * except Exception as err: # <<<<<<<<<<<<<< + * # If message object is not available, use callback query object + * cid = call.from_user.id + */ + __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); + if (__pyx_t_12) { + __Pyx_AddTraceback("cython_code.user_check.User_Check.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_4, &__pyx_t_5) < 0) __PYX_ERR(0, 51, __pyx_L13_except_error) + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_v_err = __pyx_t_4; + /*try:*/ { + + /* "cython_code/user_check.pyx":53 + * except Exception as err: + * # If message object is not available, use callback query object + * cid = call.from_user.id # <<<<<<<<<<<<<< + * logging.error(err) + * + */ + __pyx_t_13 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_call, __pyx_n_s_from_user); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 53, __pyx_L22_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_14 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_id); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 53, __pyx_L22_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_cid); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_cid, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_t_14 = 0; + + /* "cython_code/user_check.pyx":54 + * # If message object is not available, use callback query object + * cid = call.from_user.id + * logging.error(err) # <<<<<<<<<<<<<< + * + * # If the user is not the admin, perform the channel check + */ + __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_logging); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 54, __pyx_L22_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_15 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_error); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 54, __pyx_L22_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_15))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_15); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_15); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_15, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_cur_scope->__pyx_v_err}; + __pyx_t_14 = __Pyx_PyObject_FastCall(__pyx_t_15, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 54, __pyx_L22_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + } + + /* "cython_code/user_check.pyx":51 + * # Try to get the user ID from the message object + * cid = message.from_user.id + * except Exception as err: # <<<<<<<<<<<<<< + * # If message object is not available, use callback query object + * cid = call.from_user.id + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_err); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_err); __pyx_cur_scope->__pyx_v_err = 0; + goto __pyx_L23; + } + __pyx_L22_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_assign + __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_21, &__pyx_t_22, &__pyx_t_23); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20) < 0)) __Pyx_ErrFetch(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20); + __Pyx_XGOTREF(__pyx_t_18); + __Pyx_XGOTREF(__pyx_t_19); + __Pyx_XGOTREF(__pyx_t_20); + __Pyx_XGOTREF(__pyx_t_21); + __Pyx_XGOTREF(__pyx_t_22); + __Pyx_XGOTREF(__pyx_t_23); + __pyx_t_12 = __pyx_lineno; __pyx_t_16 = __pyx_clineno; __pyx_t_17 = __pyx_filename; + { + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_err); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_err); __pyx_cur_scope->__pyx_v_err = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_21); + __Pyx_XGIVEREF(__pyx_t_22); + __Pyx_XGIVEREF(__pyx_t_23); + __Pyx_ExceptionReset(__pyx_t_21, __pyx_t_22, __pyx_t_23); + } + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_XGIVEREF(__pyx_t_20); + __Pyx_ErrRestore(__pyx_t_18, __pyx_t_19, __pyx_t_20); + __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; __pyx_t_21 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; + __pyx_lineno = __pyx_t_12; __pyx_clineno = __pyx_t_16; __pyx_filename = __pyx_t_17; + goto __pyx_L13_except_error; + } + __pyx_L23:; + } + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L12_exception_handled; + } + goto __pyx_L13_except_error; + + /* "cython_code/user_check.pyx":48 + * data = DB.reading_db() + * if data['join_channel']: + * try: # <<<<<<<<<<<<<< + * # Try to get the user ID from the message object + * cid = message.from_user.id + */ + __pyx_L13_except_error:; + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11); + goto __pyx_L4_error; + __pyx_L12_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ExceptionReset(__pyx_t_9, __pyx_t_10, __pyx_t_11); + __pyx_L16_try_end:; + } + + /* "cython_code/user_check.pyx":57 + * + * # If the user is not the admin, perform the channel check + * if cid != self.ADMIN: # <<<<<<<<<<<<<< + * force = False + * result = db.select_channels() + */ + __pyx_t_5 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_self, __pyx_n_s_ADMIN); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 57, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_4 = PyObject_RichCompare(__pyx_cur_scope->__pyx_v_cid, __pyx_t_5, Py_NE); __Pyx_XGOTREF(__pyx_t_4); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 57, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_8 = __Pyx_PyObject_IsTrue(__pyx_t_4); if (unlikely((__pyx_t_8 < 0))) __PYX_ERR(0, 57, __pyx_L4_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__pyx_t_8) { + + /* "cython_code/user_check.pyx":58 + * # If the user is not the admin, perform the channel check + * if cid != self.ADMIN: + * force = False # <<<<<<<<<<<<<< + * result = db.select_channels() + * for x in result: + */ + __pyx_cur_scope->__pyx_v_force = 0; + + /* "cython_code/user_check.pyx":59 + * if cid != self.ADMIN: + * force = False + * result = db.select_channels() # <<<<<<<<<<<<<< + * for x in result: + * try: + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_db); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 59, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_select_channels); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 59, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_5 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_5)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_5); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_5, NULL}; + __pyx_t_4 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_7, 0+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 59, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __Pyx_GIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_v_result = __pyx_t_4; + __pyx_t_4 = 0; + + /* "cython_code/user_check.pyx":60 + * force = False + * result = db.select_channels() + * for x in result: # <<<<<<<<<<<<<< + * try: + * # Construct the chat ID for the channel + */ + if (likely(PyList_CheckExact(__pyx_cur_scope->__pyx_v_result)) || PyTuple_CheckExact(__pyx_cur_scope->__pyx_v_result)) { + __pyx_t_4 = __pyx_cur_scope->__pyx_v_result; __Pyx_INCREF(__pyx_t_4); + __pyx_t_24 = 0; + __pyx_t_25 = NULL; + } else { + __pyx_t_24 = -1; __pyx_t_4 = PyObject_GetIter(__pyx_cur_scope->__pyx_v_result); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 60, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_t_25 = __Pyx_PyObject_GetIterNextFunc(__pyx_t_4); if (unlikely(!__pyx_t_25)) __PYX_ERR(0, 60, __pyx_L4_error) + } + for (;;) { + if (likely(!__pyx_t_25)) { + if (likely(PyList_CheckExact(__pyx_t_4))) { + { + Py_ssize_t __pyx_temp = __Pyx_PyList_GET_SIZE(__pyx_t_4); + #if !CYTHON_ASSUME_SAFE_MACROS + if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 60, __pyx_L4_error) + #endif + if (__pyx_t_24 >= __pyx_temp) break; + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_6 = PyList_GET_ITEM(__pyx_t_4, __pyx_t_24); __Pyx_INCREF(__pyx_t_6); __pyx_t_24++; if (unlikely((0 < 0))) __PYX_ERR(0, 60, __pyx_L4_error) + #else + __pyx_t_6 = __Pyx_PySequence_ITEM(__pyx_t_4, __pyx_t_24); __pyx_t_24++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 60, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_6); + #endif + } else { + { + Py_ssize_t __pyx_temp = __Pyx_PyTuple_GET_SIZE(__pyx_t_4); + #if !CYTHON_ASSUME_SAFE_MACROS + if (unlikely((__pyx_temp < 0))) __PYX_ERR(0, 60, __pyx_L4_error) + #endif + if (__pyx_t_24 >= __pyx_temp) break; + } + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + __pyx_t_6 = PyTuple_GET_ITEM(__pyx_t_4, __pyx_t_24); __Pyx_INCREF(__pyx_t_6); __pyx_t_24++; if (unlikely((0 < 0))) __PYX_ERR(0, 60, __pyx_L4_error) + #else + __pyx_t_6 = __Pyx_PySequence_ITEM(__pyx_t_4, __pyx_t_24); __pyx_t_24++; if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 60, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_6); + #endif + } + } else { + __pyx_t_6 = __pyx_t_25(__pyx_t_4); + if (unlikely(!__pyx_t_6)) { + PyObject* exc_type = PyErr_Occurred(); + if (exc_type) { + if (likely(__Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration))) PyErr_Clear(); + else __PYX_ERR(0, 60, __pyx_L4_error) + } + break; + } + __Pyx_GOTREF(__pyx_t_6); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_x); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_x, __pyx_t_6); + __Pyx_GIVEREF(__pyx_t_6); + __pyx_t_6 = 0; + + /* "cython_code/user_check.pyx":61 + * result = db.select_channels() + * for x in result: + * try: # <<<<<<<<<<<<<< + * # Construct the chat ID for the channel + * ids = str(-100) + str(x[1]) + */ + { + __Pyx_ExceptionSave(&__pyx_t_11, &__pyx_t_10, &__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_9); + /*try:*/ { + + /* "cython_code/user_check.pyx":63 + * try: + * # Construct the chat ID for the channel + * ids = str(-100) + str(x[1]) # <<<<<<<<<<<<<< + * await bot.get_chat(ids) + * try: + */ + __pyx_t_6 = __Pyx_PyObject_Unicode(__pyx_int_neg_100); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 63, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_5 = __Pyx_GetItemInt(__pyx_cur_scope->__pyx_v_x, 1, long, 1, __Pyx_PyInt_From_long, 0, 0, 1); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 63, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_14 = __Pyx_PyObject_Unicode(__pyx_t_5); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 63, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyUnicode_ConcatInPlace(__pyx_t_6, __pyx_t_14); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 63, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_ids); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_ids, __pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_t_5 = 0; + + /* "cython_code/user_check.pyx":64 + * # Construct the chat ID for the channel + * ids = str(-100) + str(x[1]) + * await bot.get_chat(ids) # <<<<<<<<<<<<<< + * try: + * # Check the user's membership status in the channel + */ + __Pyx_GetModuleGlobalName(__pyx_t_14, __pyx_n_s_bot); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 64, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_14); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_14, __pyx_n_s_get_chat); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 64, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __pyx_t_14 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_6))) { + __pyx_t_14 = PyMethod_GET_SELF(__pyx_t_6); + if (likely(__pyx_t_14)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_6); + __Pyx_INCREF(__pyx_t_14); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_6, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_14, __pyx_cur_scope->__pyx_v_ids}; + __pyx_t_5 = __Pyx_PyObject_FastCall(__pyx_t_6, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 64, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_5); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_t_5); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XGOTREF(__pyx_r); + if (likely(__pyx_r)) { + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __Pyx_XGIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; + __Pyx_XGIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; + __Pyx_XGIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_t_3 = __pyx_t_4; + __Pyx_XGIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_t_4 = __pyx_t_9; + __Pyx_XGIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_t_5 = __pyx_t_10; + __Pyx_XGIVEREF(__pyx_t_11); + __pyx_cur_scope->__pyx_t_6 = __pyx_t_11; + __pyx_cur_scope->__pyx_t_7 = __pyx_t_24; + __pyx_cur_scope->__pyx_t_8 = __pyx_t_25; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, awaiting value */ + __pyx_generator->resume_label = 1; + return __pyx_r; + __pyx_L39_resume_from_await:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_2); + __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = 0; + __Pyx_XGOTREF(__pyx_t_3); + __pyx_t_4 = __pyx_cur_scope->__pyx_t_3; + __pyx_cur_scope->__pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_t_4); + __pyx_t_9 = __pyx_cur_scope->__pyx_t_4; + __pyx_cur_scope->__pyx_t_4 = 0; + __Pyx_XGOTREF(__pyx_t_9); + __pyx_t_10 = __pyx_cur_scope->__pyx_t_5; + __pyx_cur_scope->__pyx_t_5 = 0; + __Pyx_XGOTREF(__pyx_t_10); + __pyx_t_11 = __pyx_cur_scope->__pyx_t_6; + __pyx_cur_scope->__pyx_t_6 = 0; + __Pyx_XGOTREF(__pyx_t_11); + __pyx_t_24 = __pyx_cur_scope->__pyx_t_7; + __pyx_t_25 = __pyx_cur_scope->__pyx_t_8; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 64, __pyx_L31_error) + } else { + PyObject* exc_type = __Pyx_PyErr_CurrentExceptionType(); + if (exc_type) { + if (likely(exc_type == PyExc_StopIteration || (exc_type != PyExc_GeneratorExit && __Pyx_PyErr_GivenExceptionMatches(exc_type, PyExc_StopIteration)))) PyErr_Clear(); + else __PYX_ERR(0, 64, __pyx_L31_error) + } + } + + /* "cython_code/user_check.pyx":65 + * ids = str(-100) + str(x[1]) + * await bot.get_chat(ids) + * try: # <<<<<<<<<<<<<< + * # Check the user's membership status in the channel + * res = await bot.get_chat_member(chat_id=ids, user_id=cid) + */ + { + __Pyx_ExceptionSave(&__pyx_t_23, &__pyx_t_22, &__pyx_t_21); + __Pyx_XGOTREF(__pyx_t_23); + __Pyx_XGOTREF(__pyx_t_22); + __Pyx_XGOTREF(__pyx_t_21); + /*try:*/ { + + /* "cython_code/user_check.pyx":67 + * try: + * # Check the user's membership status in the channel + * res = await bot.get_chat_member(chat_id=ids, user_id=cid) # <<<<<<<<<<<<<< + * except: + * # Continue if unable to retrieve chat member information + */ + __Pyx_GetModuleGlobalName(__pyx_t_5, __pyx_n_s_bot); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 67, __pyx_L40_error) + __Pyx_GOTREF(__pyx_t_5); + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_t_5, __pyx_n_s_get_chat_member); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 67, __pyx_L40_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_t_5 = __Pyx_PyDict_NewPresized(2); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 67, __pyx_L40_error) + __Pyx_GOTREF(__pyx_t_5); + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_chat_id, __pyx_cur_scope->__pyx_v_ids) < 0) __PYX_ERR(0, 67, __pyx_L40_error) + if (PyDict_SetItem(__pyx_t_5, __pyx_n_s_user_id, __pyx_cur_scope->__pyx_v_cid) < 0) __PYX_ERR(0, 67, __pyx_L40_error) + __pyx_t_14 = __Pyx_PyObject_Call(__pyx_t_6, __pyx_empty_tuple, __pyx_t_5); if (unlikely(!__pyx_t_14)) __PYX_ERR(0, 67, __pyx_L40_error) + __Pyx_GOTREF(__pyx_t_14); + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __pyx_r = __Pyx_Coroutine_Yield_From(__pyx_generator, __pyx_t_14); + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XGOTREF(__pyx_r); + if (likely(__pyx_r)) { + __Pyx_XGIVEREF(__pyx_t_1); + __pyx_cur_scope->__pyx_t_0 = __pyx_t_1; + __Pyx_XGIVEREF(__pyx_t_2); + __pyx_cur_scope->__pyx_t_1 = __pyx_t_2; + __Pyx_XGIVEREF(__pyx_t_3); + __pyx_cur_scope->__pyx_t_2 = __pyx_t_3; + __Pyx_XGIVEREF(__pyx_t_4); + __pyx_cur_scope->__pyx_t_3 = __pyx_t_4; + __Pyx_XGIVEREF(__pyx_t_9); + __pyx_cur_scope->__pyx_t_4 = __pyx_t_9; + __Pyx_XGIVEREF(__pyx_t_10); + __pyx_cur_scope->__pyx_t_5 = __pyx_t_10; + __Pyx_XGIVEREF(__pyx_t_11); + __pyx_cur_scope->__pyx_t_6 = __pyx_t_11; + __Pyx_XGIVEREF(__pyx_t_21); + __pyx_cur_scope->__pyx_t_9 = __pyx_t_21; + __Pyx_XGIVEREF(__pyx_t_22); + __pyx_cur_scope->__pyx_t_10 = __pyx_t_22; + __Pyx_XGIVEREF(__pyx_t_23); + __pyx_cur_scope->__pyx_t_11 = __pyx_t_23; + __pyx_cur_scope->__pyx_t_7 = __pyx_t_24; + __pyx_cur_scope->__pyx_t_8 = __pyx_t_25; + __Pyx_XGIVEREF(__pyx_r); + __Pyx_RefNannyFinishContext(); + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + /* return from generator, awaiting value */ + __pyx_generator->resume_label = 2; + return __pyx_r; + __pyx_L48_resume_from_await:; + __pyx_t_1 = __pyx_cur_scope->__pyx_t_0; + __pyx_cur_scope->__pyx_t_0 = 0; + __Pyx_XGOTREF(__pyx_t_1); + __pyx_t_2 = __pyx_cur_scope->__pyx_t_1; + __pyx_cur_scope->__pyx_t_1 = 0; + __Pyx_XGOTREF(__pyx_t_2); + __pyx_t_3 = __pyx_cur_scope->__pyx_t_2; + __pyx_cur_scope->__pyx_t_2 = 0; + __Pyx_XGOTREF(__pyx_t_3); + __pyx_t_4 = __pyx_cur_scope->__pyx_t_3; + __pyx_cur_scope->__pyx_t_3 = 0; + __Pyx_XGOTREF(__pyx_t_4); + __pyx_t_9 = __pyx_cur_scope->__pyx_t_4; + __pyx_cur_scope->__pyx_t_4 = 0; + __Pyx_XGOTREF(__pyx_t_9); + __pyx_t_10 = __pyx_cur_scope->__pyx_t_5; + __pyx_cur_scope->__pyx_t_5 = 0; + __Pyx_XGOTREF(__pyx_t_10); + __pyx_t_11 = __pyx_cur_scope->__pyx_t_6; + __pyx_cur_scope->__pyx_t_6 = 0; + __Pyx_XGOTREF(__pyx_t_11); + __pyx_t_21 = __pyx_cur_scope->__pyx_t_9; + __pyx_cur_scope->__pyx_t_9 = 0; + __Pyx_XGOTREF(__pyx_t_21); + __pyx_t_22 = __pyx_cur_scope->__pyx_t_10; + __pyx_cur_scope->__pyx_t_10 = 0; + __Pyx_XGOTREF(__pyx_t_22); + __pyx_t_23 = __pyx_cur_scope->__pyx_t_11; + __pyx_cur_scope->__pyx_t_11 = 0; + __Pyx_XGOTREF(__pyx_t_23); + __pyx_t_24 = __pyx_cur_scope->__pyx_t_7; + __pyx_t_25 = __pyx_cur_scope->__pyx_t_8; + if (unlikely(!__pyx_sent_value)) __PYX_ERR(0, 67, __pyx_L40_error) + __pyx_t_14 = __pyx_sent_value; __Pyx_INCREF(__pyx_t_14); + } else { + __pyx_t_14 = NULL; + if (__Pyx_PyGen_FetchStopIterationValue(&__pyx_t_14) < 0) __PYX_ERR(0, 67, __pyx_L40_error) + __Pyx_GOTREF(__pyx_t_14); + } + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_res); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_res, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + __pyx_t_14 = 0; + + /* "cython_code/user_check.pyx":65 + * ids = str(-100) + str(x[1]) + * await bot.get_chat(ids) + * try: # <<<<<<<<<<<<<< + * # Check the user's membership status in the channel + * res = await bot.get_chat_member(chat_id=ids, user_id=cid) + */ + } + __Pyx_XDECREF(__pyx_t_23); __pyx_t_23 = 0; + __Pyx_XDECREF(__pyx_t_22); __pyx_t_22 = 0; + __Pyx_XDECREF(__pyx_t_21); __pyx_t_21 = 0; + goto __pyx_L47_try_end; + __pyx_L40_error:; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "cython_code/user_check.pyx":68 + * # Check the user's membership status in the channel + * res = await bot.get_chat_member(chat_id=ids, user_id=cid) + * except: # <<<<<<<<<<<<<< + * # Continue if unable to retrieve chat member information + * continue + */ + /*except:*/ { + __Pyx_AddTraceback("cython_code.user_check.User_Check.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_14, &__pyx_t_5, &__pyx_t_6) < 0) __PYX_ERR(0, 68, __pyx_L42_except_error) + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_6); + + /* "cython_code/user_check.pyx":70 + * except: + * # Continue if unable to retrieve chat member information + * continue # <<<<<<<<<<<<<< + * # If the user is not a member, administrator, or creator, set force to True + * if res.status == 'member' or res.status == 'administrator' or res.status == 'creator': + */ + goto __pyx_L49_except_continue; + __pyx_L49_except_continue:; + __Pyx_DECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + goto __pyx_L46_try_continue; + } + + /* "cython_code/user_check.pyx":65 + * ids = str(-100) + str(x[1]) + * await bot.get_chat(ids) + * try: # <<<<<<<<<<<<<< + * # Check the user's membership status in the channel + * res = await bot.get_chat_member(chat_id=ids, user_id=cid) + */ + __pyx_L42_except_error:; + __Pyx_XGIVEREF(__pyx_t_23); + __Pyx_XGIVEREF(__pyx_t_22); + __Pyx_XGIVEREF(__pyx_t_21); + __Pyx_ExceptionReset(__pyx_t_23, __pyx_t_22, __pyx_t_21); + goto __pyx_L31_error; + __pyx_L46_try_continue:; + __Pyx_XGIVEREF(__pyx_t_23); + __Pyx_XGIVEREF(__pyx_t_22); + __Pyx_XGIVEREF(__pyx_t_21); + __Pyx_ExceptionReset(__pyx_t_23, __pyx_t_22, __pyx_t_21); + goto __pyx_L37_try_continue; + __pyx_L47_try_end:; + } + + /* "cython_code/user_check.pyx":72 + * continue + * # If the user is not a member, administrator, or creator, set force to True + * if res.status == 'member' or res.status == 'administrator' or res.status == 'creator': # <<<<<<<<<<<<<< + * pass + * else: + */ + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_res, __pyx_n_s_status); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 72, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_26 = (__Pyx_PyUnicode_Equals(__pyx_t_6, __pyx_n_u_member, Py_EQ)); if (unlikely((__pyx_t_26 < 0))) __PYX_ERR(0, 72, __pyx_L31_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (!__pyx_t_26) { + } else { + __pyx_t_8 = __pyx_t_26; + goto __pyx_L52_bool_binop_done; + } + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_res, __pyx_n_s_status); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 72, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_26 = (__Pyx_PyUnicode_Equals(__pyx_t_6, __pyx_n_u_administrator, Py_EQ)); if (unlikely((__pyx_t_26 < 0))) __PYX_ERR(0, 72, __pyx_L31_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + if (!__pyx_t_26) { + } else { + __pyx_t_8 = __pyx_t_26; + goto __pyx_L52_bool_binop_done; + } + __pyx_t_6 = __Pyx_PyObject_GetAttrStr(__pyx_cur_scope->__pyx_v_res, __pyx_n_s_status); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 72, __pyx_L31_error) + __Pyx_GOTREF(__pyx_t_6); + __pyx_t_26 = (__Pyx_PyUnicode_Equals(__pyx_t_6, __pyx_n_u_creator, Py_EQ)); if (unlikely((__pyx_t_26 < 0))) __PYX_ERR(0, 72, __pyx_L31_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __pyx_t_8 = __pyx_t_26; + __pyx_L52_bool_binop_done:; + if (__pyx_t_8) { + goto __pyx_L51; + } + + /* "cython_code/user_check.pyx":75 + * pass + * else: + * force = True # <<<<<<<<<<<<<< + * except Exception as err: + * logging.error(err) + */ + /*else*/ { + __pyx_cur_scope->__pyx_v_force = 1; + } + __pyx_L51:; + + /* "cython_code/user_check.pyx":61 + * result = db.select_channels() + * for x in result: + * try: # <<<<<<<<<<<<<< + * # Construct the chat ID for the channel + * ids = str(-100) + str(x[1]) + */ + } + __Pyx_XDECREF(__pyx_t_11); __pyx_t_11 = 0; + __Pyx_XDECREF(__pyx_t_10); __pyx_t_10 = 0; + __Pyx_XDECREF(__pyx_t_9); __pyx_t_9 = 0; + goto __pyx_L38_try_end; + __pyx_L31_error:; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "cython_code/user_check.pyx":76 + * else: + * force = True + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + * return force + */ + __pyx_t_16 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); + if (__pyx_t_16) { + __Pyx_AddTraceback("cython_code.user_check.User_Check.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_6, &__pyx_t_5, &__pyx_t_14) < 0) __PYX_ERR(0, 76, __pyx_L33_except_error) + __Pyx_XGOTREF(__pyx_t_6); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_INCREF(__pyx_t_5); + __Pyx_GIVEREF(__pyx_t_5); + __pyx_cur_scope->__pyx_v_err = __pyx_t_5; + /*try:*/ { + + /* "cython_code/user_check.pyx":77 + * force = True + * except Exception as err: + * logging.error(err) # <<<<<<<<<<<<<< + * return force + * else: + */ + __Pyx_GetModuleGlobalName(__pyx_t_13, __pyx_n_s_logging); if (unlikely(!__pyx_t_13)) __PYX_ERR(0, 77, __pyx_L60_error) + __Pyx_GOTREF(__pyx_t_13); + __pyx_t_27 = __Pyx_PyObject_GetAttrStr(__pyx_t_13, __pyx_n_s_error); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 77, __pyx_L60_error) + __Pyx_GOTREF(__pyx_t_27); + __Pyx_DECREF(__pyx_t_13); __pyx_t_13 = 0; + __pyx_t_13 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_27))) { + __pyx_t_13 = PyMethod_GET_SELF(__pyx_t_27); + if (likely(__pyx_t_13)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_27); + __Pyx_INCREF(__pyx_t_13); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_27, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_13, __pyx_cur_scope->__pyx_v_err}; + __pyx_t_15 = __Pyx_PyObject_FastCall(__pyx_t_27, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 77, __pyx_L60_error) + __Pyx_GOTREF(__pyx_t_15); + __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0; + } + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + } + + /* "cython_code/user_check.pyx":76 + * else: + * force = True + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + * return force + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_err); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_err); __pyx_cur_scope->__pyx_v_err = 0; + goto __pyx_L61; + } + __pyx_L60_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_assign + __pyx_t_21 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_t_27); __pyx_t_27 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_20, &__pyx_t_19, &__pyx_t_18); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_21, &__pyx_t_22, &__pyx_t_23) < 0)) __Pyx_ErrFetch(&__pyx_t_21, &__pyx_t_22, &__pyx_t_23); + __Pyx_XGOTREF(__pyx_t_21); + __Pyx_XGOTREF(__pyx_t_22); + __Pyx_XGOTREF(__pyx_t_23); + __Pyx_XGOTREF(__pyx_t_20); + __Pyx_XGOTREF(__pyx_t_19); + __Pyx_XGOTREF(__pyx_t_18); + __pyx_t_16 = __pyx_lineno; __pyx_t_12 = __pyx_clineno; __pyx_t_28 = __pyx_filename; + { + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_err); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_err); __pyx_cur_scope->__pyx_v_err = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_20); + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_ExceptionReset(__pyx_t_20, __pyx_t_19, __pyx_t_18); + } + __Pyx_XGIVEREF(__pyx_t_21); + __Pyx_XGIVEREF(__pyx_t_22); + __Pyx_XGIVEREF(__pyx_t_23); + __Pyx_ErrRestore(__pyx_t_21, __pyx_t_22, __pyx_t_23); + __pyx_t_21 = 0; __pyx_t_22 = 0; __pyx_t_23 = 0; __pyx_t_20 = 0; __pyx_t_19 = 0; __pyx_t_18 = 0; + __pyx_lineno = __pyx_t_16; __pyx_clineno = __pyx_t_12; __pyx_filename = __pyx_t_28; + goto __pyx_L33_except_error; + } + __pyx_L61:; + } + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + goto __pyx_L32_exception_handled; + } + goto __pyx_L33_except_error; + + /* "cython_code/user_check.pyx":61 + * result = db.select_channels() + * for x in result: + * try: # <<<<<<<<<<<<<< + * # Construct the chat ID for the channel + * ids = str(-100) + str(x[1]) + */ + __pyx_L33_except_error:; + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_10, __pyx_t_9); + goto __pyx_L4_error; + __pyx_L37_try_continue:; + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_10, __pyx_t_9); + goto __pyx_L29_continue; + __pyx_L32_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_ExceptionReset(__pyx_t_11, __pyx_t_10, __pyx_t_9); + __pyx_L38_try_end:; + } + + /* "cython_code/user_check.pyx":60 + * force = False + * result = db.select_channels() + * for x in result: # <<<<<<<<<<<<<< + * try: + * # Construct the chat ID for the channel + */ + __pyx_L29_continue:; + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "cython_code/user_check.pyx":78 + * except Exception as err: + * logging.error(err) + * return force # <<<<<<<<<<<<<< + * else: + * return False + */ + __Pyx_XDECREF(__pyx_r); + __pyx_t_4 = __Pyx_PyBool_FromLong(__pyx_cur_scope->__pyx_v_force); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 78, __pyx_L4_error) + __Pyx_GOTREF(__pyx_t_4); + __pyx_r = NULL; __Pyx_ReturnWithStopIteration(__pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + goto __pyx_L8_try_return; + + /* "cython_code/user_check.pyx":57 + * + * # If the user is not the admin, perform the channel check + * if cid != self.ADMIN: # <<<<<<<<<<<<<< + * force = False + * result = db.select_channels() + */ + } + + /* "cython_code/user_check.pyx":80 + * return force + * else: + * return False # <<<<<<<<<<<<<< + * else: + * return False + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_r = NULL; __Pyx_ReturnWithStopIteration(Py_False); + goto __pyx_L8_try_return; + } + + /* "cython_code/user_check.pyx":47 + * # Retrieve the channel membership check requirement from the database + * data = DB.reading_db() + * if data['join_channel']: # <<<<<<<<<<<<<< + * try: + * # Try to get the user ID from the message object + */ + } + + /* "cython_code/user_check.pyx":82 + * return False + * else: + * return False # <<<<<<<<<<<<<< + * except Exception as err: + * logging.error(err) + */ + /*else*/ { + __Pyx_XDECREF(__pyx_r); + __pyx_r = NULL; __Pyx_ReturnWithStopIteration(Py_False); + goto __pyx_L8_try_return; + } + + /* "cython_code/user_check.pyx":44 + * - Logs errors if any exceptions occur during the check. + * """ + * try: # <<<<<<<<<<<<<< + * # Retrieve the channel membership check requirement from the database + * data = DB.reading_db() + */ + } + __pyx_L4_error:; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_t_27); __pyx_t_27 = 0; + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "cython_code/user_check.pyx":83 + * else: + * return False + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + * + */ + __pyx_t_12 = __Pyx_PyErr_ExceptionMatches(((PyObject *)(&((PyTypeObject*)PyExc_Exception)[0]))); + if (__pyx_t_12) { + __Pyx_AddTraceback("cython_code.user_check.User_Check.__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + if (__Pyx_GetException(&__pyx_t_4, &__pyx_t_14, &__pyx_t_5) < 0) __PYX_ERR(0, 83, __pyx_L6_except_error) + __Pyx_XGOTREF(__pyx_t_4); + __Pyx_XGOTREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_t_5); + __Pyx_INCREF(__pyx_t_14); + __Pyx_XGOTREF(__pyx_cur_scope->__pyx_v_err); + __Pyx_XDECREF_SET(__pyx_cur_scope->__pyx_v_err, __pyx_t_14); + __Pyx_GIVEREF(__pyx_t_14); + /*try:*/ { + + /* "cython_code/user_check.pyx":84 + * return False + * except Exception as err: + * logging.error(err) # <<<<<<<<<<<<<< + * + * return False + */ + __Pyx_GetModuleGlobalName(__pyx_t_15, __pyx_n_s_logging); if (unlikely(!__pyx_t_15)) __PYX_ERR(0, 84, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_15); + __pyx_t_27 = __Pyx_PyObject_GetAttrStr(__pyx_t_15, __pyx_n_s_error); if (unlikely(!__pyx_t_27)) __PYX_ERR(0, 84, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_27); + __Pyx_DECREF(__pyx_t_15); __pyx_t_15 = 0; + __pyx_t_15 = NULL; + __pyx_t_7 = 0; + #if CYTHON_UNPACK_METHODS + if (unlikely(PyMethod_Check(__pyx_t_27))) { + __pyx_t_15 = PyMethod_GET_SELF(__pyx_t_27); + if (likely(__pyx_t_15)) { + PyObject* function = PyMethod_GET_FUNCTION(__pyx_t_27); + __Pyx_INCREF(__pyx_t_15); + __Pyx_INCREF(function); + __Pyx_DECREF_SET(__pyx_t_27, function); + __pyx_t_7 = 1; + } + } + #endif + { + PyObject *__pyx_callargs[2] = {__pyx_t_15, __pyx_cur_scope->__pyx_v_err}; + __pyx_t_6 = __Pyx_PyObject_FastCall(__pyx_t_27, __pyx_callargs+1-__pyx_t_7, 1+__pyx_t_7); + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 84, __pyx_L72_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_DECREF(__pyx_t_27); __pyx_t_27 = 0; + } + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + } + + /* "cython_code/user_check.pyx":83 + * else: + * return False + * except Exception as err: # <<<<<<<<<<<<<< + * logging.error(err) + * + */ + /*finally:*/ { + /*normal exit:*/{ + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_err); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_err); __pyx_cur_scope->__pyx_v_err = 0; + goto __pyx_L73; + } + __pyx_L72_error:; + /*exception exit:*/{ + __Pyx_PyThreadState_assign + __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; + __Pyx_XDECREF(__pyx_t_13); __pyx_t_13 = 0; + __Pyx_XDECREF(__pyx_t_15); __pyx_t_15 = 0; + __Pyx_XDECREF(__pyx_t_27); __pyx_t_27 = 0; + __Pyx_XDECREF(__pyx_t_6); __pyx_t_6 = 0; + if (PY_MAJOR_VERSION >= 3) __Pyx_ExceptionSwap(&__pyx_t_18, &__pyx_t_19, &__pyx_t_20); + if ((PY_MAJOR_VERSION < 3) || unlikely(__Pyx_GetException(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11) < 0)) __Pyx_ErrFetch(&__pyx_t_9, &__pyx_t_10, &__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_9); + __Pyx_XGOTREF(__pyx_t_10); + __Pyx_XGOTREF(__pyx_t_11); + __Pyx_XGOTREF(__pyx_t_18); + __Pyx_XGOTREF(__pyx_t_19); + __Pyx_XGOTREF(__pyx_t_20); + __pyx_t_12 = __pyx_lineno; __pyx_t_16 = __pyx_clineno; __pyx_t_29 = __pyx_filename; + { + __Pyx_GOTREF(__pyx_cur_scope->__pyx_v_err); + __Pyx_DECREF(__pyx_cur_scope->__pyx_v_err); __pyx_cur_scope->__pyx_v_err = 0; + } + if (PY_MAJOR_VERSION >= 3) { + __Pyx_XGIVEREF(__pyx_t_18); + __Pyx_XGIVEREF(__pyx_t_19); + __Pyx_XGIVEREF(__pyx_t_20); + __Pyx_ExceptionReset(__pyx_t_18, __pyx_t_19, __pyx_t_20); + } + __Pyx_XGIVEREF(__pyx_t_9); + __Pyx_XGIVEREF(__pyx_t_10); + __Pyx_XGIVEREF(__pyx_t_11); + __Pyx_ErrRestore(__pyx_t_9, __pyx_t_10, __pyx_t_11); + __pyx_t_9 = 0; __pyx_t_10 = 0; __pyx_t_11 = 0; __pyx_t_18 = 0; __pyx_t_19 = 0; __pyx_t_20 = 0; + __pyx_lineno = __pyx_t_12; __pyx_clineno = __pyx_t_16; __pyx_filename = __pyx_t_29; + goto __pyx_L6_except_error; + } + __pyx_L73:; + } + __Pyx_XDECREF(__pyx_t_4); __pyx_t_4 = 0; + __Pyx_XDECREF(__pyx_t_14); __pyx_t_14 = 0; + __Pyx_XDECREF(__pyx_t_5); __pyx_t_5 = 0; + goto __pyx_L5_exception_handled; + } + goto __pyx_L6_except_error; + + /* "cython_code/user_check.pyx":44 + * - Logs errors if any exceptions occur during the check. + * """ + * try: # <<<<<<<<<<<<<< + * # Retrieve the channel membership check requirement from the database + * data = DB.reading_db() + */ + __pyx_L6_except_error:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L1_error; + __pyx_L8_try_return:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + goto __pyx_L0; + __pyx_L5_exception_handled:; + __Pyx_XGIVEREF(__pyx_t_1); + __Pyx_XGIVEREF(__pyx_t_2); + __Pyx_XGIVEREF(__pyx_t_3); + __Pyx_ExceptionReset(__pyx_t_1, __pyx_t_2, __pyx_t_3); + } + + /* "cython_code/user_check.pyx":86 + * logging.error(err) + * + * return False # <<<<<<<<<<<<<< + */ + __Pyx_XDECREF(__pyx_r); + __pyx_r = NULL; __Pyx_ReturnWithStopIteration(Py_False); + goto __pyx_L0; + CYTHON_MAYBE_UNUSED_VAR(__pyx_cur_scope); + + /* "cython_code/user_check.pyx":28 + * self.ADMIN = ADMIN + * + * async def __call__(self, message: Message, call: CallbackQuery = None) -> bool: # <<<<<<<<<<<<<< + * """ + * Checks if the user is a member of required channels. + */ + + /* function exit code */ + __pyx_L1_error:; + __Pyx_Generator_Replace_StopIteration(0); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + __Pyx_XDECREF(__pyx_t_13); + __Pyx_XDECREF(__pyx_t_14); + __Pyx_XDECREF(__pyx_t_15); + __Pyx_XDECREF(__pyx_t_27); + __Pyx_AddTraceback("__call__", __pyx_clineno, __pyx_lineno, __pyx_filename); + __pyx_L0:; + __Pyx_XDECREF(__pyx_r); __pyx_r = 0; + #if !CYTHON_USE_EXC_INFO_STACK + __Pyx_Coroutine_ResetAndClearException(__pyx_generator); + #endif + __pyx_generator->resume_label = -1; + __Pyx_Coroutine_clear((PyObject*)__pyx_generator); + __Pyx_RefNannyFinishContext(); + return __pyx_r; +} + +#if CYTHON_USE_FREELISTS +static struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__ *__pyx_freelist_11cython_code_10user_check___pyx_scope_struct____call__[8]; +static int __pyx_freecount_11cython_code_10user_check___pyx_scope_struct____call__ = 0; +#endif + +static PyObject *__pyx_tp_new_11cython_code_10user_check___pyx_scope_struct____call__(PyTypeObject *t, CYTHON_UNUSED PyObject *a, CYTHON_UNUSED PyObject *k) { + PyObject *o; + #if CYTHON_COMPILING_IN_LIMITED_API + allocfunc alloc_func = (allocfunc)PyType_GetSlot(t, Py_tp_alloc); + o = alloc_func(t, 0); + #else + #if CYTHON_USE_FREELISTS + if (likely((int)(__pyx_freecount_11cython_code_10user_check___pyx_scope_struct____call__ > 0) & (int)(t->tp_basicsize == sizeof(struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__)))) { + o = (PyObject*)__pyx_freelist_11cython_code_10user_check___pyx_scope_struct____call__[--__pyx_freecount_11cython_code_10user_check___pyx_scope_struct____call__]; + memset(o, 0, sizeof(struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__)); + (void) PyObject_INIT(o, t); + PyObject_GC_Track(o); + } else + #endif + { + o = (*t->tp_alloc)(t, 0); + if (unlikely(!o)) return 0; + } + #endif + return o; +} + +static void __pyx_tp_dealloc_11cython_code_10user_check___pyx_scope_struct____call__(PyObject *o) { + struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__ *p = (struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__ *)o; + #if CYTHON_USE_TP_FINALIZE + if (unlikely((PY_VERSION_HEX >= 0x03080000 || __Pyx_PyType_HasFeature(Py_TYPE(o), Py_TPFLAGS_HAVE_FINALIZE)) && __Pyx_PyObject_GetSlot(o, tp_finalize, destructor)) && !__Pyx_PyObject_GC_IsFinalized(o)) { + if (__Pyx_PyObject_GetSlot(o, tp_dealloc, destructor) == __pyx_tp_dealloc_11cython_code_10user_check___pyx_scope_struct____call__) { + if (PyObject_CallFinalizerFromDealloc(o)) return; + } + } + #endif + PyObject_GC_UnTrack(o); + Py_CLEAR(p->__pyx_v_call); + Py_CLEAR(p->__pyx_v_cid); + Py_CLEAR(p->__pyx_v_data); + Py_CLEAR(p->__pyx_v_err); + Py_CLEAR(p->__pyx_v_ids); + Py_CLEAR(p->__pyx_v_message); + Py_CLEAR(p->__pyx_v_res); + Py_CLEAR(p->__pyx_v_result); + Py_CLEAR(p->__pyx_v_self); + Py_CLEAR(p->__pyx_v_x); + Py_CLEAR(p->__pyx_t_0); + Py_CLEAR(p->__pyx_t_1); + Py_CLEAR(p->__pyx_t_2); + Py_CLEAR(p->__pyx_t_3); + Py_CLEAR(p->__pyx_t_4); + Py_CLEAR(p->__pyx_t_5); + Py_CLEAR(p->__pyx_t_6); + Py_CLEAR(p->__pyx_t_9); + Py_CLEAR(p->__pyx_t_10); + Py_CLEAR(p->__pyx_t_11); + #if CYTHON_USE_FREELISTS + if (((int)(__pyx_freecount_11cython_code_10user_check___pyx_scope_struct____call__ < 8) & (int)(Py_TYPE(o)->tp_basicsize == sizeof(struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__)))) { + __pyx_freelist_11cython_code_10user_check___pyx_scope_struct____call__[__pyx_freecount_11cython_code_10user_check___pyx_scope_struct____call__++] = ((struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__ *)o); + } else + #endif + { + #if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY + (*Py_TYPE(o)->tp_free)(o); + #else + { + freefunc tp_free = (freefunc)PyType_GetSlot(Py_TYPE(o), Py_tp_free); + if (tp_free) tp_free(o); + } + #endif + } +} + +static int __pyx_tp_traverse_11cython_code_10user_check___pyx_scope_struct____call__(PyObject *o, visitproc v, void *a) { + int e; + struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__ *p = (struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__ *)o; + if (p->__pyx_v_call) { + e = (*v)(p->__pyx_v_call, a); if (e) return e; + } + if (p->__pyx_v_cid) { + e = (*v)(p->__pyx_v_cid, a); if (e) return e; + } + if (p->__pyx_v_data) { + e = (*v)(p->__pyx_v_data, a); if (e) return e; + } + if (p->__pyx_v_err) { + e = (*v)(p->__pyx_v_err, a); if (e) return e; + } + if (p->__pyx_v_ids) { + e = (*v)(p->__pyx_v_ids, a); if (e) return e; + } + if (p->__pyx_v_message) { + e = (*v)(p->__pyx_v_message, a); if (e) return e; + } + if (p->__pyx_v_res) { + e = (*v)(p->__pyx_v_res, a); if (e) return e; + } + if (p->__pyx_v_result) { + e = (*v)(p->__pyx_v_result, a); if (e) return e; + } + if (p->__pyx_v_self) { + e = (*v)(p->__pyx_v_self, a); if (e) return e; + } + if (p->__pyx_v_x) { + e = (*v)(p->__pyx_v_x, a); if (e) return e; + } + if (p->__pyx_t_0) { + e = (*v)(p->__pyx_t_0, a); if (e) return e; + } + if (p->__pyx_t_1) { + e = (*v)(p->__pyx_t_1, a); if (e) return e; + } + if (p->__pyx_t_2) { + e = (*v)(p->__pyx_t_2, a); if (e) return e; + } + if (p->__pyx_t_3) { + e = (*v)(p->__pyx_t_3, a); if (e) return e; + } + if (p->__pyx_t_4) { + e = (*v)(p->__pyx_t_4, a); if (e) return e; + } + if (p->__pyx_t_5) { + e = (*v)(p->__pyx_t_5, a); if (e) return e; + } + if (p->__pyx_t_6) { + e = (*v)(p->__pyx_t_6, a); if (e) return e; + } + if (p->__pyx_t_9) { + e = (*v)(p->__pyx_t_9, a); if (e) return e; + } + if (p->__pyx_t_10) { + e = (*v)(p->__pyx_t_10, a); if (e) return e; + } + if (p->__pyx_t_11) { + e = (*v)(p->__pyx_t_11, a); if (e) return e; + } + return 0; +} +#if CYTHON_USE_TYPE_SPECS +static PyType_Slot __pyx_type_11cython_code_10user_check___pyx_scope_struct____call___slots[] = { + {Py_tp_dealloc, (void *)__pyx_tp_dealloc_11cython_code_10user_check___pyx_scope_struct____call__}, + {Py_tp_traverse, (void *)__pyx_tp_traverse_11cython_code_10user_check___pyx_scope_struct____call__}, + {Py_tp_new, (void *)__pyx_tp_new_11cython_code_10user_check___pyx_scope_struct____call__}, + {0, 0}, +}; +static PyType_Spec __pyx_type_11cython_code_10user_check___pyx_scope_struct____call___spec = { + "cython_code.user_check.__pyx_scope_struct____call__", + sizeof(struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__), + 0, + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_FINALIZE, + __pyx_type_11cython_code_10user_check___pyx_scope_struct____call___slots, +}; +#else + +static PyTypeObject __pyx_type_11cython_code_10user_check___pyx_scope_struct____call__ = { + PyVarObject_HEAD_INIT(0, 0) + "cython_code.user_check.""__pyx_scope_struct____call__", /*tp_name*/ + sizeof(struct __pyx_obj_11cython_code_10user_check___pyx_scope_struct____call__), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + __pyx_tp_dealloc_11cython_code_10user_check___pyx_scope_struct____call__, /*tp_dealloc*/ + #if PY_VERSION_HEX < 0x030800b4 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030800b4 + 0, /*tp_vectorcall_offset*/ + #endif + 0, /*tp_getattr*/ + 0, /*tp_setattr*/ + #if PY_MAJOR_VERSION < 3 + 0, /*tp_compare*/ + #endif + #if PY_MAJOR_VERSION >= 3 + 0, /*tp_as_async*/ + #endif + 0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + 0, /*tp_hash*/ + 0, /*tp_call*/ + 0, /*tp_str*/ + 0, /*tp_getattro*/ + 0, /*tp_setattro*/ + 0, /*tp_as_buffer*/ + Py_TPFLAGS_DEFAULT|Py_TPFLAGS_HAVE_VERSION_TAG|Py_TPFLAGS_CHECKTYPES|Py_TPFLAGS_HAVE_NEWBUFFER|Py_TPFLAGS_HAVE_GC|Py_TPFLAGS_HAVE_FINALIZE, /*tp_flags*/ + 0, /*tp_doc*/ + __pyx_tp_traverse_11cython_code_10user_check___pyx_scope_struct____call__, /*tp_traverse*/ + 0, /*tp_clear*/ + 0, /*tp_richcompare*/ + 0, /*tp_weaklistoffset*/ + 0, /*tp_iter*/ + 0, /*tp_iternext*/ + 0, /*tp_methods*/ + 0, /*tp_members*/ + 0, /*tp_getset*/ + 0, /*tp_base*/ + 0, /*tp_dict*/ + 0, /*tp_descr_get*/ + 0, /*tp_descr_set*/ + #if !CYTHON_USE_TYPE_SPECS + 0, /*tp_dictoffset*/ + #endif + 0, /*tp_init*/ + 0, /*tp_alloc*/ + __pyx_tp_new_11cython_code_10user_check___pyx_scope_struct____call__, /*tp_new*/ + 0, /*tp_free*/ + 0, /*tp_is_gc*/ + 0, /*tp_bases*/ + 0, /*tp_mro*/ + 0, /*tp_cache*/ + 0, /*tp_subclasses*/ + 0, /*tp_weaklist*/ + 0, /*tp_del*/ + 0, /*tp_version_tag*/ + #if PY_VERSION_HEX >= 0x030400a1 + #if CYTHON_USE_TP_FINALIZE + 0, /*tp_finalize*/ + #else + NULL, /*tp_finalize*/ + #endif + #endif + #if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) + 0, /*tp_vectorcall*/ + #endif + #if __PYX_NEED_TP_PRINT_SLOT == 1 + 0, /*tp_print*/ + #endif + #if PY_VERSION_HEX >= 0x030C0000 + 0, /*tp_watched*/ + #endif + #if PY_VERSION_HEX >= 0x030d00A4 + 0, /*tp_versions_used*/ + #endif + #if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 + 0, /*tp_pypy_flags*/ + #endif +}; +#endif + +static PyMethodDef __pyx_methods[] = { + {0, 0, 0, 0} +}; +#ifndef CYTHON_SMALL_CODE +#if defined(__clang__) + #define CYTHON_SMALL_CODE +#elif defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3)) + #define CYTHON_SMALL_CODE __attribute__((cold)) +#else + #define CYTHON_SMALL_CODE +#endif +#endif +/* #### Code section: pystring_table ### */ + +static int __Pyx_CreateStringTabAndInitStrings(void) { + __Pyx_StringTabEntry __pyx_string_tab[] = { + {&__pyx_n_s_ADMIN, __pyx_k_ADMIN, sizeof(__pyx_k_ADMIN), 0, 0, 1, 1}, + {&__pyx_n_s_BaseFilter, __pyx_k_BaseFilter, sizeof(__pyx_k_BaseFilter), 0, 0, 1, 1}, + {&__pyx_n_s_BaseMiddleware, __pyx_k_BaseMiddleware, sizeof(__pyx_k_BaseMiddleware), 0, 0, 1, 1}, + {&__pyx_n_s_CallbackQuery, __pyx_k_CallbackQuery, sizeof(__pyx_k_CallbackQuery), 0, 0, 1, 1}, + {&__pyx_n_s_DB, __pyx_k_DB, sizeof(__pyx_k_DB), 0, 0, 1, 1}, + {&__pyx_n_s_Message, __pyx_k_Message, sizeof(__pyx_k_Message), 0, 0, 1, 1}, + {&__pyx_kp_s_Middleware_and_filter_class_to, __pyx_k_Middleware_and_filter_class_to, sizeof(__pyx_k_Middleware_and_filter_class_to), 0, 0, 1, 0}, + {&__pyx_n_s_User_Check, __pyx_k_User_Check, sizeof(__pyx_k_User_Check), 0, 0, 1, 1}, + {&__pyx_n_s_User_Check___call, __pyx_k_User_Check___call, sizeof(__pyx_k_User_Check___call), 0, 0, 1, 1}, + {&__pyx_n_s_User_Check___init, __pyx_k_User_Check___init, sizeof(__pyx_k_User_Check___init), 0, 0, 1, 1}, + {&__pyx_n_s__2, __pyx_k__2, sizeof(__pyx_k__2), 0, 0, 1, 1}, + {&__pyx_kp_u__3, __pyx_k__3, sizeof(__pyx_k__3), 0, 1, 0, 0}, + {&__pyx_n_s__8, __pyx_k__8, sizeof(__pyx_k__8), 0, 0, 1, 1}, + {&__pyx_n_u_administrator, __pyx_k_administrator, sizeof(__pyx_k_administrator), 0, 1, 0, 1}, + {&__pyx_n_s_aiogram, __pyx_k_aiogram, sizeof(__pyx_k_aiogram), 0, 0, 1, 1}, + {&__pyx_n_s_aiogram_filters, __pyx_k_aiogram_filters, sizeof(__pyx_k_aiogram_filters), 0, 0, 1, 1}, + {&__pyx_n_s_aiogram_types, __pyx_k_aiogram_types, sizeof(__pyx_k_aiogram_types), 0, 0, 1, 1}, + {&__pyx_n_s_args, __pyx_k_args, sizeof(__pyx_k_args), 0, 0, 1, 1}, + {&__pyx_n_s_asyncio_coroutines, __pyx_k_asyncio_coroutines, sizeof(__pyx_k_asyncio_coroutines), 0, 0, 1, 1}, + {&__pyx_n_s_await, __pyx_k_await, sizeof(__pyx_k_await), 0, 0, 1, 1}, + {&__pyx_n_s_bool, __pyx_k_bool, sizeof(__pyx_k_bool), 0, 0, 1, 1}, + {&__pyx_n_s_bot, __pyx_k_bot, sizeof(__pyx_k_bot), 0, 0, 1, 1}, + {&__pyx_n_s_call, __pyx_k_call, sizeof(__pyx_k_call), 0, 0, 1, 1}, + {&__pyx_n_s_call_2, __pyx_k_call_2, sizeof(__pyx_k_call_2), 0, 0, 1, 1}, + {&__pyx_n_s_chat_id, __pyx_k_chat_id, sizeof(__pyx_k_chat_id), 0, 0, 1, 1}, + {&__pyx_n_s_cid, __pyx_k_cid, sizeof(__pyx_k_cid), 0, 0, 1, 1}, + {&__pyx_n_s_cline_in_traceback, __pyx_k_cline_in_traceback, sizeof(__pyx_k_cline_in_traceback), 0, 0, 1, 1}, + {&__pyx_n_s_close, __pyx_k_close, sizeof(__pyx_k_close), 0, 0, 1, 1}, + {&__pyx_n_u_creator, __pyx_k_creator, sizeof(__pyx_k_creator), 0, 1, 0, 1}, + {&__pyx_n_s_cython_code_user_check, __pyx_k_cython_code_user_check, sizeof(__pyx_k_cython_code_user_check), 0, 0, 1, 1}, + {&__pyx_kp_s_cython_code_user_check_pyx, __pyx_k_cython_code_user_check_pyx, sizeof(__pyx_k_cython_code_user_check_pyx), 0, 0, 1, 0}, + {&__pyx_n_s_data, __pyx_k_data, sizeof(__pyx_k_data), 0, 0, 1, 1}, + {&__pyx_n_s_data_config, __pyx_k_data_config, sizeof(__pyx_k_data_config), 0, 0, 1, 1}, + {&__pyx_n_s_db, __pyx_k_db, sizeof(__pyx_k_db), 0, 0, 1, 1}, + {&__pyx_n_s_dict, __pyx_k_dict, sizeof(__pyx_k_dict), 0, 0, 1, 1}, + {&__pyx_kp_u_disable, __pyx_k_disable, sizeof(__pyx_k_disable), 0, 1, 0, 0}, + {&__pyx_n_s_doc, __pyx_k_doc, sizeof(__pyx_k_doc), 0, 0, 1, 1}, + {&__pyx_kp_u_enable, __pyx_k_enable, sizeof(__pyx_k_enable), 0, 1, 0, 0}, + {&__pyx_n_s_err, __pyx_k_err, sizeof(__pyx_k_err), 0, 0, 1, 1}, + {&__pyx_n_s_error, __pyx_k_error, sizeof(__pyx_k_error), 0, 0, 1, 1}, + {&__pyx_n_s_force, __pyx_k_force, sizeof(__pyx_k_force), 0, 0, 1, 1}, + {&__pyx_n_s_from_user, __pyx_k_from_user, sizeof(__pyx_k_from_user), 0, 0, 1, 1}, + {&__pyx_kp_u_gc, __pyx_k_gc, sizeof(__pyx_k_gc), 0, 1, 0, 0}, + {&__pyx_n_s_get_chat, __pyx_k_get_chat, sizeof(__pyx_k_get_chat), 0, 0, 1, 1}, + {&__pyx_n_s_get_chat_member, __pyx_k_get_chat_member, sizeof(__pyx_k_get_chat_member), 0, 0, 1, 1}, + {&__pyx_n_s_id, __pyx_k_id, sizeof(__pyx_k_id), 0, 0, 1, 1}, + {&__pyx_n_s_ids, __pyx_k_ids, sizeof(__pyx_k_ids), 0, 0, 1, 1}, + {&__pyx_n_s_import, __pyx_k_import, sizeof(__pyx_k_import), 0, 0, 1, 1}, + {&__pyx_n_s_init, __pyx_k_init, sizeof(__pyx_k_init), 0, 0, 1, 1}, + {&__pyx_n_s_init_subclass, __pyx_k_init_subclass, sizeof(__pyx_k_init_subclass), 0, 0, 1, 1}, + {&__pyx_n_s_initializing, __pyx_k_initializing, sizeof(__pyx_k_initializing), 0, 0, 1, 1}, + {&__pyx_n_s_is_coroutine, __pyx_k_is_coroutine, sizeof(__pyx_k_is_coroutine), 0, 0, 1, 1}, + {&__pyx_kp_u_isenabled, __pyx_k_isenabled, sizeof(__pyx_k_isenabled), 0, 1, 0, 0}, + {&__pyx_n_u_join_channel, __pyx_k_join_channel, sizeof(__pyx_k_join_channel), 0, 1, 0, 1}, + {&__pyx_n_s_loader, __pyx_k_loader, sizeof(__pyx_k_loader), 0, 0, 1, 1}, + {&__pyx_n_s_logging, __pyx_k_logging, sizeof(__pyx_k_logging), 0, 0, 1, 1}, + {&__pyx_n_s_main, __pyx_k_main, sizeof(__pyx_k_main), 0, 0, 1, 1}, + {&__pyx_n_u_member, __pyx_k_member, sizeof(__pyx_k_member), 0, 1, 0, 1}, + {&__pyx_n_s_message, __pyx_k_message, sizeof(__pyx_k_message), 0, 0, 1, 1}, + {&__pyx_n_s_metaclass, __pyx_k_metaclass, sizeof(__pyx_k_metaclass), 0, 0, 1, 1}, + {&__pyx_n_s_module, __pyx_k_module, sizeof(__pyx_k_module), 0, 0, 1, 1}, + {&__pyx_n_s_mro_entries, __pyx_k_mro_entries, sizeof(__pyx_k_mro_entries), 0, 0, 1, 1}, + {&__pyx_n_s_name, __pyx_k_name, sizeof(__pyx_k_name), 0, 0, 1, 1}, + {&__pyx_n_s_prepare, __pyx_k_prepare, sizeof(__pyx_k_prepare), 0, 0, 1, 1}, + {&__pyx_n_s_qualname, __pyx_k_qualname, sizeof(__pyx_k_qualname), 0, 0, 1, 1}, + {&__pyx_n_s_reading_db, __pyx_k_reading_db, sizeof(__pyx_k_reading_db), 0, 0, 1, 1}, + {&__pyx_n_s_res, __pyx_k_res, sizeof(__pyx_k_res), 0, 0, 1, 1}, + {&__pyx_n_s_result, __pyx_k_result, sizeof(__pyx_k_result), 0, 0, 1, 1}, + {&__pyx_n_s_return, __pyx_k_return, sizeof(__pyx_k_return), 0, 0, 1, 1}, + {&__pyx_n_s_select_channels, __pyx_k_select_channels, sizeof(__pyx_k_select_channels), 0, 0, 1, 1}, + {&__pyx_n_s_self, __pyx_k_self, sizeof(__pyx_k_self), 0, 0, 1, 1}, + {&__pyx_n_s_send, __pyx_k_send, sizeof(__pyx_k_send), 0, 0, 1, 1}, + {&__pyx_n_s_set_name, __pyx_k_set_name, sizeof(__pyx_k_set_name), 0, 0, 1, 1}, + {&__pyx_n_s_spec, __pyx_k_spec, sizeof(__pyx_k_spec), 0, 0, 1, 1}, + {&__pyx_n_s_status, __pyx_k_status, sizeof(__pyx_k_status), 0, 0, 1, 1}, + {&__pyx_n_s_super, __pyx_k_super, sizeof(__pyx_k_super), 0, 0, 1, 1}, + {&__pyx_n_s_test, __pyx_k_test, sizeof(__pyx_k_test), 0, 0, 1, 1}, + {&__pyx_n_s_throw, __pyx_k_throw, sizeof(__pyx_k_throw), 0, 0, 1, 1}, + {&__pyx_n_s_user_id, __pyx_k_user_id, sizeof(__pyx_k_user_id), 0, 0, 1, 1}, + {&__pyx_n_s_x, __pyx_k_x, sizeof(__pyx_k_x), 0, 0, 1, 1}, + {0, 0, 0, 0, 0, 0, 0} + }; + return __Pyx_InitStrings(__pyx_string_tab); +} +/* #### Code section: cached_builtins ### */ +static CYTHON_SMALL_CODE int __Pyx_InitCachedBuiltins(void) { + return 0; +} +/* #### Code section: cached_constants ### */ + +static CYTHON_SMALL_CODE int __Pyx_InitCachedConstants(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_InitCachedConstants", 0); + + /* "cython_code/user_check.pyx":17 + * """ + * + * def __init__(self): # <<<<<<<<<<<<<< + * """ + * Initializes the User_Check class. + */ + __pyx_tuple__4 = PyTuple_Pack(1, __pyx_n_s_self); if (unlikely(!__pyx_tuple__4)) __PYX_ERR(0, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__4); + __Pyx_GIVEREF(__pyx_tuple__4); + __pyx_codeobj__5 = (PyObject*)__Pyx_PyCode_New(1, 0, 0, 1, 0, CO_OPTIMIZED|CO_NEWLOCALS, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__4, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cython_code_user_check_pyx, __pyx_n_s_init, 17, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj__5)) __PYX_ERR(0, 17, __pyx_L1_error) + + /* "cython_code/user_check.pyx":28 + * self.ADMIN = ADMIN + * + * async def __call__(self, message: Message, call: CallbackQuery = None) -> bool: # <<<<<<<<<<<<<< + * """ + * Checks if the user is a member of required channels. + */ + __pyx_tuple__6 = PyTuple_Pack(11, __pyx_n_s_self, __pyx_n_s_message, __pyx_n_s_call, __pyx_n_s_data, __pyx_n_s_cid, __pyx_n_s_err, __pyx_n_s_force, __pyx_n_s_result, __pyx_n_s_x, __pyx_n_s_ids, __pyx_n_s_res); if (unlikely(!__pyx_tuple__6)) __PYX_ERR(0, 28, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__6); + __Pyx_GIVEREF(__pyx_tuple__6); + __pyx_codeobj_ = (PyObject*)__Pyx_PyCode_New(3, 0, 0, 11, 0, CO_OPTIMIZED|CO_NEWLOCALS|CO_COROUTINE, __pyx_empty_bytes, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_tuple__6, __pyx_empty_tuple, __pyx_empty_tuple, __pyx_kp_s_cython_code_user_check_pyx, __pyx_n_s_call_2, 28, __pyx_empty_bytes); if (unlikely(!__pyx_codeobj_)) __PYX_ERR(0, 28, __pyx_L1_error) + __pyx_tuple__7 = PyTuple_Pack(1, Py_None); if (unlikely(!__pyx_tuple__7)) __PYX_ERR(0, 28, __pyx_L1_error) + __Pyx_GOTREF(__pyx_tuple__7); + __Pyx_GIVEREF(__pyx_tuple__7); + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} +/* #### Code section: init_constants ### */ + +static CYTHON_SMALL_CODE int __Pyx_InitConstants(void) { + if (__Pyx_CreateStringTabAndInitStrings() < 0) __PYX_ERR(0, 1, __pyx_L1_error); + __pyx_int_neg_100 = PyInt_FromLong(-100); if (unlikely(!__pyx_int_neg_100)) __PYX_ERR(0, 1, __pyx_L1_error) + return 0; + __pyx_L1_error:; + return -1; +} +/* #### Code section: init_globals ### */ + +static CYTHON_SMALL_CODE int __Pyx_InitGlobals(void) { + return 0; +} +/* #### Code section: init_module ### */ + +static CYTHON_SMALL_CODE int __Pyx_modinit_global_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_export_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_init_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_type_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_variable_import_code(void); /*proto*/ +static CYTHON_SMALL_CODE int __Pyx_modinit_function_import_code(void); /*proto*/ + +static int __Pyx_modinit_global_init_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_global_init_code", 0); + /*--- Global init code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_export_code", 0); + /*--- Variable export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_export_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_export_code", 0); + /*--- Function export code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_type_init_code(void) { + __Pyx_RefNannyDeclarations + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannySetupContext("__Pyx_modinit_type_init_code", 0); + /*--- Type init code ---*/ + #if CYTHON_USE_TYPE_SPECS + __pyx_ptype_11cython_code_10user_check___pyx_scope_struct____call__ = (PyTypeObject *) __Pyx_PyType_FromModuleAndSpec(__pyx_m, &__pyx_type_11cython_code_10user_check___pyx_scope_struct____call___spec, NULL); if (unlikely(!__pyx_ptype_11cython_code_10user_check___pyx_scope_struct____call__)) __PYX_ERR(0, 28, __pyx_L1_error) + if (__Pyx_fix_up_extension_type_from_spec(&__pyx_type_11cython_code_10user_check___pyx_scope_struct____call___spec, __pyx_ptype_11cython_code_10user_check___pyx_scope_struct____call__) < 0) __PYX_ERR(0, 28, __pyx_L1_error) + #else + __pyx_ptype_11cython_code_10user_check___pyx_scope_struct____call__ = &__pyx_type_11cython_code_10user_check___pyx_scope_struct____call__; + #endif + #if !CYTHON_COMPILING_IN_LIMITED_API + #endif + #if !CYTHON_USE_TYPE_SPECS + if (__Pyx_PyType_Ready(__pyx_ptype_11cython_code_10user_check___pyx_scope_struct____call__) < 0) __PYX_ERR(0, 28, __pyx_L1_error) + #endif + #if PY_MAJOR_VERSION < 3 + __pyx_ptype_11cython_code_10user_check___pyx_scope_struct____call__->tp_print = 0; + #endif + #if !CYTHON_COMPILING_IN_LIMITED_API + if ((CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP) && likely(!__pyx_ptype_11cython_code_10user_check___pyx_scope_struct____call__->tp_dictoffset && __pyx_ptype_11cython_code_10user_check___pyx_scope_struct____call__->tp_getattro == PyObject_GenericGetAttr)) { + __pyx_ptype_11cython_code_10user_check___pyx_scope_struct____call__->tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; + } + #endif + __Pyx_RefNannyFinishContext(); + return 0; + __pyx_L1_error:; + __Pyx_RefNannyFinishContext(); + return -1; +} + +static int __Pyx_modinit_type_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_type_import_code", 0); + /*--- Type import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_variable_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_variable_import_code", 0); + /*--- Variable import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + +static int __Pyx_modinit_function_import_code(void) { + __Pyx_RefNannyDeclarations + __Pyx_RefNannySetupContext("__Pyx_modinit_function_import_code", 0); + /*--- Function import code ---*/ + __Pyx_RefNannyFinishContext(); + return 0; +} + + +#if PY_MAJOR_VERSION >= 3 +#if CYTHON_PEP489_MULTI_PHASE_INIT +static PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def); /*proto*/ +static int __pyx_pymod_exec_user_check(PyObject* module); /*proto*/ +static PyModuleDef_Slot __pyx_moduledef_slots[] = { + {Py_mod_create, (void*)__pyx_pymod_create}, + {Py_mod_exec, (void*)__pyx_pymod_exec_user_check}, + {0, NULL} +}; +#endif + +#ifdef __cplusplus +namespace { + struct PyModuleDef __pyx_moduledef = + #else + static struct PyModuleDef __pyx_moduledef = + #endif + { + PyModuleDef_HEAD_INIT, + "user_check", + 0, /* m_doc */ + #if CYTHON_PEP489_MULTI_PHASE_INIT + 0, /* m_size */ + #elif CYTHON_USE_MODULE_STATE + sizeof(__pyx_mstate), /* m_size */ + #else + -1, /* m_size */ + #endif + __pyx_methods /* m_methods */, + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_moduledef_slots, /* m_slots */ + #else + NULL, /* m_reload */ + #endif + #if CYTHON_USE_MODULE_STATE + __pyx_m_traverse, /* m_traverse */ + __pyx_m_clear, /* m_clear */ + NULL /* m_free */ + #else + NULL, /* m_traverse */ + NULL, /* m_clear */ + NULL /* m_free */ + #endif + }; + #ifdef __cplusplus +} /* anonymous namespace */ +#endif +#endif + +#ifndef CYTHON_NO_PYINIT_EXPORT +#define __Pyx_PyMODINIT_FUNC PyMODINIT_FUNC +#elif PY_MAJOR_VERSION < 3 +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" void +#else +#define __Pyx_PyMODINIT_FUNC void +#endif +#else +#ifdef __cplusplus +#define __Pyx_PyMODINIT_FUNC extern "C" PyObject * +#else +#define __Pyx_PyMODINIT_FUNC PyObject * +#endif +#endif + + +#if PY_MAJOR_VERSION < 3 +__Pyx_PyMODINIT_FUNC inituser_check(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC inituser_check(void) +#else +__Pyx_PyMODINIT_FUNC PyInit_user_check(void) CYTHON_SMALL_CODE; /*proto*/ +__Pyx_PyMODINIT_FUNC PyInit_user_check(void) +#if CYTHON_PEP489_MULTI_PHASE_INIT +{ + return PyModuleDef_Init(&__pyx_moduledef); +} +static CYTHON_SMALL_CODE int __Pyx_check_single_interpreter(void) { + #if PY_VERSION_HEX >= 0x030700A1 + static PY_INT64_T main_interpreter_id = -1; + PY_INT64_T current_id = PyInterpreterState_GetID(PyThreadState_Get()->interp); + if (main_interpreter_id == -1) { + main_interpreter_id = current_id; + return (unlikely(current_id == -1)) ? -1 : 0; + } else if (unlikely(main_interpreter_id != current_id)) + #else + static PyInterpreterState *main_interpreter = NULL; + PyInterpreterState *current_interpreter = PyThreadState_Get()->interp; + if (!main_interpreter) { + main_interpreter = current_interpreter; + } else if (unlikely(main_interpreter != current_interpreter)) + #endif + { + PyErr_SetString( + PyExc_ImportError, + "Interpreter change detected - this module can only be loaded into one interpreter per process."); + return -1; + } + return 0; +} +#if CYTHON_COMPILING_IN_LIMITED_API +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *module, const char* from_name, const char* to_name, int allow_none) +#else +static CYTHON_SMALL_CODE int __Pyx_copy_spec_to_module(PyObject *spec, PyObject *moddict, const char* from_name, const char* to_name, int allow_none) +#endif +{ + PyObject *value = PyObject_GetAttrString(spec, from_name); + int result = 0; + if (likely(value)) { + if (allow_none || value != Py_None) { +#if CYTHON_COMPILING_IN_LIMITED_API + result = PyModule_AddObject(module, to_name, value); +#else + result = PyDict_SetItemString(moddict, to_name, value); +#endif + } + Py_DECREF(value); + } else if (PyErr_ExceptionMatches(PyExc_AttributeError)) { + PyErr_Clear(); + } else { + result = -1; + } + return result; +} +static CYTHON_SMALL_CODE PyObject* __pyx_pymod_create(PyObject *spec, PyModuleDef *def) { + PyObject *module = NULL, *moddict, *modname; + CYTHON_UNUSED_VAR(def); + if (__Pyx_check_single_interpreter()) + return NULL; + if (__pyx_m) + return __Pyx_NewRef(__pyx_m); + modname = PyObject_GetAttrString(spec, "name"); + if (unlikely(!modname)) goto bad; + module = PyModule_NewObject(modname); + Py_DECREF(modname); + if (unlikely(!module)) goto bad; +#if CYTHON_COMPILING_IN_LIMITED_API + moddict = module; +#else + moddict = PyModule_GetDict(module); + if (unlikely(!moddict)) goto bad; +#endif + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "loader", "__loader__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "origin", "__file__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "parent", "__package__", 1) < 0)) goto bad; + if (unlikely(__Pyx_copy_spec_to_module(spec, moddict, "submodule_search_locations", "__path__", 0) < 0)) goto bad; + return module; +bad: + Py_XDECREF(module); + return NULL; +} + + +static CYTHON_SMALL_CODE int __pyx_pymod_exec_user_check(PyObject *__pyx_pyinit_module) +#endif +#endif +{ + int stringtab_initialized = 0; + #if CYTHON_USE_MODULE_STATE + int pystate_addmodule_run = 0; + #endif + PyObject *__pyx_t_1 = NULL; + PyObject *__pyx_t_2 = NULL; + PyObject *__pyx_t_3 = NULL; + PyObject *__pyx_t_4 = NULL; + PyObject *__pyx_t_5 = NULL; + PyObject *__pyx_t_6 = NULL; + int __pyx_lineno = 0; + const char *__pyx_filename = NULL; + int __pyx_clineno = 0; + __Pyx_RefNannyDeclarations + #if CYTHON_PEP489_MULTI_PHASE_INIT + if (__pyx_m) { + if (__pyx_m == __pyx_pyinit_module) return 0; + PyErr_SetString(PyExc_RuntimeError, "Module 'user_check' has already been imported. Re-initialisation is not supported."); + return -1; + } + #elif PY_MAJOR_VERSION >= 3 + if (__pyx_m) return __Pyx_NewRef(__pyx_m); + #endif + /*--- Module creation code ---*/ + #if CYTHON_PEP489_MULTI_PHASE_INIT + __pyx_m = __pyx_pyinit_module; + Py_INCREF(__pyx_m); + #else + #if PY_MAJOR_VERSION < 3 + __pyx_m = Py_InitModule4("user_check", __pyx_methods, 0, 0, PYTHON_API_VERSION); Py_XINCREF(__pyx_m); + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #elif CYTHON_USE_MODULE_STATE + __pyx_t_1 = PyModule_Create(&__pyx_moduledef); if (unlikely(!__pyx_t_1)) __PYX_ERR(0, 1, __pyx_L1_error) + { + int add_module_result = PyState_AddModule(__pyx_t_1, &__pyx_moduledef); + __pyx_t_1 = 0; /* transfer ownership from __pyx_t_1 to "user_check" pseudovariable */ + if (unlikely((add_module_result < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + pystate_addmodule_run = 1; + } + #else + __pyx_m = PyModule_Create(&__pyx_moduledef); + if (unlikely(!__pyx_m)) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #endif + CYTHON_UNUSED_VAR(__pyx_t_1); + __pyx_d = PyModule_GetDict(__pyx_m); if (unlikely(!__pyx_d)) __PYX_ERR(0, 1, __pyx_L1_error) + Py_INCREF(__pyx_d); + __pyx_b = __Pyx_PyImport_AddModuleRef(__Pyx_BUILTIN_MODULE_NAME); if (unlikely(!__pyx_b)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_cython_runtime = __Pyx_PyImport_AddModuleRef((const char *) "cython_runtime"); if (unlikely(!__pyx_cython_runtime)) __PYX_ERR(0, 1, __pyx_L1_error) + if (PyObject_SetAttrString(__pyx_m, "__builtins__", __pyx_b) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if CYTHON_REFNANNY +__Pyx_RefNanny = __Pyx_RefNannyImportAPI("refnanny"); +if (!__Pyx_RefNanny) { + PyErr_Clear(); + __Pyx_RefNanny = __Pyx_RefNannyImportAPI("Cython.Runtime.refnanny"); + if (!__Pyx_RefNanny) + Py_FatalError("failed to import 'refnanny' module"); +} +#endif + __Pyx_RefNannySetupContext("__Pyx_PyMODINIT_FUNC PyInit_user_check(void)", 0); + if (__Pyx_check_binary_version(__PYX_LIMITED_VERSION_HEX, __Pyx_get_runtime_version(), CYTHON_COMPILING_IN_LIMITED_API) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pxy_PyFrame_Initialize_Offsets + __Pxy_PyFrame_Initialize_Offsets(); + #endif + __pyx_empty_tuple = PyTuple_New(0); if (unlikely(!__pyx_empty_tuple)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_bytes = PyBytes_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_bytes)) __PYX_ERR(0, 1, __pyx_L1_error) + __pyx_empty_unicode = PyUnicode_FromStringAndSize("", 0); if (unlikely(!__pyx_empty_unicode)) __PYX_ERR(0, 1, __pyx_L1_error) + #ifdef __Pyx_CyFunction_USED + if (__pyx_CyFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_FusedFunction_USED + if (__pyx_FusedFunction_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Coroutine_USED + if (__pyx_Coroutine_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_Generator_USED + if (__pyx_Generator_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_AsyncGen_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + #ifdef __Pyx_StopAsyncIteration_USED + if (__pyx_StopAsyncIteration_init(__pyx_m) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + /*--- Library function declarations ---*/ + /*--- Threads initialization code ---*/ + #if defined(WITH_THREAD) && PY_VERSION_HEX < 0x030700F0 && defined(__PYX_FORCE_INIT_THREADS) && __PYX_FORCE_INIT_THREADS + PyEval_InitThreads(); + #endif + /*--- Initialize various global constants etc. ---*/ + if (__Pyx_InitConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + stringtab_initialized = 1; + if (__Pyx_InitGlobals() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #if PY_MAJOR_VERSION < 3 && (__PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT) + if (__Pyx_init_sys_getdefaultencoding_params() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + if (__pyx_module_is_main_cython_code__user_check) { + if (PyObject_SetAttr(__pyx_m, __pyx_n_s_name, __pyx_n_s_main) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + } + #if PY_MAJOR_VERSION >= 3 + { + PyObject *modules = PyImport_GetModuleDict(); if (unlikely(!modules)) __PYX_ERR(0, 1, __pyx_L1_error) + if (!PyDict_GetItemString(modules, "cython_code.user_check")) { + if (unlikely((PyDict_SetItemString(modules, "cython_code.user_check", __pyx_m) < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + } + } + #endif + /*--- Builtin init code ---*/ + if (__Pyx_InitCachedBuiltins() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Constants init code ---*/ + if (__Pyx_InitCachedConstants() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + /*--- Global type/function init code ---*/ + (void)__Pyx_modinit_global_init_code(); + (void)__Pyx_modinit_variable_export_code(); + (void)__Pyx_modinit_function_export_code(); + if (unlikely((__Pyx_modinit_type_init_code() < 0))) __PYX_ERR(0, 1, __pyx_L1_error) + (void)__Pyx_modinit_type_import_code(); + (void)__Pyx_modinit_variable_import_code(); + (void)__Pyx_modinit_function_import_code(); + /*--- Execution code ---*/ + #if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + if (__Pyx_patch_abc() < 0) __PYX_ERR(0, 1, __pyx_L1_error) + #endif + + /* "cython_code/user_check.pyx":2 + * # user_check.pyx + * import logging # <<<<<<<<<<<<<< + * from loader import bot, db, DB + * from data.config import ADMIN + */ + __pyx_t_2 = __Pyx_ImportDottedModule(__pyx_n_s_logging, NULL); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 2, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_logging, __pyx_t_2) < 0) __PYX_ERR(0, 2, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/user_check.pyx":3 + * # user_check.pyx + * import logging + * from loader import bot, db, DB # <<<<<<<<<<<<<< + * from data.config import ADMIN + * from aiogram.filters import BaseFilter + */ + __pyx_t_2 = PyList_New(3); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_bot); + __Pyx_GIVEREF(__pyx_n_s_bot); + if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_bot)) __PYX_ERR(0, 3, __pyx_L1_error); + __Pyx_INCREF(__pyx_n_s_db); + __Pyx_GIVEREF(__pyx_n_s_db); + if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 1, __pyx_n_s_db)) __PYX_ERR(0, 3, __pyx_L1_error); + __Pyx_INCREF(__pyx_n_s_DB); + __Pyx_GIVEREF(__pyx_n_s_DB); + if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 2, __pyx_n_s_DB)) __PYX_ERR(0, 3, __pyx_L1_error); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_loader, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_bot); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_bot, __pyx_t_2) < 0) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_db); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_db, __pyx_t_2) < 0) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_DB); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_DB, __pyx_t_2) < 0) __PYX_ERR(0, 3, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "cython_code/user_check.pyx":4 + * import logging + * from loader import bot, db, DB + * from data.config import ADMIN # <<<<<<<<<<<<<< + * from aiogram.filters import BaseFilter + * from aiogram.types import Message, CallbackQuery + */ + __pyx_t_3 = PyList_New(1); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_n_s_ADMIN); + __Pyx_GIVEREF(__pyx_n_s_ADMIN); + if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_ADMIN)) __PYX_ERR(0, 4, __pyx_L1_error); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_data_config, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_ADMIN); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_ADMIN, __pyx_t_3) < 0) __PYX_ERR(0, 4, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/user_check.pyx":5 + * from loader import bot, db, DB + * from data.config import ADMIN + * from aiogram.filters import BaseFilter # <<<<<<<<<<<<<< + * from aiogram.types import Message, CallbackQuery + * from aiogram import BaseMiddleware + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_BaseFilter); + __Pyx_GIVEREF(__pyx_n_s_BaseFilter); + if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_BaseFilter)) __PYX_ERR(0, 5, __pyx_L1_error); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_aiogram_filters, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_BaseFilter); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_BaseFilter, __pyx_t_2) < 0) __PYX_ERR(0, 5, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "cython_code/user_check.pyx":6 + * from data.config import ADMIN + * from aiogram.filters import BaseFilter + * from aiogram.types import Message, CallbackQuery # <<<<<<<<<<<<<< + * from aiogram import BaseMiddleware + * + */ + __pyx_t_3 = PyList_New(2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_INCREF(__pyx_n_s_Message); + __Pyx_GIVEREF(__pyx_n_s_Message); + if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 0, __pyx_n_s_Message)) __PYX_ERR(0, 6, __pyx_L1_error); + __Pyx_INCREF(__pyx_n_s_CallbackQuery); + __Pyx_GIVEREF(__pyx_n_s_CallbackQuery); + if (__Pyx_PyList_SET_ITEM(__pyx_t_3, 1, __pyx_n_s_CallbackQuery)) __PYX_ERR(0, 6, __pyx_L1_error); + __pyx_t_2 = __Pyx_Import(__pyx_n_s_aiogram_types, __pyx_t_3, 0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_Message); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_Message, __pyx_t_3) < 0) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __pyx_t_3 = __Pyx_ImportFrom(__pyx_t_2, __pyx_n_s_CallbackQuery); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_CallbackQuery, __pyx_t_3) < 0) __PYX_ERR(0, 6, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/user_check.pyx":7 + * from aiogram.filters import BaseFilter + * from aiogram.types import Message, CallbackQuery + * from aiogram import BaseMiddleware # <<<<<<<<<<<<<< + * + * class User_Check(BaseFilter, BaseMiddleware): + */ + __pyx_t_2 = PyList_New(1); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __Pyx_INCREF(__pyx_n_s_BaseMiddleware); + __Pyx_GIVEREF(__pyx_n_s_BaseMiddleware); + if (__Pyx_PyList_SET_ITEM(__pyx_t_2, 0, __pyx_n_s_BaseMiddleware)) __PYX_ERR(0, 7, __pyx_L1_error); + __pyx_t_3 = __Pyx_Import(__pyx_n_s_aiogram, __pyx_t_2, 0); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_ImportFrom(__pyx_t_3, __pyx_n_s_BaseMiddleware); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_BaseMiddleware, __pyx_t_2) < 0) __PYX_ERR(0, 7, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + + /* "cython_code/user_check.pyx":9 + * from aiogram import BaseMiddleware + * + * class User_Check(BaseFilter, BaseMiddleware): # <<<<<<<<<<<<<< + * """ + * Middleware and filter class to check if a user is a member of required channels. + */ + __Pyx_GetModuleGlobalName(__pyx_t_3, __pyx_n_s_BaseFilter); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __Pyx_GetModuleGlobalName(__pyx_t_2, __pyx_n_s_BaseMiddleware); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_4 = PyTuple_New(2); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + __Pyx_GIVEREF(__pyx_t_3); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 0, __pyx_t_3)) __PYX_ERR(0, 9, __pyx_L1_error); + __Pyx_GIVEREF(__pyx_t_2); + if (__Pyx_PyTuple_SET_ITEM(__pyx_t_4, 1, __pyx_t_2)) __PYX_ERR(0, 9, __pyx_L1_error); + __pyx_t_3 = 0; + __pyx_t_2 = 0; + __pyx_t_2 = __Pyx_PEP560_update_bases(__pyx_t_4); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + __pyx_t_3 = __Pyx_CalculateMetaclass(NULL, __pyx_t_2); if (unlikely(!__pyx_t_3)) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_3); + __pyx_t_5 = __Pyx_Py3MetaclassPrepare(__pyx_t_3, __pyx_t_2, __pyx_n_s_User_Check, __pyx_n_s_User_Check, (PyObject *) NULL, __pyx_n_s_cython_code_user_check, __pyx_kp_s_Middleware_and_filter_class_to); if (unlikely(!__pyx_t_5)) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_5); + if (__pyx_t_2 != __pyx_t_4) { + if (unlikely((PyDict_SetItemString(__pyx_t_5, "__orig_bases__", __pyx_t_4) < 0))) __PYX_ERR(0, 9, __pyx_L1_error) + } + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "cython_code/user_check.pyx":17 + * """ + * + * def __init__(self): # <<<<<<<<<<<<<< + * """ + * Initializes the User_Check class. + */ + __pyx_t_4 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_10user_check_10User_Check_1__init__, 0, __pyx_n_s_User_Check___init, NULL, __pyx_n_s_cython_code_user_check, __pyx_d, ((PyObject *)__pyx_codeobj__5)); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 17, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (__Pyx_SetNameInClass(__pyx_t_5, __pyx_n_s_init, __pyx_t_4) < 0) __PYX_ERR(0, 17, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + + /* "cython_code/user_check.pyx":28 + * self.ADMIN = ADMIN + * + * async def __call__(self, message: Message, call: CallbackQuery = None) -> bool: # <<<<<<<<<<<<<< + * """ + * Checks if the user is a member of required channels. + */ + __pyx_t_4 = __Pyx_PyDict_NewPresized(3); if (unlikely(!__pyx_t_4)) __PYX_ERR(0, 28, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_4); + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_message, __pyx_n_s_Message) < 0) __PYX_ERR(0, 28, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_call, __pyx_n_s_CallbackQuery) < 0) __PYX_ERR(0, 28, __pyx_L1_error) + if (PyDict_SetItem(__pyx_t_4, __pyx_n_s_return, __pyx_n_s_bool) < 0) __PYX_ERR(0, 28, __pyx_L1_error) + __pyx_t_6 = __Pyx_CyFunction_New(&__pyx_mdef_11cython_code_10user_check_10User_Check_3__call__, __Pyx_CYFUNCTION_COROUTINE, __pyx_n_s_User_Check___call, NULL, __pyx_n_s_cython_code_user_check, __pyx_d, ((PyObject *)__pyx_codeobj_)); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 28, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + __Pyx_CyFunction_SetDefaultsTuple(__pyx_t_6, __pyx_tuple__7); + __Pyx_CyFunction_SetAnnotationsDict(__pyx_t_6, __pyx_t_4); + __Pyx_DECREF(__pyx_t_4); __pyx_t_4 = 0; + if (__Pyx_SetNameInClass(__pyx_t_5, __pyx_n_s_call_2, __pyx_t_6) < 0) __PYX_ERR(0, 28, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + + /* "cython_code/user_check.pyx":9 + * from aiogram import BaseMiddleware + * + * class User_Check(BaseFilter, BaseMiddleware): # <<<<<<<<<<<<<< + * """ + * Middleware and filter class to check if a user is a member of required channels. + */ + __pyx_t_6 = __Pyx_Py3ClassCreate(__pyx_t_3, __pyx_n_s_User_Check, __pyx_t_2, __pyx_t_5, NULL, 0, 0); if (unlikely(!__pyx_t_6)) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_6); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_User_Check, __pyx_t_6) < 0) __PYX_ERR(0, 9, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_6); __pyx_t_6 = 0; + __Pyx_DECREF(__pyx_t_5); __pyx_t_5 = 0; + __Pyx_DECREF(__pyx_t_3); __pyx_t_3 = 0; + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /* "cython_code/user_check.pyx":1 + * # user_check.pyx # <<<<<<<<<<<<<< + * import logging + * from loader import bot, db, DB + */ + __pyx_t_2 = __Pyx_PyDict_NewPresized(0); if (unlikely(!__pyx_t_2)) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_GOTREF(__pyx_t_2); + if (PyDict_SetItem(__pyx_d, __pyx_n_s_test, __pyx_t_2) < 0) __PYX_ERR(0, 1, __pyx_L1_error) + __Pyx_DECREF(__pyx_t_2); __pyx_t_2 = 0; + + /*--- Wrapped vars code ---*/ + + goto __pyx_L0; + __pyx_L1_error:; + __Pyx_XDECREF(__pyx_t_2); + __Pyx_XDECREF(__pyx_t_3); + __Pyx_XDECREF(__pyx_t_4); + __Pyx_XDECREF(__pyx_t_5); + __Pyx_XDECREF(__pyx_t_6); + if (__pyx_m) { + if (__pyx_d && stringtab_initialized) { + __Pyx_AddTraceback("init cython_code.user_check", __pyx_clineno, __pyx_lineno, __pyx_filename); + } + #if !CYTHON_USE_MODULE_STATE + Py_CLEAR(__pyx_m); + #else + Py_DECREF(__pyx_m); + if (pystate_addmodule_run) { + PyObject *tp, *value, *tb; + PyErr_Fetch(&tp, &value, &tb); + PyState_RemoveModule(&__pyx_moduledef); + PyErr_Restore(tp, value, tb); + } + #endif + } else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_ImportError, "init cython_code.user_check"); + } + __pyx_L0:; + __Pyx_RefNannyFinishContext(); + #if CYTHON_PEP489_MULTI_PHASE_INIT + return (__pyx_m != NULL) ? 0 : -1; + #elif PY_MAJOR_VERSION >= 3 + return __pyx_m; + #else + return; + #endif +} +/* #### Code section: cleanup_globals ### */ +/* #### Code section: cleanup_module ### */ +/* #### Code section: main_method ### */ +/* #### Code section: utility_code_pragmas ### */ +#ifdef _MSC_VER +#pragma warning( push ) +/* Warning 4127: conditional expression is constant + * Cython uses constant conditional expressions to allow in inline functions to be optimized at + * compile-time, so this warning is not useful + */ +#pragma warning( disable : 4127 ) +#endif + + + +/* #### Code section: utility_code_def ### */ + +/* --- Runtime support code --- */ +/* Refnanny */ +#if CYTHON_REFNANNY +static __Pyx_RefNannyAPIStruct *__Pyx_RefNannyImportAPI(const char *modname) { + PyObject *m = NULL, *p = NULL; + void *r = NULL; + m = PyImport_ImportModule(modname); + if (!m) goto end; + p = PyObject_GetAttrString(m, "RefNannyAPI"); + if (!p) goto end; + r = PyLong_AsVoidPtr(p); +end: + Py_XDECREF(p); + Py_XDECREF(m); + return (__Pyx_RefNannyAPIStruct *)r; +} +#endif + +/* TupleAndListFromArray */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE void __Pyx_copy_object_array(PyObject *const *CYTHON_RESTRICT src, PyObject** CYTHON_RESTRICT dest, Py_ssize_t length) { + PyObject *v; + Py_ssize_t i; + for (i = 0; i < length; i++) { + v = dest[i] = src[i]; + Py_INCREF(v); + } +} +static CYTHON_INLINE PyObject * +__Pyx_PyTuple_FromArray(PyObject *const *src, Py_ssize_t n) +{ + PyObject *res; + if (n <= 0) { + Py_INCREF(__pyx_empty_tuple); + return __pyx_empty_tuple; + } + res = PyTuple_New(n); + if (unlikely(res == NULL)) return NULL; + __Pyx_copy_object_array(src, ((PyTupleObject*)res)->ob_item, n); + return res; +} +static CYTHON_INLINE PyObject * +__Pyx_PyList_FromArray(PyObject *const *src, Py_ssize_t n) +{ + PyObject *res; + if (n <= 0) { + return PyList_New(0); + } + res = PyList_New(n); + if (unlikely(res == NULL)) return NULL; + __Pyx_copy_object_array(src, ((PyListObject*)res)->ob_item, n); + return res; +} +#endif + +/* BytesEquals */ +static CYTHON_INLINE int __Pyx_PyBytes_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API + return PyObject_RichCompareBool(s1, s2, equals); +#else + if (s1 == s2) { + return (equals == Py_EQ); + } else if (PyBytes_CheckExact(s1) & PyBytes_CheckExact(s2)) { + const char *ps1, *ps2; + Py_ssize_t length = PyBytes_GET_SIZE(s1); + if (length != PyBytes_GET_SIZE(s2)) + return (equals == Py_NE); + ps1 = PyBytes_AS_STRING(s1); + ps2 = PyBytes_AS_STRING(s2); + if (ps1[0] != ps2[0]) { + return (equals == Py_NE); + } else if (length == 1) { + return (equals == Py_EQ); + } else { + int result; +#if CYTHON_USE_UNICODE_INTERNALS && (PY_VERSION_HEX < 0x030B0000) + Py_hash_t hash1, hash2; + hash1 = ((PyBytesObject*)s1)->ob_shash; + hash2 = ((PyBytesObject*)s2)->ob_shash; + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + return (equals == Py_NE); + } +#endif + result = memcmp(ps1, ps2, (size_t)length); + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & PyBytes_CheckExact(s2)) { + return (equals == Py_NE); + } else if ((s2 == Py_None) & PyBytes_CheckExact(s1)) { + return (equals == Py_NE); + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +#endif +} + +/* UnicodeEquals */ +static CYTHON_INLINE int __Pyx_PyUnicode_Equals(PyObject* s1, PyObject* s2, int equals) { +#if CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API + return PyObject_RichCompareBool(s1, s2, equals); +#else +#if PY_MAJOR_VERSION < 3 + PyObject* owned_ref = NULL; +#endif + int s1_is_unicode, s2_is_unicode; + if (s1 == s2) { + goto return_eq; + } + s1_is_unicode = PyUnicode_CheckExact(s1); + s2_is_unicode = PyUnicode_CheckExact(s2); +#if PY_MAJOR_VERSION < 3 + if ((s1_is_unicode & (!s2_is_unicode)) && PyString_CheckExact(s2)) { + owned_ref = PyUnicode_FromObject(s2); + if (unlikely(!owned_ref)) + return -1; + s2 = owned_ref; + s2_is_unicode = 1; + } else if ((s2_is_unicode & (!s1_is_unicode)) && PyString_CheckExact(s1)) { + owned_ref = PyUnicode_FromObject(s1); + if (unlikely(!owned_ref)) + return -1; + s1 = owned_ref; + s1_is_unicode = 1; + } else if (((!s2_is_unicode) & (!s1_is_unicode))) { + return __Pyx_PyBytes_Equals(s1, s2, equals); + } +#endif + if (s1_is_unicode & s2_is_unicode) { + Py_ssize_t length; + int kind; + void *data1, *data2; + if (unlikely(__Pyx_PyUnicode_READY(s1) < 0) || unlikely(__Pyx_PyUnicode_READY(s2) < 0)) + return -1; + length = __Pyx_PyUnicode_GET_LENGTH(s1); + if (length != __Pyx_PyUnicode_GET_LENGTH(s2)) { + goto return_ne; + } +#if CYTHON_USE_UNICODE_INTERNALS + { + Py_hash_t hash1, hash2; + #if CYTHON_PEP393_ENABLED + hash1 = ((PyASCIIObject*)s1)->hash; + hash2 = ((PyASCIIObject*)s2)->hash; + #else + hash1 = ((PyUnicodeObject*)s1)->hash; + hash2 = ((PyUnicodeObject*)s2)->hash; + #endif + if (hash1 != hash2 && hash1 != -1 && hash2 != -1) { + goto return_ne; + } + } +#endif + kind = __Pyx_PyUnicode_KIND(s1); + if (kind != __Pyx_PyUnicode_KIND(s2)) { + goto return_ne; + } + data1 = __Pyx_PyUnicode_DATA(s1); + data2 = __Pyx_PyUnicode_DATA(s2); + if (__Pyx_PyUnicode_READ(kind, data1, 0) != __Pyx_PyUnicode_READ(kind, data2, 0)) { + goto return_ne; + } else if (length == 1) { + goto return_eq; + } else { + int result = memcmp(data1, data2, (size_t)(length * kind)); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ) ? (result == 0) : (result != 0); + } + } else if ((s1 == Py_None) & s2_is_unicode) { + goto return_ne; + } else if ((s2 == Py_None) & s1_is_unicode) { + goto return_ne; + } else { + int result; + PyObject* py_result = PyObject_RichCompare(s1, s2, equals); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + if (!py_result) + return -1; + result = __Pyx_PyObject_IsTrue(py_result); + Py_DECREF(py_result); + return result; + } +return_eq: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_EQ); +return_ne: + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(owned_ref); + #endif + return (equals == Py_NE); +#endif +} + +/* fastcall */ +#if CYTHON_METH_FASTCALL +static CYTHON_INLINE PyObject * __Pyx_GetKwValue_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues, PyObject *s) +{ + Py_ssize_t i, n = PyTuple_GET_SIZE(kwnames); + for (i = 0; i < n; i++) + { + if (s == PyTuple_GET_ITEM(kwnames, i)) return kwvalues[i]; + } + for (i = 0; i < n; i++) + { + int eq = __Pyx_PyUnicode_Equals(s, PyTuple_GET_ITEM(kwnames, i), Py_EQ); + if (unlikely(eq != 0)) { + if (unlikely(eq < 0)) return NULL; + return kwvalues[i]; + } + } + return NULL; +} +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030d0000 +CYTHON_UNUSED static PyObject *__Pyx_KwargsAsDict_FASTCALL(PyObject *kwnames, PyObject *const *kwvalues) { + Py_ssize_t i, nkwargs = PyTuple_GET_SIZE(kwnames); + PyObject *dict; + dict = PyDict_New(); + if (unlikely(!dict)) + return NULL; + for (i=0; i= 3 + "%s() got multiple values for keyword argument '%U'", func_name, kw_name); + #else + "%s() got multiple values for keyword argument '%s'", func_name, + PyString_AsString(kw_name)); + #endif +} + +/* ParseKeywords */ +static int __Pyx_ParseOptionalKeywords( + PyObject *kwds, + PyObject *const *kwvalues, + PyObject **argnames[], + PyObject *kwds2, + PyObject *values[], + Py_ssize_t num_pos_args, + const char* function_name) +{ + PyObject *key = 0, *value = 0; + Py_ssize_t pos = 0; + PyObject*** name; + PyObject*** first_kw_arg = argnames + num_pos_args; + int kwds_is_tuple = CYTHON_METH_FASTCALL && likely(PyTuple_Check(kwds)); + while (1) { + Py_XDECREF(key); key = NULL; + Py_XDECREF(value); value = NULL; + if (kwds_is_tuple) { + Py_ssize_t size; +#if CYTHON_ASSUME_SAFE_MACROS + size = PyTuple_GET_SIZE(kwds); +#else + size = PyTuple_Size(kwds); + if (size < 0) goto bad; +#endif + if (pos >= size) break; +#if CYTHON_AVOID_BORROWED_REFS + key = __Pyx_PySequence_ITEM(kwds, pos); + if (!key) goto bad; +#elif CYTHON_ASSUME_SAFE_MACROS + key = PyTuple_GET_ITEM(kwds, pos); +#else + key = PyTuple_GetItem(kwds, pos); + if (!key) goto bad; +#endif + value = kwvalues[pos]; + pos++; + } + else + { + if (!PyDict_Next(kwds, &pos, &key, &value)) break; +#if CYTHON_AVOID_BORROWED_REFS + Py_INCREF(key); +#endif + } + name = first_kw_arg; + while (*name && (**name != key)) name++; + if (*name) { + values[name-argnames] = value; +#if CYTHON_AVOID_BORROWED_REFS + Py_INCREF(value); + Py_DECREF(key); +#endif + key = NULL; + value = NULL; + continue; + } +#if !CYTHON_AVOID_BORROWED_REFS + Py_INCREF(key); +#endif + Py_INCREF(value); + name = first_kw_arg; + #if PY_MAJOR_VERSION < 3 + if (likely(PyString_Check(key))) { + while (*name) { + if ((CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**name) == PyString_GET_SIZE(key)) + && _PyString_Eq(**name, key)) { + values[name-argnames] = value; +#if CYTHON_AVOID_BORROWED_REFS + value = NULL; +#endif + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + if ((**argname == key) || ( + (CYTHON_COMPILING_IN_PYPY || PyString_GET_SIZE(**argname) == PyString_GET_SIZE(key)) + && _PyString_Eq(**argname, key))) { + goto arg_passed_twice; + } + argname++; + } + } + } else + #endif + if (likely(PyUnicode_Check(key))) { + while (*name) { + int cmp = ( + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (__Pyx_PyUnicode_GET_LENGTH(**name) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : + #endif + PyUnicode_Compare(**name, key) + ); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) { + values[name-argnames] = value; +#if CYTHON_AVOID_BORROWED_REFS + value = NULL; +#endif + break; + } + name++; + } + if (*name) continue; + else { + PyObject*** argname = argnames; + while (argname != first_kw_arg) { + int cmp = (**argname == key) ? 0 : + #if !CYTHON_COMPILING_IN_PYPY && PY_MAJOR_VERSION >= 3 + (__Pyx_PyUnicode_GET_LENGTH(**argname) != __Pyx_PyUnicode_GET_LENGTH(key)) ? 1 : + #endif + PyUnicode_Compare(**argname, key); + if (cmp < 0 && unlikely(PyErr_Occurred())) goto bad; + if (cmp == 0) goto arg_passed_twice; + argname++; + } + } + } else + goto invalid_keyword_type; + if (kwds2) { + if (unlikely(PyDict_SetItem(kwds2, key, value))) goto bad; + } else { + goto invalid_keyword; + } + } + Py_XDECREF(key); + Py_XDECREF(value); + return 0; +arg_passed_twice: + __Pyx_RaiseDoubleKeywordsError(function_name, key); + goto bad; +invalid_keyword_type: + PyErr_Format(PyExc_TypeError, + "%.200s() keywords must be strings", function_name); + goto bad; +invalid_keyword: + #if PY_MAJOR_VERSION < 3 + PyErr_Format(PyExc_TypeError, + "%.200s() got an unexpected keyword argument '%.200s'", + function_name, PyString_AsString(key)); + #else + PyErr_Format(PyExc_TypeError, + "%s() got an unexpected keyword argument '%U'", + function_name, key); + #endif +bad: + Py_XDECREF(key); + Py_XDECREF(value); + return -1; +} + +/* RaiseArgTupleInvalid */ +static void __Pyx_RaiseArgtupleInvalid( + const char* func_name, + int exact, + Py_ssize_t num_min, + Py_ssize_t num_max, + Py_ssize_t num_found) +{ + Py_ssize_t num_expected; + const char *more_or_less; + if (num_found < num_min) { + num_expected = num_min; + more_or_less = "at least"; + } else { + num_expected = num_max; + more_or_less = "at most"; + } + if (exact) { + more_or_less = "exactly"; + } + PyErr_Format(PyExc_TypeError, + "%.200s() takes %.8s %" CYTHON_FORMAT_SSIZE_T "d positional argument%.1s (%" CYTHON_FORMAT_SSIZE_T "d given)", + func_name, more_or_less, num_expected, + (num_expected == 1) ? "" : "s", num_found); +} + +/* PyErrExceptionMatches */ +#if CYTHON_FAST_THREAD_STATE +static int __Pyx_PyErr_ExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; i= 0x030C00A6 + PyObject *current_exception = tstate->current_exception; + if (unlikely(!current_exception)) return 0; + exc_type = (PyObject*) Py_TYPE(current_exception); + if (exc_type == err) return 1; +#else + exc_type = tstate->curexc_type; + if (exc_type == err) return 1; + if (unlikely(!exc_type)) return 0; +#endif + #if CYTHON_AVOID_BORROWED_REFS + Py_INCREF(exc_type); + #endif + if (unlikely(PyTuple_Check(err))) { + result = __Pyx_PyErr_ExceptionMatchesTuple(exc_type, err); + } else { + result = __Pyx_PyErr_GivenExceptionMatches(exc_type, err); + } + #if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(exc_type); + #endif + return result; +} +#endif + +/* PyErrFetchRestore */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx_ErrRestoreInState(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { +#if PY_VERSION_HEX >= 0x030C00A6 + PyObject *tmp_value; + assert(type == NULL || (value != NULL && type == (PyObject*) Py_TYPE(value))); + if (value) { + #if CYTHON_COMPILING_IN_CPYTHON + if (unlikely(((PyBaseExceptionObject*) value)->traceback != tb)) + #endif + PyException_SetTraceback(value, tb); + } + tmp_value = tstate->current_exception; + tstate->current_exception = value; + Py_XDECREF(tmp_value); + Py_XDECREF(type); + Py_XDECREF(tb); +#else + PyObject *tmp_type, *tmp_value, *tmp_tb; + tmp_type = tstate->curexc_type; + tmp_value = tstate->curexc_value; + tmp_tb = tstate->curexc_traceback; + tstate->curexc_type = type; + tstate->curexc_value = value; + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#endif +} +static CYTHON_INLINE void __Pyx_ErrFetchInState(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { +#if PY_VERSION_HEX >= 0x030C00A6 + PyObject* exc_value; + exc_value = tstate->current_exception; + tstate->current_exception = 0; + *value = exc_value; + *type = NULL; + *tb = NULL; + if (exc_value) { + *type = (PyObject*) Py_TYPE(exc_value); + Py_INCREF(*type); + #if CYTHON_COMPILING_IN_CPYTHON + *tb = ((PyBaseExceptionObject*) exc_value)->traceback; + Py_XINCREF(*tb); + #else + *tb = PyException_GetTraceback(exc_value); + #endif + } +#else + *type = tstate->curexc_type; + *value = tstate->curexc_value; + *tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; +#endif +} +#endif + +/* PyObjectGetAttrStr */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStr(PyObject* obj, PyObject* attr_name) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro)) + return tp->tp_getattro(obj, attr_name); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_getattr)) + return tp->tp_getattr(obj, PyString_AS_STRING(attr_name)); +#endif + return PyObject_GetAttr(obj, attr_name); +} +#endif + +/* PyObjectGetAttrStrNoError */ +#if __PYX_LIMITED_VERSION_HEX < 0x030d00A1 +static void __Pyx_PyObject_GetAttrStr_ClearAttributeError(void) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (likely(__Pyx_PyErr_ExceptionMatches(PyExc_AttributeError))) + __Pyx_PyErr_Clear(); +} +#endif +static CYTHON_INLINE PyObject* __Pyx_PyObject_GetAttrStrNoError(PyObject* obj, PyObject* attr_name) { + PyObject *result; +#if __PYX_LIMITED_VERSION_HEX >= 0x030d00A1 + (void) PyObject_GetOptionalAttr(obj, attr_name, &result); + return result; +#else +#if CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_TYPE_SLOTS && PY_VERSION_HEX >= 0x030700B1 + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_getattro == PyObject_GenericGetAttr)) { + return _PyObject_GenericGetAttrWithDict(obj, attr_name, NULL, 1); + } +#endif + result = __Pyx_PyObject_GetAttrStr(obj, attr_name); + if (unlikely(!result)) { + __Pyx_PyObject_GetAttrStr_ClearAttributeError(); + } + return result; +#endif +} + +/* GetBuiltinName */ +static PyObject *__Pyx_GetBuiltinName(PyObject *name) { + PyObject* result = __Pyx_PyObject_GetAttrStrNoError(__pyx_b, name); + if (unlikely(!result) && !PyErr_Occurred()) { + PyErr_Format(PyExc_NameError, +#if PY_MAJOR_VERSION >= 3 + "name '%U' is not defined", name); +#else + "name '%.200s' is not defined", PyString_AS_STRING(name)); +#endif + } + return result; +} + +/* PyDictVersioning */ +#if CYTHON_USE_DICT_VERSIONS && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PY_UINT64_T __Pyx_get_tp_dict_version(PyObject *obj) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + return likely(dict) ? __PYX_GET_DICT_VERSION(dict) : 0; +} +static CYTHON_INLINE PY_UINT64_T __Pyx_get_object_dict_version(PyObject *obj) { + PyObject **dictptr = NULL; + Py_ssize_t offset = Py_TYPE(obj)->tp_dictoffset; + if (offset) { +#if CYTHON_COMPILING_IN_CPYTHON + dictptr = (likely(offset > 0)) ? (PyObject **) ((char *)obj + offset) : _PyObject_GetDictPtr(obj); +#else + dictptr = _PyObject_GetDictPtr(obj); +#endif + } + return (dictptr && *dictptr) ? __PYX_GET_DICT_VERSION(*dictptr) : 0; +} +static CYTHON_INLINE int __Pyx_object_dict_version_matches(PyObject* obj, PY_UINT64_T tp_dict_version, PY_UINT64_T obj_dict_version) { + PyObject *dict = Py_TYPE(obj)->tp_dict; + if (unlikely(!dict) || unlikely(tp_dict_version != __PYX_GET_DICT_VERSION(dict))) + return 0; + return obj_dict_version == __Pyx_get_object_dict_version(obj); +} +#endif + +/* GetModuleGlobalName */ +#if CYTHON_USE_DICT_VERSIONS +static PyObject *__Pyx__GetModuleGlobalName(PyObject *name, PY_UINT64_T *dict_version, PyObject **dict_cached_value) +#else +static CYTHON_INLINE PyObject *__Pyx__GetModuleGlobalName(PyObject *name) +#endif +{ + PyObject *result; +#if !CYTHON_AVOID_BORROWED_REFS +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030500A1 && PY_VERSION_HEX < 0x030d0000 + result = _PyDict_GetItem_KnownHash(__pyx_d, name, ((PyASCIIObject *) name)->hash); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } else if (unlikely(PyErr_Occurred())) { + return NULL; + } +#elif CYTHON_COMPILING_IN_LIMITED_API + if (unlikely(!__pyx_m)) { + return NULL; + } + result = PyObject_GetAttr(__pyx_m, name); + if (likely(result)) { + return result; + } +#else + result = PyDict_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } +#endif +#else + result = PyObject_GetItem(__pyx_d, name); + __PYX_UPDATE_DICT_CACHE(__pyx_d, result, *dict_cached_value, *dict_version) + if (likely(result)) { + return __Pyx_NewRef(result); + } + PyErr_Clear(); +#endif + return __Pyx_GetBuiltinName(name); +} + +/* PyObjectSetAttrStr */ +#if CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE int __Pyx_PyObject_SetAttrStr(PyObject* obj, PyObject* attr_name, PyObject* value) { + PyTypeObject* tp = Py_TYPE(obj); + if (likely(tp->tp_setattro)) + return tp->tp_setattro(obj, attr_name, value); +#if PY_MAJOR_VERSION < 3 + if (likely(tp->tp_setattr)) + return tp->tp_setattr(obj, PyString_AS_STRING(attr_name), value); +#endif + return PyObject_SetAttr(obj, attr_name, value); +} +#endif + +/* PyFunctionFastCall */ +#if CYTHON_FAST_PYCALL && !CYTHON_VECTORCALL +static PyObject* __Pyx_PyFunction_FastCallNoKw(PyCodeObject *co, PyObject **args, Py_ssize_t na, + PyObject *globals) { + PyFrameObject *f; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject **fastlocals; + Py_ssize_t i; + PyObject *result; + assert(globals != NULL); + /* XXX Perhaps we should create a specialized + PyFrame_New() that doesn't take locals, but does + take builtins without sanity checking them. + */ + assert(tstate != NULL); + f = PyFrame_New(tstate, co, globals, NULL); + if (f == NULL) { + return NULL; + } + fastlocals = __Pyx_PyFrame_GetLocalsplus(f); + for (i = 0; i < na; i++) { + Py_INCREF(*args); + fastlocals[i] = *args++; + } + result = PyEval_EvalFrameEx(f,0); + ++tstate->recursion_depth; + Py_DECREF(f); + --tstate->recursion_depth; + return result; +} +static PyObject *__Pyx_PyFunction_FastCallDict(PyObject *func, PyObject **args, Py_ssize_t nargs, PyObject *kwargs) { + PyCodeObject *co = (PyCodeObject *)PyFunction_GET_CODE(func); + PyObject *globals = PyFunction_GET_GLOBALS(func); + PyObject *argdefs = PyFunction_GET_DEFAULTS(func); + PyObject *closure; +#if PY_MAJOR_VERSION >= 3 + PyObject *kwdefs; +#endif + PyObject *kwtuple, **k; + PyObject **d; + Py_ssize_t nd; + Py_ssize_t nk; + PyObject *result; + assert(kwargs == NULL || PyDict_Check(kwargs)); + nk = kwargs ? PyDict_Size(kwargs) : 0; + #if PY_MAJOR_VERSION < 3 + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) { + return NULL; + } + #else + if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) { + return NULL; + } + #endif + if ( +#if PY_MAJOR_VERSION >= 3 + co->co_kwonlyargcount == 0 && +#endif + likely(kwargs == NULL || nk == 0) && + co->co_flags == (CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE)) { + if (argdefs == NULL && co->co_argcount == nargs) { + result = __Pyx_PyFunction_FastCallNoKw(co, args, nargs, globals); + goto done; + } + else if (nargs == 0 && argdefs != NULL + && co->co_argcount == Py_SIZE(argdefs)) { + /* function called with no arguments, but all parameters have + a default value: use default values as arguments .*/ + args = &PyTuple_GET_ITEM(argdefs, 0); + result =__Pyx_PyFunction_FastCallNoKw(co, args, Py_SIZE(argdefs), globals); + goto done; + } + } + if (kwargs != NULL) { + Py_ssize_t pos, i; + kwtuple = PyTuple_New(2 * nk); + if (kwtuple == NULL) { + result = NULL; + goto done; + } + k = &PyTuple_GET_ITEM(kwtuple, 0); + pos = i = 0; + while (PyDict_Next(kwargs, &pos, &k[i], &k[i+1])) { + Py_INCREF(k[i]); + Py_INCREF(k[i+1]); + i += 2; + } + nk = i / 2; + } + else { + kwtuple = NULL; + k = NULL; + } + closure = PyFunction_GET_CLOSURE(func); +#if PY_MAJOR_VERSION >= 3 + kwdefs = PyFunction_GET_KW_DEFAULTS(func); +#endif + if (argdefs != NULL) { + d = &PyTuple_GET_ITEM(argdefs, 0); + nd = Py_SIZE(argdefs); + } + else { + d = NULL; + nd = 0; + } +#if PY_MAJOR_VERSION >= 3 + result = PyEval_EvalCodeEx((PyObject*)co, globals, (PyObject *)NULL, + args, (int)nargs, + k, (int)nk, + d, (int)nd, kwdefs, closure); +#else + result = PyEval_EvalCodeEx(co, globals, (PyObject *)NULL, + args, (int)nargs, + k, (int)nk, + d, (int)nd, closure); +#endif + Py_XDECREF(kwtuple); +done: + Py_LeaveRecursiveCall(); + return result; +} +#endif + +/* PyObjectCall */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *result; + ternaryfunc call = Py_TYPE(func)->tp_call; + if (unlikely(!call)) + return PyObject_Call(func, arg, kw); + #if PY_MAJOR_VERSION < 3 + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + #else + if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) + return NULL; + #endif + result = (*call)(func, arg, kw); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* PyObjectCallMethO */ +#if CYTHON_COMPILING_IN_CPYTHON +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallMethO(PyObject *func, PyObject *arg) { + PyObject *self, *result; + PyCFunction cfunc; + cfunc = __Pyx_CyOrPyCFunction_GET_FUNCTION(func); + self = __Pyx_CyOrPyCFunction_GET_SELF(func); + #if PY_MAJOR_VERSION < 3 + if (unlikely(Py_EnterRecursiveCall((char*)" while calling a Python object"))) + return NULL; + #else + if (unlikely(Py_EnterRecursiveCall(" while calling a Python object"))) + return NULL; + #endif + result = cfunc(self, arg); + Py_LeaveRecursiveCall(); + if (unlikely(!result) && unlikely(!PyErr_Occurred())) { + PyErr_SetString( + PyExc_SystemError, + "NULL result without error in PyObject_Call"); + } + return result; +} +#endif + +/* PyObjectFastCall */ +#if PY_VERSION_HEX < 0x03090000 || CYTHON_COMPILING_IN_LIMITED_API +static PyObject* __Pyx_PyObject_FastCall_fallback(PyObject *func, PyObject **args, size_t nargs, PyObject *kwargs) { + PyObject *argstuple; + PyObject *result = 0; + size_t i; + argstuple = PyTuple_New((Py_ssize_t)nargs); + if (unlikely(!argstuple)) return NULL; + for (i = 0; i < nargs; i++) { + Py_INCREF(args[i]); + if (__Pyx_PyTuple_SET_ITEM(argstuple, (Py_ssize_t)i, args[i]) < 0) goto bad; + } + result = __Pyx_PyObject_Call(func, argstuple, kwargs); + bad: + Py_DECREF(argstuple); + return result; +} +#endif +static CYTHON_INLINE PyObject* __Pyx_PyObject_FastCallDict(PyObject *func, PyObject **args, size_t _nargs, PyObject *kwargs) { + Py_ssize_t nargs = __Pyx_PyVectorcall_NARGS(_nargs); +#if CYTHON_COMPILING_IN_CPYTHON + if (nargs == 0 && kwargs == NULL) { + if (__Pyx_CyOrPyCFunction_Check(func) && likely( __Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_NOARGS)) + return __Pyx_PyObject_CallMethO(func, NULL); + } + else if (nargs == 1 && kwargs == NULL) { + if (__Pyx_CyOrPyCFunction_Check(func) && likely( __Pyx_CyOrPyCFunction_GET_FLAGS(func) & METH_O)) + return __Pyx_PyObject_CallMethO(func, args[0]); + } +#endif + #if PY_VERSION_HEX < 0x030800B1 + #if CYTHON_FAST_PYCCALL + if (PyCFunction_Check(func)) { + if (kwargs) { + return _PyCFunction_FastCallDict(func, args, nargs, kwargs); + } else { + return _PyCFunction_FastCallKeywords(func, args, nargs, NULL); + } + } + #if PY_VERSION_HEX >= 0x030700A1 + if (!kwargs && __Pyx_IS_TYPE(func, &PyMethodDescr_Type)) { + return _PyMethodDescr_FastCallKeywords(func, args, nargs, NULL); + } + #endif + #endif + #if CYTHON_FAST_PYCALL + if (PyFunction_Check(func)) { + return __Pyx_PyFunction_FastCallDict(func, args, nargs, kwargs); + } + #endif + #endif + if (kwargs == NULL) { + #if CYTHON_VECTORCALL + #if PY_VERSION_HEX < 0x03090000 + vectorcallfunc f = _PyVectorcall_Function(func); + #else + vectorcallfunc f = PyVectorcall_Function(func); + #endif + if (f) { + return f(func, args, (size_t)nargs, NULL); + } + #elif defined(__Pyx_CyFunction_USED) && CYTHON_BACKPORT_VECTORCALL + if (__Pyx_CyFunction_CheckExact(func)) { + __pyx_vectorcallfunc f = __Pyx_CyFunction_func_vectorcall(func); + if (f) return f(func, args, (size_t)nargs, NULL); + } + #endif + } + if (nargs == 0) { + return __Pyx_PyObject_Call(func, __pyx_empty_tuple, kwargs); + } + #if PY_VERSION_HEX >= 0x03090000 && !CYTHON_COMPILING_IN_LIMITED_API + return PyObject_VectorcallDict(func, args, (size_t)nargs, kwargs); + #else + return __Pyx_PyObject_FastCall_fallback(func, args, (size_t)nargs, kwargs); + #endif +} + +/* DictGetItem */ +#if PY_MAJOR_VERSION >= 3 && !CYTHON_COMPILING_IN_PYPY +static PyObject *__Pyx_PyDict_GetItem(PyObject *d, PyObject* key) { + PyObject *value; + value = PyDict_GetItemWithError(d, key); + if (unlikely(!value)) { + if (!PyErr_Occurred()) { + if (unlikely(PyTuple_Check(key))) { + PyObject* args = PyTuple_Pack(1, key); + if (likely(args)) { + PyErr_SetObject(PyExc_KeyError, args); + Py_DECREF(args); + } + } else { + PyErr_SetObject(PyExc_KeyError, key); + } + } + return NULL; + } + Py_INCREF(value); + return value; +} +#endif + +/* GetTopmostException */ +#if CYTHON_USE_EXC_INFO_STACK && CYTHON_FAST_THREAD_STATE +static _PyErr_StackItem * +__Pyx_PyErr_GetTopmostException(PyThreadState *tstate) +{ + _PyErr_StackItem *exc_info = tstate->exc_info; + while ((exc_info->exc_value == NULL || exc_info->exc_value == Py_None) && + exc_info->previous_item != NULL) + { + exc_info = exc_info->previous_item; + } + return exc_info; +} +#endif + +/* SaveResetException */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSave(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4 + _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); + PyObject *exc_value = exc_info->exc_value; + if (exc_value == NULL || exc_value == Py_None) { + *value = NULL; + *type = NULL; + *tb = NULL; + } else { + *value = exc_value; + Py_INCREF(*value); + *type = (PyObject*) Py_TYPE(exc_value); + Py_INCREF(*type); + *tb = PyException_GetTraceback(exc_value); + } + #elif CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = __Pyx_PyErr_GetTopmostException(tstate); + *type = exc_info->exc_type; + *value = exc_info->exc_value; + *tb = exc_info->exc_traceback; + Py_XINCREF(*type); + Py_XINCREF(*value); + Py_XINCREF(*tb); + #else + *type = tstate->exc_type; + *value = tstate->exc_value; + *tb = tstate->exc_traceback; + Py_XINCREF(*type); + Py_XINCREF(*value); + Py_XINCREF(*tb); + #endif +} +static CYTHON_INLINE void __Pyx__ExceptionReset(PyThreadState *tstate, PyObject *type, PyObject *value, PyObject *tb) { + #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4 + _PyErr_StackItem *exc_info = tstate->exc_info; + PyObject *tmp_value = exc_info->exc_value; + exc_info->exc_value = value; + Py_XDECREF(tmp_value); + Py_XDECREF(type); + Py_XDECREF(tb); + #else + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = type; + exc_info->exc_value = value; + exc_info->exc_traceback = tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = type; + tstate->exc_value = value; + tstate->exc_traceback = tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); + #endif +} +#endif + +/* GetException */ +#if CYTHON_FAST_THREAD_STATE +static int __Pyx__GetException(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) +#else +static int __Pyx_GetException(PyObject **type, PyObject **value, PyObject **tb) +#endif +{ + PyObject *local_type = NULL, *local_value, *local_tb = NULL; +#if CYTHON_FAST_THREAD_STATE + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if PY_VERSION_HEX >= 0x030C00A6 + local_value = tstate->current_exception; + tstate->current_exception = 0; + if (likely(local_value)) { + local_type = (PyObject*) Py_TYPE(local_value); + Py_INCREF(local_type); + local_tb = PyException_GetTraceback(local_value); + } + #else + local_type = tstate->curexc_type; + local_value = tstate->curexc_value; + local_tb = tstate->curexc_traceback; + tstate->curexc_type = 0; + tstate->curexc_value = 0; + tstate->curexc_traceback = 0; + #endif +#else + PyErr_Fetch(&local_type, &local_value, &local_tb); +#endif + PyErr_NormalizeException(&local_type, &local_value, &local_tb); +#if CYTHON_FAST_THREAD_STATE && PY_VERSION_HEX >= 0x030C00A6 + if (unlikely(tstate->current_exception)) +#elif CYTHON_FAST_THREAD_STATE + if (unlikely(tstate->curexc_type)) +#else + if (unlikely(PyErr_Occurred())) +#endif + goto bad; + #if PY_MAJOR_VERSION >= 3 + if (local_tb) { + if (unlikely(PyException_SetTraceback(local_value, local_tb) < 0)) + goto bad; + } + #endif + Py_XINCREF(local_tb); + Py_XINCREF(local_type); + Py_XINCREF(local_value); + *type = local_type; + *value = local_value; + *tb = local_tb; +#if CYTHON_FAST_THREAD_STATE + #if CYTHON_USE_EXC_INFO_STACK + { + _PyErr_StackItem *exc_info = tstate->exc_info; + #if PY_VERSION_HEX >= 0x030B00a4 + tmp_value = exc_info->exc_value; + exc_info->exc_value = local_value; + tmp_type = NULL; + tmp_tb = NULL; + Py_XDECREF(local_type); + Py_XDECREF(local_tb); + #else + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = local_type; + exc_info->exc_value = local_value; + exc_info->exc_traceback = local_tb; + #endif + } + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = local_type; + tstate->exc_value = local_value; + tstate->exc_traceback = local_tb; + #endif + Py_XDECREF(tmp_type); + Py_XDECREF(tmp_value); + Py_XDECREF(tmp_tb); +#else + PyErr_SetExcInfo(local_type, local_value, local_tb); +#endif + return 0; +bad: + *type = 0; + *value = 0; + *tb = 0; + Py_XDECREF(local_type); + Py_XDECREF(local_value); + Py_XDECREF(local_tb); + return -1; +} + +/* SwapException */ +#if CYTHON_FAST_THREAD_STATE +static CYTHON_INLINE void __Pyx__ExceptionSwap(PyThreadState *tstate, PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + #if CYTHON_USE_EXC_INFO_STACK && PY_VERSION_HEX >= 0x030B00a4 + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_value = exc_info->exc_value; + exc_info->exc_value = *value; + if (tmp_value == NULL || tmp_value == Py_None) { + Py_XDECREF(tmp_value); + tmp_value = NULL; + tmp_type = NULL; + tmp_tb = NULL; + } else { + tmp_type = (PyObject*) Py_TYPE(tmp_value); + Py_INCREF(tmp_type); + #if CYTHON_COMPILING_IN_CPYTHON + tmp_tb = ((PyBaseExceptionObject*) tmp_value)->traceback; + Py_XINCREF(tmp_tb); + #else + tmp_tb = PyException_GetTraceback(tmp_value); + #endif + } + #elif CYTHON_USE_EXC_INFO_STACK + _PyErr_StackItem *exc_info = tstate->exc_info; + tmp_type = exc_info->exc_type; + tmp_value = exc_info->exc_value; + tmp_tb = exc_info->exc_traceback; + exc_info->exc_type = *type; + exc_info->exc_value = *value; + exc_info->exc_traceback = *tb; + #else + tmp_type = tstate->exc_type; + tmp_value = tstate->exc_value; + tmp_tb = tstate->exc_traceback; + tstate->exc_type = *type; + tstate->exc_value = *value; + tstate->exc_traceback = *tb; + #endif + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#else +static CYTHON_INLINE void __Pyx_ExceptionSwap(PyObject **type, PyObject **value, PyObject **tb) { + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_GetExcInfo(&tmp_type, &tmp_value, &tmp_tb); + PyErr_SetExcInfo(*type, *value, *tb); + *type = tmp_type; + *value = tmp_value; + *tb = tmp_tb; +} +#endif + +/* GetItemInt */ +static PyObject *__Pyx_GetItemInt_Generic(PyObject *o, PyObject* j) { + PyObject *r; + if (unlikely(!j)) return NULL; + r = PyObject_GetItem(o, j); + Py_DECREF(j); + return r; +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_List_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + Py_ssize_t wrapped_i = i; + if (wraparound & unlikely(i < 0)) { + wrapped_i += PyList_GET_SIZE(o); + } + if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyList_GET_SIZE(o)))) { + PyObject *r = PyList_GET_ITEM(o, wrapped_i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Tuple_Fast(PyObject *o, Py_ssize_t i, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + Py_ssize_t wrapped_i = i; + if (wraparound & unlikely(i < 0)) { + wrapped_i += PyTuple_GET_SIZE(o); + } + if ((!boundscheck) || likely(__Pyx_is_valid_index(wrapped_i, PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, wrapped_i); + Py_INCREF(r); + return r; + } + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +#else + return PySequence_GetItem(o, i); +#endif +} +static CYTHON_INLINE PyObject *__Pyx_GetItemInt_Fast(PyObject *o, Py_ssize_t i, int is_list, + CYTHON_NCP_UNUSED int wraparound, + CYTHON_NCP_UNUSED int boundscheck) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS && CYTHON_USE_TYPE_SLOTS + if (is_list || PyList_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyList_GET_SIZE(o); + if ((!boundscheck) || (likely(__Pyx_is_valid_index(n, PyList_GET_SIZE(o))))) { + PyObject *r = PyList_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } + else if (PyTuple_CheckExact(o)) { + Py_ssize_t n = ((!wraparound) | likely(i >= 0)) ? i : i + PyTuple_GET_SIZE(o); + if ((!boundscheck) || likely(__Pyx_is_valid_index(n, PyTuple_GET_SIZE(o)))) { + PyObject *r = PyTuple_GET_ITEM(o, n); + Py_INCREF(r); + return r; + } + } else { + PyMappingMethods *mm = Py_TYPE(o)->tp_as_mapping; + PySequenceMethods *sm = Py_TYPE(o)->tp_as_sequence; + if (mm && mm->mp_subscript) { + PyObject *r, *key = PyInt_FromSsize_t(i); + if (unlikely(!key)) return NULL; + r = mm->mp_subscript(o, key); + Py_DECREF(key); + return r; + } + if (likely(sm && sm->sq_item)) { + if (wraparound && unlikely(i < 0) && likely(sm->sq_length)) { + Py_ssize_t l = sm->sq_length(o); + if (likely(l >= 0)) { + i += l; + } else { + if (!PyErr_ExceptionMatches(PyExc_OverflowError)) + return NULL; + PyErr_Clear(); + } + } + return sm->sq_item(o, i); + } + } +#else + if (is_list || !PyMapping_Check(o)) { + return PySequence_GetItem(o, i); + } +#endif + return __Pyx_GetItemInt_Generic(o, PyInt_FromSsize_t(i)); +} + +/* UnicodeConcatInPlace */ +# if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 +static int +__Pyx_unicode_modifiable(PyObject *unicode) +{ + if (Py_REFCNT(unicode) != 1) + return 0; + if (!PyUnicode_CheckExact(unicode)) + return 0; + if (PyUnicode_CHECK_INTERNED(unicode)) + return 0; + return 1; +} +static CYTHON_INLINE PyObject *__Pyx_PyUnicode_ConcatInPlaceImpl(PyObject **p_left, PyObject *right + #if CYTHON_REFNANNY + , void* __pyx_refnanny + #endif + ) { + PyObject *left = *p_left; + Py_ssize_t left_len, right_len, new_len; + if (unlikely(__Pyx_PyUnicode_READY(left) == -1)) + return NULL; + if (unlikely(__Pyx_PyUnicode_READY(right) == -1)) + return NULL; + left_len = PyUnicode_GET_LENGTH(left); + if (left_len == 0) { + Py_INCREF(right); + return right; + } + right_len = PyUnicode_GET_LENGTH(right); + if (right_len == 0) { + Py_INCREF(left); + return left; + } + if (unlikely(left_len > PY_SSIZE_T_MAX - right_len)) { + PyErr_SetString(PyExc_OverflowError, + "strings are too large to concat"); + return NULL; + } + new_len = left_len + right_len; + if (__Pyx_unicode_modifiable(left) + && PyUnicode_CheckExact(right) + && PyUnicode_KIND(right) <= PyUnicode_KIND(left) + && !(PyUnicode_IS_ASCII(left) && !PyUnicode_IS_ASCII(right))) { + int ret; + __Pyx_GIVEREF(*p_left); + ret = PyUnicode_Resize(p_left, new_len); + __Pyx_GOTREF(*p_left); + if (unlikely(ret != 0)) + return NULL; + #if PY_VERSION_HEX >= 0x030d0000 + if (unlikely(PyUnicode_CopyCharacters(*p_left, left_len, right, 0, right_len) < 0)) return NULL; + #else + _PyUnicode_FastCopyCharacters(*p_left, left_len, right, 0, right_len); + #endif + __Pyx_INCREF(*p_left); + __Pyx_GIVEREF(*p_left); + return *p_left; + } else { + return __Pyx_PyUnicode_Concat(left, right); + } + } +#endif + +/* FixUpExtensionType */ +#if CYTHON_USE_TYPE_SPECS +static int __Pyx_fix_up_extension_type_from_spec(PyType_Spec *spec, PyTypeObject *type) { +#if PY_VERSION_HEX > 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + CYTHON_UNUSED_VAR(spec); + CYTHON_UNUSED_VAR(type); +#else + const PyType_Slot *slot = spec->slots; + while (slot && slot->slot && slot->slot != Py_tp_members) + slot++; + if (slot && slot->slot == Py_tp_members) { + int changed = 0; +#if !(PY_VERSION_HEX <= 0x030900b1 && CYTHON_COMPILING_IN_CPYTHON) + const +#endif + PyMemberDef *memb = (PyMemberDef*) slot->pfunc; + while (memb && memb->name) { + if (memb->name[0] == '_' && memb->name[1] == '_') { +#if PY_VERSION_HEX < 0x030900b1 + if (strcmp(memb->name, "__weaklistoffset__") == 0) { + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); + type->tp_weaklistoffset = memb->offset; + changed = 1; + } + else if (strcmp(memb->name, "__dictoffset__") == 0) { + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); + type->tp_dictoffset = memb->offset; + changed = 1; + } +#if CYTHON_METH_FASTCALL + else if (strcmp(memb->name, "__vectorcalloffset__") == 0) { + assert(memb->type == T_PYSSIZET); + assert(memb->flags == READONLY); +#if PY_VERSION_HEX >= 0x030800b4 + type->tp_vectorcall_offset = memb->offset; +#else + type->tp_print = (printfunc) memb->offset; +#endif + changed = 1; + } +#endif +#else + if ((0)); +#endif +#if PY_VERSION_HEX <= 0x030900b1 && CYTHON_COMPILING_IN_CPYTHON + else if (strcmp(memb->name, "__module__") == 0) { + PyObject *descr; + assert(memb->type == T_OBJECT); + assert(memb->flags == 0 || memb->flags == READONLY); + descr = PyDescr_NewMember(type, memb); + if (unlikely(!descr)) + return -1; + if (unlikely(PyDict_SetItem(type->tp_dict, PyDescr_NAME(descr), descr) < 0)) { + Py_DECREF(descr); + return -1; + } + Py_DECREF(descr); + changed = 1; + } +#endif + } + memb++; + } + if (changed) + PyType_Modified(type); + } +#endif + return 0; +} +#endif + +/* FetchSharedCythonModule */ +static PyObject *__Pyx_FetchSharedCythonABIModule(void) { + return __Pyx_PyImport_AddModuleRef((char*) __PYX_ABI_MODULE_NAME); +} + +/* FetchCommonType */ +static int __Pyx_VerifyCachedType(PyObject *cached_type, + const char *name, + Py_ssize_t basicsize, + Py_ssize_t expected_basicsize) { + if (!PyType_Check(cached_type)) { + PyErr_Format(PyExc_TypeError, + "Shared Cython type %.200s is not a type object", name); + return -1; + } + if (basicsize != expected_basicsize) { + PyErr_Format(PyExc_TypeError, + "Shared Cython type %.200s has the wrong size, try recompiling", + name); + return -1; + } + return 0; +} +#if !CYTHON_USE_TYPE_SPECS +static PyTypeObject* __Pyx_FetchCommonType(PyTypeObject* type) { + PyObject* abi_module; + const char* object_name; + PyTypeObject *cached_type = NULL; + abi_module = __Pyx_FetchSharedCythonABIModule(); + if (!abi_module) return NULL; + object_name = strrchr(type->tp_name, '.'); + object_name = object_name ? object_name+1 : type->tp_name; + cached_type = (PyTypeObject*) PyObject_GetAttrString(abi_module, object_name); + if (cached_type) { + if (__Pyx_VerifyCachedType( + (PyObject *)cached_type, + object_name, + cached_type->tp_basicsize, + type->tp_basicsize) < 0) { + goto bad; + } + goto done; + } + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; + PyErr_Clear(); + if (PyType_Ready(type) < 0) goto bad; + if (PyObject_SetAttrString(abi_module, object_name, (PyObject *)type) < 0) + goto bad; + Py_INCREF(type); + cached_type = type; +done: + Py_DECREF(abi_module); + return cached_type; +bad: + Py_XDECREF(cached_type); + cached_type = NULL; + goto done; +} +#else +static PyTypeObject *__Pyx_FetchCommonTypeFromSpec(PyObject *module, PyType_Spec *spec, PyObject *bases) { + PyObject *abi_module, *cached_type = NULL; + const char* object_name = strrchr(spec->name, '.'); + object_name = object_name ? object_name+1 : spec->name; + abi_module = __Pyx_FetchSharedCythonABIModule(); + if (!abi_module) return NULL; + cached_type = PyObject_GetAttrString(abi_module, object_name); + if (cached_type) { + Py_ssize_t basicsize; +#if CYTHON_COMPILING_IN_LIMITED_API + PyObject *py_basicsize; + py_basicsize = PyObject_GetAttrString(cached_type, "__basicsize__"); + if (unlikely(!py_basicsize)) goto bad; + basicsize = PyLong_AsSsize_t(py_basicsize); + Py_DECREF(py_basicsize); + py_basicsize = 0; + if (unlikely(basicsize == (Py_ssize_t)-1) && PyErr_Occurred()) goto bad; +#else + basicsize = likely(PyType_Check(cached_type)) ? ((PyTypeObject*) cached_type)->tp_basicsize : -1; +#endif + if (__Pyx_VerifyCachedType( + cached_type, + object_name, + basicsize, + spec->basicsize) < 0) { + goto bad; + } + goto done; + } + if (!PyErr_ExceptionMatches(PyExc_AttributeError)) goto bad; + PyErr_Clear(); + CYTHON_UNUSED_VAR(module); + cached_type = __Pyx_PyType_FromModuleAndSpec(abi_module, spec, bases); + if (unlikely(!cached_type)) goto bad; + if (unlikely(__Pyx_fix_up_extension_type_from_spec(spec, (PyTypeObject *) cached_type) < 0)) goto bad; + if (PyObject_SetAttrString(abi_module, object_name, cached_type) < 0) goto bad; +done: + Py_DECREF(abi_module); + assert(cached_type == NULL || PyType_Check(cached_type)); + return (PyTypeObject *) cached_type; +bad: + Py_XDECREF(cached_type); + cached_type = NULL; + goto done; +} +#endif + +/* RaiseException */ +#if PY_MAJOR_VERSION < 3 +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + __Pyx_PyThreadState_declare + CYTHON_UNUSED_VAR(cause); + Py_XINCREF(type); + if (!value || value == Py_None) + value = NULL; + else + Py_INCREF(value); + if (!tb || tb == Py_None) + tb = NULL; + else { + Py_INCREF(tb); + if (!PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto raise_error; + } + } + if (PyType_Check(type)) { +#if CYTHON_COMPILING_IN_PYPY + if (!value) { + Py_INCREF(Py_None); + value = Py_None; + } +#endif + PyErr_NormalizeException(&type, &value, &tb); + } else { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto raise_error; + } + value = type; + type = (PyObject*) Py_TYPE(type); + Py_INCREF(type); + if (!PyType_IsSubtype((PyTypeObject *)type, (PyTypeObject *)PyExc_BaseException)) { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto raise_error; + } + } + __Pyx_PyThreadState_assign + __Pyx_ErrRestore(type, value, tb); + return; +raise_error: + Py_XDECREF(value); + Py_XDECREF(type); + Py_XDECREF(tb); + return; +} +#else +static void __Pyx_Raise(PyObject *type, PyObject *value, PyObject *tb, PyObject *cause) { + PyObject* owned_instance = NULL; + if (tb == Py_None) { + tb = 0; + } else if (tb && !PyTraceBack_Check(tb)) { + PyErr_SetString(PyExc_TypeError, + "raise: arg 3 must be a traceback or None"); + goto bad; + } + if (value == Py_None) + value = 0; + if (PyExceptionInstance_Check(type)) { + if (value) { + PyErr_SetString(PyExc_TypeError, + "instance exception may not have a separate value"); + goto bad; + } + value = type; + type = (PyObject*) Py_TYPE(value); + } else if (PyExceptionClass_Check(type)) { + PyObject *instance_class = NULL; + if (value && PyExceptionInstance_Check(value)) { + instance_class = (PyObject*) Py_TYPE(value); + if (instance_class != type) { + int is_subclass = PyObject_IsSubclass(instance_class, type); + if (!is_subclass) { + instance_class = NULL; + } else if (unlikely(is_subclass == -1)) { + goto bad; + } else { + type = instance_class; + } + } + } + if (!instance_class) { + PyObject *args; + if (!value) + args = PyTuple_New(0); + else if (PyTuple_Check(value)) { + Py_INCREF(value); + args = value; + } else + args = PyTuple_Pack(1, value); + if (!args) + goto bad; + owned_instance = PyObject_Call(type, args, NULL); + Py_DECREF(args); + if (!owned_instance) + goto bad; + value = owned_instance; + if (!PyExceptionInstance_Check(value)) { + PyErr_Format(PyExc_TypeError, + "calling %R should have returned an instance of " + "BaseException, not %R", + type, Py_TYPE(value)); + goto bad; + } + } + } else { + PyErr_SetString(PyExc_TypeError, + "raise: exception class must be a subclass of BaseException"); + goto bad; + } + if (cause) { + PyObject *fixed_cause; + if (cause == Py_None) { + fixed_cause = NULL; + } else if (PyExceptionClass_Check(cause)) { + fixed_cause = PyObject_CallObject(cause, NULL); + if (fixed_cause == NULL) + goto bad; + } else if (PyExceptionInstance_Check(cause)) { + fixed_cause = cause; + Py_INCREF(fixed_cause); + } else { + PyErr_SetString(PyExc_TypeError, + "exception causes must derive from " + "BaseException"); + goto bad; + } + PyException_SetCause(value, fixed_cause); + } + PyErr_SetObject(type, value); + if (tb) { + #if PY_VERSION_HEX >= 0x030C00A6 + PyException_SetTraceback(value, tb); + #elif CYTHON_FAST_THREAD_STATE + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject* tmp_tb = tstate->curexc_traceback; + if (tb != tmp_tb) { + Py_INCREF(tb); + tstate->curexc_traceback = tb; + Py_XDECREF(tmp_tb); + } +#else + PyObject *tmp_type, *tmp_value, *tmp_tb; + PyErr_Fetch(&tmp_type, &tmp_value, &tmp_tb); + Py_INCREF(tb); + PyErr_Restore(tmp_type, tmp_value, tb); + Py_XDECREF(tmp_tb); +#endif + } +bad: + Py_XDECREF(owned_instance); + return; +} +#endif + +/* PyObjectCall2Args */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_Call2Args(PyObject* function, PyObject* arg1, PyObject* arg2) { + PyObject *args[3] = {NULL, arg1, arg2}; + return __Pyx_PyObject_FastCall(function, args+1, 2 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET); +} + +/* PyObjectCallOneArg */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallOneArg(PyObject *func, PyObject *arg) { + PyObject *args[2] = {NULL, arg}; + return __Pyx_PyObject_FastCall(func, args+1, 1 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET); +} + +/* PyObjectGetMethod */ +static int __Pyx_PyObject_GetMethod(PyObject *obj, PyObject *name, PyObject **method) { + PyObject *attr; +#if CYTHON_UNPACK_METHODS && CYTHON_COMPILING_IN_CPYTHON && CYTHON_USE_PYTYPE_LOOKUP + __Pyx_TypeName type_name; + PyTypeObject *tp = Py_TYPE(obj); + PyObject *descr; + descrgetfunc f = NULL; + PyObject **dictptr, *dict; + int meth_found = 0; + assert (*method == NULL); + if (unlikely(tp->tp_getattro != PyObject_GenericGetAttr)) { + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; + } + if (unlikely(tp->tp_dict == NULL) && unlikely(PyType_Ready(tp) < 0)) { + return 0; + } + descr = _PyType_Lookup(tp, name); + if (likely(descr != NULL)) { + Py_INCREF(descr); +#if defined(Py_TPFLAGS_METHOD_DESCRIPTOR) && Py_TPFLAGS_METHOD_DESCRIPTOR + if (__Pyx_PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_METHOD_DESCRIPTOR)) +#elif PY_MAJOR_VERSION >= 3 + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr) || __Pyx_IS_TYPE(descr, &PyMethodDescr_Type))) + #endif +#else + #ifdef __Pyx_CyFunction_USED + if (likely(PyFunction_Check(descr) || __Pyx_CyFunction_Check(descr))) + #else + if (likely(PyFunction_Check(descr))) + #endif +#endif + { + meth_found = 1; + } else { + f = Py_TYPE(descr)->tp_descr_get; + if (f != NULL && PyDescr_IsData(descr)) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + } + } + dictptr = _PyObject_GetDictPtr(obj); + if (dictptr != NULL && (dict = *dictptr) != NULL) { + Py_INCREF(dict); + attr = __Pyx_PyDict_GetItemStr(dict, name); + if (attr != NULL) { + Py_INCREF(attr); + Py_DECREF(dict); + Py_XDECREF(descr); + goto try_unpack; + } + Py_DECREF(dict); + } + if (meth_found) { + *method = descr; + return 1; + } + if (f != NULL) { + attr = f(descr, obj, (PyObject *)Py_TYPE(obj)); + Py_DECREF(descr); + goto try_unpack; + } + if (likely(descr != NULL)) { + *method = descr; + return 0; + } + type_name = __Pyx_PyType_GetName(tp); + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%U'", + type_name, name); +#else + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%.400s'", + type_name, PyString_AS_STRING(name)); +#endif + __Pyx_DECREF_TypeName(type_name); + return 0; +#else + attr = __Pyx_PyObject_GetAttrStr(obj, name); + goto try_unpack; +#endif +try_unpack: +#if CYTHON_UNPACK_METHODS + if (likely(attr) && PyMethod_Check(attr) && likely(PyMethod_GET_SELF(attr) == obj)) { + PyObject *function = PyMethod_GET_FUNCTION(attr); + Py_INCREF(function); + Py_DECREF(attr); + *method = function; + return 1; + } +#endif + *method = attr; + return 0; +} + +/* PyObjectCallMethod1 */ +#if !(CYTHON_VECTORCALL && __PYX_LIMITED_VERSION_HEX >= 0x030C00A2) +static PyObject* __Pyx__PyObject_CallMethod1(PyObject* method, PyObject* arg) { + PyObject *result = __Pyx_PyObject_CallOneArg(method, arg); + Py_DECREF(method); + return result; +} +#endif +static PyObject* __Pyx_PyObject_CallMethod1(PyObject* obj, PyObject* method_name, PyObject* arg) { +#if CYTHON_VECTORCALL && __PYX_LIMITED_VERSION_HEX >= 0x030C00A2 + PyObject *args[2] = {obj, arg}; + (void) __Pyx_PyObject_GetMethod; + (void) __Pyx_PyObject_CallOneArg; + (void) __Pyx_PyObject_Call2Args; + return PyObject_VectorcallMethod(method_name, args, 2 | PY_VECTORCALL_ARGUMENTS_OFFSET, NULL); +#else + PyObject *method = NULL, *result; + int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); + if (likely(is_method)) { + result = __Pyx_PyObject_Call2Args(method, obj, arg); + Py_DECREF(method); + return result; + } + if (unlikely(!method)) return NULL; + return __Pyx__PyObject_CallMethod1(method, arg); +#endif +} + +/* PyObjectCallNoArg */ +static CYTHON_INLINE PyObject* __Pyx_PyObject_CallNoArg(PyObject *func) { + PyObject *arg[2] = {NULL, NULL}; + return __Pyx_PyObject_FastCall(func, arg + 1, 0 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET); +} + +/* CoroutineBase */ +#include +#if PY_VERSION_HEX >= 0x030b00a6 + #ifndef Py_BUILD_CORE + #define Py_BUILD_CORE 1 + #endif + #include "internal/pycore_frame.h" +#endif +#define __Pyx_Coroutine_Undelegate(gen) Py_CLEAR((gen)->yieldfrom) +static int __Pyx_PyGen__FetchStopIterationValue(PyThreadState *__pyx_tstate, PyObject **pvalue) { + PyObject *et, *ev, *tb; + PyObject *value = NULL; + CYTHON_UNUSED_VAR(__pyx_tstate); + __Pyx_ErrFetch(&et, &ev, &tb); + if (!et) { + Py_XDECREF(tb); + Py_XDECREF(ev); + Py_INCREF(Py_None); + *pvalue = Py_None; + return 0; + } + if (likely(et == PyExc_StopIteration)) { + if (!ev) { + Py_INCREF(Py_None); + value = Py_None; + } +#if PY_VERSION_HEX >= 0x030300A0 + else if (likely(__Pyx_IS_TYPE(ev, (PyTypeObject*)PyExc_StopIteration))) { + value = ((PyStopIterationObject *)ev)->value; + Py_INCREF(value); + Py_DECREF(ev); + } +#endif + else if (unlikely(PyTuple_Check(ev))) { + if (PyTuple_GET_SIZE(ev) >= 1) { +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + value = PyTuple_GET_ITEM(ev, 0); + Py_INCREF(value); +#else + value = PySequence_ITEM(ev, 0); +#endif + } else { + Py_INCREF(Py_None); + value = Py_None; + } + Py_DECREF(ev); + } + else if (!__Pyx_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration)) { + value = ev; + } + if (likely(value)) { + Py_XDECREF(tb); + Py_DECREF(et); + *pvalue = value; + return 0; + } + } else if (!__Pyx_PyErr_GivenExceptionMatches(et, PyExc_StopIteration)) { + __Pyx_ErrRestore(et, ev, tb); + return -1; + } + PyErr_NormalizeException(&et, &ev, &tb); + if (unlikely(!PyObject_TypeCheck(ev, (PyTypeObject*)PyExc_StopIteration))) { + __Pyx_ErrRestore(et, ev, tb); + return -1; + } + Py_XDECREF(tb); + Py_DECREF(et); +#if PY_VERSION_HEX >= 0x030300A0 + value = ((PyStopIterationObject *)ev)->value; + Py_INCREF(value); + Py_DECREF(ev); +#else + { + PyObject* args = __Pyx_PyObject_GetAttrStr(ev, __pyx_n_s_args); + Py_DECREF(ev); + if (likely(args)) { + value = PySequence_GetItem(args, 0); + Py_DECREF(args); + } + if (unlikely(!value)) { + __Pyx_ErrRestore(NULL, NULL, NULL); + Py_INCREF(Py_None); + value = Py_None; + } + } +#endif + *pvalue = value; + return 0; +} +static CYTHON_INLINE +void __Pyx_Coroutine_ExceptionClear(__Pyx_ExcInfoStruct *exc_state) { +#if PY_VERSION_HEX >= 0x030B00a4 + Py_CLEAR(exc_state->exc_value); +#else + PyObject *t, *v, *tb; + t = exc_state->exc_type; + v = exc_state->exc_value; + tb = exc_state->exc_traceback; + exc_state->exc_type = NULL; + exc_state->exc_value = NULL; + exc_state->exc_traceback = NULL; + Py_XDECREF(t); + Py_XDECREF(v); + Py_XDECREF(tb); +#endif +} +#define __Pyx_Coroutine_AlreadyRunningError(gen) (__Pyx__Coroutine_AlreadyRunningError(gen), (PyObject*)NULL) +static void __Pyx__Coroutine_AlreadyRunningError(__pyx_CoroutineObject *gen) { + const char *msg; + CYTHON_MAYBE_UNUSED_VAR(gen); + if ((0)) { + #ifdef __Pyx_Coroutine_USED + } else if (__Pyx_Coroutine_Check((PyObject*)gen)) { + msg = "coroutine already executing"; + #endif + #ifdef __Pyx_AsyncGen_USED + } else if (__Pyx_AsyncGen_CheckExact((PyObject*)gen)) { + msg = "async generator already executing"; + #endif + } else { + msg = "generator already executing"; + } + PyErr_SetString(PyExc_ValueError, msg); +} +#define __Pyx_Coroutine_NotStartedError(gen) (__Pyx__Coroutine_NotStartedError(gen), (PyObject*)NULL) +static void __Pyx__Coroutine_NotStartedError(PyObject *gen) { + const char *msg; + CYTHON_MAYBE_UNUSED_VAR(gen); + if ((0)) { + #ifdef __Pyx_Coroutine_USED + } else if (__Pyx_Coroutine_Check(gen)) { + msg = "can't send non-None value to a just-started coroutine"; + #endif + #ifdef __Pyx_AsyncGen_USED + } else if (__Pyx_AsyncGen_CheckExact(gen)) { + msg = "can't send non-None value to a just-started async generator"; + #endif + } else { + msg = "can't send non-None value to a just-started generator"; + } + PyErr_SetString(PyExc_TypeError, msg); +} +#define __Pyx_Coroutine_AlreadyTerminatedError(gen, value, closing) (__Pyx__Coroutine_AlreadyTerminatedError(gen, value, closing), (PyObject*)NULL) +static void __Pyx__Coroutine_AlreadyTerminatedError(PyObject *gen, PyObject *value, int closing) { + CYTHON_MAYBE_UNUSED_VAR(gen); + CYTHON_MAYBE_UNUSED_VAR(closing); + #ifdef __Pyx_Coroutine_USED + if (!closing && __Pyx_Coroutine_Check(gen)) { + PyErr_SetString(PyExc_RuntimeError, "cannot reuse already awaited coroutine"); + } else + #endif + if (value) { + #ifdef __Pyx_AsyncGen_USED + if (__Pyx_AsyncGen_CheckExact(gen)) + PyErr_SetNone(__Pyx_PyExc_StopAsyncIteration); + else + #endif + PyErr_SetNone(PyExc_StopIteration); + } +} +static +PyObject *__Pyx_Coroutine_SendEx(__pyx_CoroutineObject *self, PyObject *value, int closing) { + __Pyx_PyThreadState_declare + PyThreadState *tstate; + __Pyx_ExcInfoStruct *exc_state; + PyObject *retval; + assert(!self->is_running); + if (unlikely(self->resume_label == 0)) { + if (unlikely(value && value != Py_None)) { + return __Pyx_Coroutine_NotStartedError((PyObject*)self); + } + } + if (unlikely(self->resume_label == -1)) { + return __Pyx_Coroutine_AlreadyTerminatedError((PyObject*)self, value, closing); + } +#if CYTHON_FAST_THREAD_STATE + __Pyx_PyThreadState_assign + tstate = __pyx_tstate; +#else + tstate = __Pyx_PyThreadState_Current; +#endif + exc_state = &self->gi_exc_state; + if (exc_state->exc_value) { + #if CYTHON_COMPILING_IN_PYPY + #else + PyObject *exc_tb; + #if PY_VERSION_HEX >= 0x030B00a4 && !CYTHON_COMPILING_IN_CPYTHON + exc_tb = PyException_GetTraceback(exc_state->exc_value); + #elif PY_VERSION_HEX >= 0x030B00a4 + exc_tb = ((PyBaseExceptionObject*) exc_state->exc_value)->traceback; + #else + exc_tb = exc_state->exc_traceback; + #endif + if (exc_tb) { + PyTracebackObject *tb = (PyTracebackObject *) exc_tb; + PyFrameObject *f = tb->tb_frame; + assert(f->f_back == NULL); + #if PY_VERSION_HEX >= 0x030B00A1 + f->f_back = PyThreadState_GetFrame(tstate); + #else + Py_XINCREF(tstate->frame); + f->f_back = tstate->frame; + #endif + #if PY_VERSION_HEX >= 0x030B00a4 && !CYTHON_COMPILING_IN_CPYTHON + Py_DECREF(exc_tb); + #endif + } + #endif + } +#if CYTHON_USE_EXC_INFO_STACK + exc_state->previous_item = tstate->exc_info; + tstate->exc_info = exc_state; +#else + if (exc_state->exc_type) { + __Pyx_ExceptionSwap(&exc_state->exc_type, &exc_state->exc_value, &exc_state->exc_traceback); + } else { + __Pyx_Coroutine_ExceptionClear(exc_state); + __Pyx_ExceptionSave(&exc_state->exc_type, &exc_state->exc_value, &exc_state->exc_traceback); + } +#endif + self->is_running = 1; + retval = self->body(self, tstate, value); + self->is_running = 0; +#if CYTHON_USE_EXC_INFO_STACK + exc_state = &self->gi_exc_state; + tstate->exc_info = exc_state->previous_item; + exc_state->previous_item = NULL; + __Pyx_Coroutine_ResetFrameBackpointer(exc_state); +#endif + return retval; +} +static CYTHON_INLINE void __Pyx_Coroutine_ResetFrameBackpointer(__Pyx_ExcInfoStruct *exc_state) { +#if CYTHON_COMPILING_IN_PYPY + CYTHON_UNUSED_VAR(exc_state); +#else + PyObject *exc_tb; + #if PY_VERSION_HEX >= 0x030B00a4 + if (!exc_state->exc_value) return; + exc_tb = PyException_GetTraceback(exc_state->exc_value); + #else + exc_tb = exc_state->exc_traceback; + #endif + if (likely(exc_tb)) { + PyTracebackObject *tb = (PyTracebackObject *) exc_tb; + PyFrameObject *f = tb->tb_frame; + Py_CLEAR(f->f_back); + #if PY_VERSION_HEX >= 0x030B00a4 + Py_DECREF(exc_tb); + #endif + } +#endif +} +static CYTHON_INLINE +PyObject *__Pyx_Coroutine_MethodReturn(PyObject* gen, PyObject *retval) { + CYTHON_MAYBE_UNUSED_VAR(gen); + if (unlikely(!retval)) { + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + if (!__Pyx_PyErr_Occurred()) { + PyObject *exc = PyExc_StopIteration; + #ifdef __Pyx_AsyncGen_USED + if (__Pyx_AsyncGen_CheckExact(gen)) + exc = __Pyx_PyExc_StopAsyncIteration; + #endif + __Pyx_PyErr_SetNone(exc); + } + } + return retval; +} +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3) +static CYTHON_INLINE +PyObject *__Pyx_PyGen_Send(PyGenObject *gen, PyObject *arg) { +#if PY_VERSION_HEX <= 0x030A00A1 + return _PyGen_Send(gen, arg); +#else + PyObject *result; + if (PyIter_Send((PyObject*)gen, arg ? arg : Py_None, &result) == PYGEN_RETURN) { + if (PyAsyncGen_CheckExact(gen)) { + assert(result == Py_None); + PyErr_SetNone(PyExc_StopAsyncIteration); + } + else if (result == Py_None) { + PyErr_SetNone(PyExc_StopIteration); + } + else { +#if PY_VERSION_HEX < 0x030d00A1 + _PyGen_SetStopIterationValue(result); +#else + if (!PyTuple_Check(result) && !PyExceptionInstance_Check(result)) { + PyErr_SetObject(PyExc_StopIteration, result); + } else { + PyObject *exc = __Pyx_PyObject_CallOneArg(PyExc_StopIteration, result); + if (likely(exc != NULL)) { + PyErr_SetObject(PyExc_StopIteration, exc); + Py_DECREF(exc); + } + } +#endif + } + Py_DECREF(result); + result = NULL; + } + return result; +#endif +} +#endif +static CYTHON_INLINE +PyObject *__Pyx_Coroutine_FinishDelegation(__pyx_CoroutineObject *gen) { + PyObject *ret; + PyObject *val = NULL; + __Pyx_Coroutine_Undelegate(gen); + __Pyx_PyGen__FetchStopIterationValue(__Pyx_PyThreadState_Current, &val); + ret = __Pyx_Coroutine_SendEx(gen, val, 0); + Py_XDECREF(val); + return ret; +} +static PyObject *__Pyx_Coroutine_Send(PyObject *self, PyObject *value) { + PyObject *retval; + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self; + PyObject *yf = gen->yieldfrom; + if (unlikely(gen->is_running)) + return __Pyx_Coroutine_AlreadyRunningError(gen); + if (yf) { + PyObject *ret; + gen->is_running = 1; + #ifdef __Pyx_Generator_USED + if (__Pyx_Generator_CheckExact(yf)) { + ret = __Pyx_Coroutine_Send(yf, value); + } else + #endif + #ifdef __Pyx_Coroutine_USED + if (__Pyx_Coroutine_Check(yf)) { + ret = __Pyx_Coroutine_Send(yf, value); + } else + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_PyAsyncGenASend_CheckExact(yf)) { + ret = __Pyx_async_gen_asend_send(yf, value); + } else + #endif + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3) + if (PyGen_CheckExact(yf)) { + ret = __Pyx_PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value); + } else + #endif + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03050000 && defined(PyCoro_CheckExact) && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3) + if (PyCoro_CheckExact(yf)) { + ret = __Pyx_PyGen_Send((PyGenObject*)yf, value == Py_None ? NULL : value); + } else + #endif + { + if (value == Py_None) + ret = __Pyx_PyObject_GetIterNextFunc(yf)(yf); + else + ret = __Pyx_PyObject_CallMethod1(yf, __pyx_n_s_send, value); + } + gen->is_running = 0; + if (likely(ret)) { + return ret; + } + retval = __Pyx_Coroutine_FinishDelegation(gen); + } else { + retval = __Pyx_Coroutine_SendEx(gen, value, 0); + } + return __Pyx_Coroutine_MethodReturn(self, retval); +} +static int __Pyx_Coroutine_CloseIter(__pyx_CoroutineObject *gen, PyObject *yf) { + PyObject *retval = NULL; + int err = 0; + #ifdef __Pyx_Generator_USED + if (__Pyx_Generator_CheckExact(yf)) { + retval = __Pyx_Coroutine_Close(yf); + if (!retval) + return -1; + } else + #endif + #ifdef __Pyx_Coroutine_USED + if (__Pyx_Coroutine_Check(yf)) { + retval = __Pyx_Coroutine_Close(yf); + if (!retval) + return -1; + } else + if (__Pyx_CoroutineAwait_CheckExact(yf)) { + retval = __Pyx_CoroutineAwait_Close((__pyx_CoroutineAwaitObject*)yf, NULL); + if (!retval) + return -1; + } else + #endif + #ifdef __Pyx_AsyncGen_USED + if (__pyx_PyAsyncGenASend_CheckExact(yf)) { + retval = __Pyx_async_gen_asend_close(yf, NULL); + } else + if (__pyx_PyAsyncGenAThrow_CheckExact(yf)) { + retval = __Pyx_async_gen_athrow_close(yf, NULL); + } else + #endif + { + PyObject *meth; + gen->is_running = 1; + meth = __Pyx_PyObject_GetAttrStrNoError(yf, __pyx_n_s_close); + if (unlikely(!meth)) { + if (unlikely(PyErr_Occurred())) { + PyErr_WriteUnraisable(yf); + } + } else { + retval = __Pyx_PyObject_CallNoArg(meth); + Py_DECREF(meth); + if (unlikely(!retval)) + err = -1; + } + gen->is_running = 0; + } + Py_XDECREF(retval); + return err; +} +static PyObject *__Pyx_Generator_Next(PyObject *self) { + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject*) self; + PyObject *yf = gen->yieldfrom; + if (unlikely(gen->is_running)) + return __Pyx_Coroutine_AlreadyRunningError(gen); + if (yf) { + PyObject *ret; + gen->is_running = 1; + #ifdef __Pyx_Generator_USED + if (__Pyx_Generator_CheckExact(yf)) { + ret = __Pyx_Generator_Next(yf); + } else + #endif + #if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x03030000 && (defined(__linux__) || PY_VERSION_HEX >= 0x030600B3) + if (PyGen_CheckExact(yf)) { + ret = __Pyx_PyGen_Send((PyGenObject*)yf, NULL); + } else + #endif + #ifdef __Pyx_Coroutine_USED + if (__Pyx_Coroutine_Check(yf)) { + ret = __Pyx_Coroutine_Send(yf, Py_None); + } else + #endif + ret = __Pyx_PyObject_GetIterNextFunc(yf)(yf); + gen->is_running = 0; + if (likely(ret)) { + return ret; + } + return __Pyx_Coroutine_FinishDelegation(gen); + } + return __Pyx_Coroutine_SendEx(gen, Py_None, 0); +} +static PyObject *__Pyx_Coroutine_Close_Method(PyObject *self, PyObject *arg) { + CYTHON_UNUSED_VAR(arg); + return __Pyx_Coroutine_Close(self); +} +static PyObject *__Pyx_Coroutine_Close(PyObject *self) { + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; + PyObject *retval, *raised_exception; + PyObject *yf = gen->yieldfrom; + int err = 0; + if (unlikely(gen->is_running)) + return __Pyx_Coroutine_AlreadyRunningError(gen); + if (yf) { + Py_INCREF(yf); + err = __Pyx_Coroutine_CloseIter(gen, yf); + __Pyx_Coroutine_Undelegate(gen); + Py_DECREF(yf); + } + if (err == 0) + PyErr_SetNone(PyExc_GeneratorExit); + retval = __Pyx_Coroutine_SendEx(gen, NULL, 1); + if (unlikely(retval)) { + const char *msg; + Py_DECREF(retval); + if ((0)) { + #ifdef __Pyx_Coroutine_USED + } else if (__Pyx_Coroutine_Check(self)) { + msg = "coroutine ignored GeneratorExit"; + #endif + #ifdef __Pyx_AsyncGen_USED + } else if (__Pyx_AsyncGen_CheckExact(self)) { +#if PY_VERSION_HEX < 0x03060000 + msg = "async generator ignored GeneratorExit - might require Python 3.6+ finalisation (PEP 525)"; +#else + msg = "async generator ignored GeneratorExit"; +#endif + #endif + } else { + msg = "generator ignored GeneratorExit"; + } + PyErr_SetString(PyExc_RuntimeError, msg); + return NULL; + } + raised_exception = PyErr_Occurred(); + if (likely(!raised_exception || __Pyx_PyErr_GivenExceptionMatches2(raised_exception, PyExc_GeneratorExit, PyExc_StopIteration))) { + if (raised_exception) PyErr_Clear(); + Py_INCREF(Py_None); + return Py_None; + } + return NULL; +} +static PyObject *__Pyx__Coroutine_Throw(PyObject *self, PyObject *typ, PyObject *val, PyObject *tb, + PyObject *args, int close_on_genexit) { + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; + PyObject *yf = gen->yieldfrom; + if (unlikely(gen->is_running)) + return __Pyx_Coroutine_AlreadyRunningError(gen); + if (yf) { + PyObject *ret; + Py_INCREF(yf); + if (__Pyx_PyErr_GivenExceptionMatches(typ, PyExc_GeneratorExit) && close_on_genexit) { + int err = __Pyx_Coroutine_CloseIter(gen, yf); + Py_DECREF(yf); + __Pyx_Coroutine_Undelegate(gen); + if (err < 0) + return __Pyx_Coroutine_MethodReturn(self, __Pyx_Coroutine_SendEx(gen, NULL, 0)); + goto throw_here; + } + gen->is_running = 1; + if (0 + #ifdef __Pyx_Generator_USED + || __Pyx_Generator_CheckExact(yf) + #endif + #ifdef __Pyx_Coroutine_USED + || __Pyx_Coroutine_Check(yf) + #endif + ) { + ret = __Pyx__Coroutine_Throw(yf, typ, val, tb, args, close_on_genexit); + #ifdef __Pyx_Coroutine_USED + } else if (__Pyx_CoroutineAwait_CheckExact(yf)) { + ret = __Pyx__Coroutine_Throw(((__pyx_CoroutineAwaitObject*)yf)->coroutine, typ, val, tb, args, close_on_genexit); + #endif + } else { + PyObject *meth = __Pyx_PyObject_GetAttrStrNoError(yf, __pyx_n_s_throw); + if (unlikely(!meth)) { + Py_DECREF(yf); + if (unlikely(PyErr_Occurred())) { + gen->is_running = 0; + return NULL; + } + __Pyx_Coroutine_Undelegate(gen); + gen->is_running = 0; + goto throw_here; + } + if (likely(args)) { + ret = __Pyx_PyObject_Call(meth, args, NULL); + } else { + PyObject *cargs[4] = {NULL, typ, val, tb}; + ret = __Pyx_PyObject_FastCall(meth, cargs+1, 3 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET); + } + Py_DECREF(meth); + } + gen->is_running = 0; + Py_DECREF(yf); + if (!ret) { + ret = __Pyx_Coroutine_FinishDelegation(gen); + } + return __Pyx_Coroutine_MethodReturn(self, ret); + } +throw_here: + __Pyx_Raise(typ, val, tb, NULL); + return __Pyx_Coroutine_MethodReturn(self, __Pyx_Coroutine_SendEx(gen, NULL, 0)); +} +static PyObject *__Pyx_Coroutine_Throw(PyObject *self, PyObject *args) { + PyObject *typ; + PyObject *val = NULL; + PyObject *tb = NULL; + if (unlikely(!PyArg_UnpackTuple(args, (char *)"throw", 1, 3, &typ, &val, &tb))) + return NULL; + return __Pyx__Coroutine_Throw(self, typ, val, tb, args, 1); +} +static CYTHON_INLINE int __Pyx_Coroutine_traverse_excstate(__Pyx_ExcInfoStruct *exc_state, visitproc visit, void *arg) { +#if PY_VERSION_HEX >= 0x030B00a4 + Py_VISIT(exc_state->exc_value); +#else + Py_VISIT(exc_state->exc_type); + Py_VISIT(exc_state->exc_value); + Py_VISIT(exc_state->exc_traceback); +#endif + return 0; +} +static int __Pyx_Coroutine_traverse(__pyx_CoroutineObject *gen, visitproc visit, void *arg) { + Py_VISIT(gen->closure); + Py_VISIT(gen->classobj); + Py_VISIT(gen->yieldfrom); + return __Pyx_Coroutine_traverse_excstate(&gen->gi_exc_state, visit, arg); +} +static int __Pyx_Coroutine_clear(PyObject *self) { + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; + Py_CLEAR(gen->closure); + Py_CLEAR(gen->classobj); + Py_CLEAR(gen->yieldfrom); + __Pyx_Coroutine_ExceptionClear(&gen->gi_exc_state); +#ifdef __Pyx_AsyncGen_USED + if (__Pyx_AsyncGen_CheckExact(self)) { + Py_CLEAR(((__pyx_PyAsyncGenObject*)gen)->ag_finalizer); + } +#endif + Py_CLEAR(gen->gi_code); + Py_CLEAR(gen->gi_frame); + Py_CLEAR(gen->gi_name); + Py_CLEAR(gen->gi_qualname); + Py_CLEAR(gen->gi_modulename); + return 0; +} +static void __Pyx_Coroutine_dealloc(PyObject *self) { + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; + PyObject_GC_UnTrack(gen); + if (gen->gi_weakreflist != NULL) + PyObject_ClearWeakRefs(self); + if (gen->resume_label >= 0) { + PyObject_GC_Track(self); +#if PY_VERSION_HEX >= 0x030400a1 && CYTHON_USE_TP_FINALIZE + if (unlikely(PyObject_CallFinalizerFromDealloc(self))) +#else + Py_TYPE(gen)->tp_del(self); + if (unlikely(Py_REFCNT(self) > 0)) +#endif + { + return; + } + PyObject_GC_UnTrack(self); + } +#ifdef __Pyx_AsyncGen_USED + if (__Pyx_AsyncGen_CheckExact(self)) { + /* We have to handle this case for asynchronous generators + right here, because this code has to be between UNTRACK + and GC_Del. */ + Py_CLEAR(((__pyx_PyAsyncGenObject*)self)->ag_finalizer); + } +#endif + __Pyx_Coroutine_clear(self); + __Pyx_PyHeapTypeObject_GC_Del(gen); +} +static void __Pyx_Coroutine_del(PyObject *self) { + PyObject *error_type, *error_value, *error_traceback; + __pyx_CoroutineObject *gen = (__pyx_CoroutineObject *) self; + __Pyx_PyThreadState_declare + if (gen->resume_label < 0) { + return; + } +#if !CYTHON_USE_TP_FINALIZE + assert(self->ob_refcnt == 0); + __Pyx_SET_REFCNT(self, 1); +#endif + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&error_type, &error_value, &error_traceback); +#ifdef __Pyx_AsyncGen_USED + if (__Pyx_AsyncGen_CheckExact(self)) { + __pyx_PyAsyncGenObject *agen = (__pyx_PyAsyncGenObject*)self; + PyObject *finalizer = agen->ag_finalizer; + if (finalizer && !agen->ag_closed) { + PyObject *res = __Pyx_PyObject_CallOneArg(finalizer, self); + if (unlikely(!res)) { + PyErr_WriteUnraisable(self); + } else { + Py_DECREF(res); + } + __Pyx_ErrRestore(error_type, error_value, error_traceback); + return; + } + } +#endif + if (unlikely(gen->resume_label == 0 && !error_value)) { +#ifdef __Pyx_Coroutine_USED +#ifdef __Pyx_Generator_USED + if (!__Pyx_Generator_CheckExact(self)) +#endif + { + PyObject_GC_UnTrack(self); +#if PY_MAJOR_VERSION >= 3 || defined(PyErr_WarnFormat) + if (unlikely(PyErr_WarnFormat(PyExc_RuntimeWarning, 1, "coroutine '%.50S' was never awaited", gen->gi_qualname) < 0)) + PyErr_WriteUnraisable(self); +#else + {PyObject *msg; + char *cmsg; + #if CYTHON_COMPILING_IN_PYPY + msg = NULL; + cmsg = (char*) "coroutine was never awaited"; + #else + char *cname; + PyObject *qualname; + qualname = gen->gi_qualname; + cname = PyString_AS_STRING(qualname); + msg = PyString_FromFormat("coroutine '%.50s' was never awaited", cname); + if (unlikely(!msg)) { + PyErr_Clear(); + cmsg = (char*) "coroutine was never awaited"; + } else { + cmsg = PyString_AS_STRING(msg); + } + #endif + if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, cmsg, 1) < 0)) + PyErr_WriteUnraisable(self); + Py_XDECREF(msg);} +#endif + PyObject_GC_Track(self); + } +#endif + } else { + PyObject *res = __Pyx_Coroutine_Close(self); + if (unlikely(!res)) { + if (PyErr_Occurred()) + PyErr_WriteUnraisable(self); + } else { + Py_DECREF(res); + } + } + __Pyx_ErrRestore(error_type, error_value, error_traceback); +#if !CYTHON_USE_TP_FINALIZE + assert(Py_REFCNT(self) > 0); + if (likely(--self->ob_refcnt == 0)) { + return; + } + { + Py_ssize_t refcnt = Py_REFCNT(self); + _Py_NewReference(self); + __Pyx_SET_REFCNT(self, refcnt); + } +#if CYTHON_COMPILING_IN_CPYTHON + assert(PyType_IS_GC(Py_TYPE(self)) && + _Py_AS_GC(self)->gc.gc_refs != _PyGC_REFS_UNTRACKED); + _Py_DEC_REFTOTAL; +#endif +#ifdef COUNT_ALLOCS + --Py_TYPE(self)->tp_frees; + --Py_TYPE(self)->tp_allocs; +#endif +#endif +} +static PyObject * +__Pyx_Coroutine_get_name(__pyx_CoroutineObject *self, void *context) +{ + PyObject *name = self->gi_name; + CYTHON_UNUSED_VAR(context); + if (unlikely(!name)) name = Py_None; + Py_INCREF(name); + return name; +} +static int +__Pyx_Coroutine_set_name(__pyx_CoroutineObject *self, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) +#else + if (unlikely(value == NULL || !PyString_Check(value))) +#endif + { + PyErr_SetString(PyExc_TypeError, + "__name__ must be set to a string object"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(self->gi_name, value); + return 0; +} +static PyObject * +__Pyx_Coroutine_get_qualname(__pyx_CoroutineObject *self, void *context) +{ + PyObject *name = self->gi_qualname; + CYTHON_UNUSED_VAR(context); + if (unlikely(!name)) name = Py_None; + Py_INCREF(name); + return name; +} +static int +__Pyx_Coroutine_set_qualname(__pyx_CoroutineObject *self, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) +#else + if (unlikely(value == NULL || !PyString_Check(value))) +#endif + { + PyErr_SetString(PyExc_TypeError, + "__qualname__ must be set to a string object"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(self->gi_qualname, value); + return 0; +} +static PyObject * +__Pyx_Coroutine_get_frame(__pyx_CoroutineObject *self, void *context) +{ + PyObject *frame = self->gi_frame; + CYTHON_UNUSED_VAR(context); + if (!frame) { + if (unlikely(!self->gi_code)) { + Py_RETURN_NONE; + } + frame = (PyObject *) PyFrame_New( + PyThreadState_Get(), /*PyThreadState *tstate,*/ + (PyCodeObject*) self->gi_code, /*PyCodeObject *code,*/ + __pyx_d, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (unlikely(!frame)) + return NULL; + self->gi_frame = frame; + } + Py_INCREF(frame); + return frame; +} +static __pyx_CoroutineObject *__Pyx__Coroutine_New( + PyTypeObject* type, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, + PyObject *name, PyObject *qualname, PyObject *module_name) { + __pyx_CoroutineObject *gen = PyObject_GC_New(__pyx_CoroutineObject, type); + if (unlikely(!gen)) + return NULL; + return __Pyx__Coroutine_NewInit(gen, body, code, closure, name, qualname, module_name); +} +static __pyx_CoroutineObject *__Pyx__Coroutine_NewInit( + __pyx_CoroutineObject *gen, __pyx_coroutine_body_t body, PyObject *code, PyObject *closure, + PyObject *name, PyObject *qualname, PyObject *module_name) { + gen->body = body; + gen->closure = closure; + Py_XINCREF(closure); + gen->is_running = 0; + gen->resume_label = 0; + gen->classobj = NULL; + gen->yieldfrom = NULL; + #if PY_VERSION_HEX >= 0x030B00a4 + gen->gi_exc_state.exc_value = NULL; + #else + gen->gi_exc_state.exc_type = NULL; + gen->gi_exc_state.exc_value = NULL; + gen->gi_exc_state.exc_traceback = NULL; + #endif +#if CYTHON_USE_EXC_INFO_STACK + gen->gi_exc_state.previous_item = NULL; +#endif + gen->gi_weakreflist = NULL; + Py_XINCREF(qualname); + gen->gi_qualname = qualname; + Py_XINCREF(name); + gen->gi_name = name; + Py_XINCREF(module_name); + gen->gi_modulename = module_name; + Py_XINCREF(code); + gen->gi_code = code; + gen->gi_frame = NULL; + PyObject_GC_Track(gen); + return gen; +} + +/* PyObject_GenericGetAttrNoDict */ +#if CYTHON_USE_TYPE_SLOTS && CYTHON_USE_PYTYPE_LOOKUP && PY_VERSION_HEX < 0x03070000 +static PyObject *__Pyx_RaiseGenericGetAttributeError(PyTypeObject *tp, PyObject *attr_name) { + __Pyx_TypeName type_name = __Pyx_PyType_GetName(tp); + PyErr_Format(PyExc_AttributeError, +#if PY_MAJOR_VERSION >= 3 + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%U'", + type_name, attr_name); +#else + "'" __Pyx_FMT_TYPENAME "' object has no attribute '%.400s'", + type_name, PyString_AS_STRING(attr_name)); +#endif + __Pyx_DECREF_TypeName(type_name); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyObject_GenericGetAttrNoDict(PyObject* obj, PyObject* attr_name) { + PyObject *descr; + PyTypeObject *tp = Py_TYPE(obj); + if (unlikely(!PyString_Check(attr_name))) { + return PyObject_GenericGetAttr(obj, attr_name); + } + assert(!tp->tp_dictoffset); + descr = _PyType_Lookup(tp, attr_name); + if (unlikely(!descr)) { + return __Pyx_RaiseGenericGetAttributeError(tp, attr_name); + } + Py_INCREF(descr); + #if PY_MAJOR_VERSION < 3 + if (likely(PyType_HasFeature(Py_TYPE(descr), Py_TPFLAGS_HAVE_CLASS))) + #endif + { + descrgetfunc f = Py_TYPE(descr)->tp_descr_get; + if (unlikely(f)) { + PyObject *res = f(descr, obj, (PyObject *)tp); + Py_DECREF(descr); + return res; + } + } + return descr; +} +#endif + +/* PatchModuleWithCoroutine */ +static PyObject* __Pyx_Coroutine_patch_module(PyObject* module, const char* py_code) { +#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + int result; + PyObject *globals, *result_obj; + globals = PyDict_New(); if (unlikely(!globals)) goto ignore; + result = PyDict_SetItemString(globals, "_cython_coroutine_type", + #ifdef __Pyx_Coroutine_USED + (PyObject*)__pyx_CoroutineType); + #else + Py_None); + #endif + if (unlikely(result < 0)) goto ignore; + result = PyDict_SetItemString(globals, "_cython_generator_type", + #ifdef __Pyx_Generator_USED + (PyObject*)__pyx_GeneratorType); + #else + Py_None); + #endif + if (unlikely(result < 0)) goto ignore; + if (unlikely(PyDict_SetItemString(globals, "_module", module) < 0)) goto ignore; + if (unlikely(PyDict_SetItemString(globals, "__builtins__", __pyx_b) < 0)) goto ignore; + result_obj = PyRun_String(py_code, Py_file_input, globals, globals); + if (unlikely(!result_obj)) goto ignore; + Py_DECREF(result_obj); + Py_DECREF(globals); + return module; +ignore: + Py_XDECREF(globals); + PyErr_WriteUnraisable(module); + if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, "Cython module failed to patch module with custom type", 1) < 0)) { + Py_DECREF(module); + module = NULL; + } +#else + py_code++; +#endif + return module; +} + +/* PatchGeneratorABC */ +#ifndef CYTHON_REGISTER_ABCS +#define CYTHON_REGISTER_ABCS 1 +#endif +#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) +static PyObject* __Pyx_patch_abc_module(PyObject *module); +static PyObject* __Pyx_patch_abc_module(PyObject *module) { + module = __Pyx_Coroutine_patch_module( + module, "" +"if _cython_generator_type is not None:\n" +" try: Generator = _module.Generator\n" +" except AttributeError: pass\n" +" else: Generator.register(_cython_generator_type)\n" +"if _cython_coroutine_type is not None:\n" +" try: Coroutine = _module.Coroutine\n" +" except AttributeError: pass\n" +" else: Coroutine.register(_cython_coroutine_type)\n" + ); + return module; +} +#endif +static int __Pyx_patch_abc(void) { +#if defined(__Pyx_Generator_USED) || defined(__Pyx_Coroutine_USED) + static int abc_patched = 0; + if (CYTHON_REGISTER_ABCS && !abc_patched) { + PyObject *module; + module = PyImport_ImportModule((PY_MAJOR_VERSION >= 3) ? "collections.abc" : "collections"); + if (unlikely(!module)) { + PyErr_WriteUnraisable(NULL); + if (unlikely(PyErr_WarnEx(PyExc_RuntimeWarning, + ((PY_MAJOR_VERSION >= 3) ? + "Cython module failed to register with collections.abc module" : + "Cython module failed to register with collections module"), 1) < 0)) { + return -1; + } + } else { + module = __Pyx_patch_abc_module(module); + abc_patched = 1; + if (unlikely(!module)) + return -1; + Py_DECREF(module); + } + module = PyImport_ImportModule("backports_abc"); + if (module) { + module = __Pyx_patch_abc_module(module); + Py_XDECREF(module); + } + if (!module) { + PyErr_Clear(); + } + } +#else + if ((0)) __Pyx_Coroutine_patch_module(NULL, NULL); +#endif + return 0; +} + +/* Coroutine */ +static void __Pyx_CoroutineAwait_dealloc(PyObject *self) { + PyObject_GC_UnTrack(self); + Py_CLEAR(((__pyx_CoroutineAwaitObject*)self)->coroutine); + __Pyx_PyHeapTypeObject_GC_Del(self); +} +static int __Pyx_CoroutineAwait_traverse(__pyx_CoroutineAwaitObject *self, visitproc visit, void *arg) { + Py_VISIT(self->coroutine); + return 0; +} +static int __Pyx_CoroutineAwait_clear(__pyx_CoroutineAwaitObject *self) { + Py_CLEAR(self->coroutine); + return 0; +} +static PyObject *__Pyx_CoroutineAwait_Next(__pyx_CoroutineAwaitObject *self) { + return __Pyx_Generator_Next(self->coroutine); +} +static PyObject *__Pyx_CoroutineAwait_Send(__pyx_CoroutineAwaitObject *self, PyObject *value) { + return __Pyx_Coroutine_Send(self->coroutine, value); +} +static PyObject *__Pyx_CoroutineAwait_Throw(__pyx_CoroutineAwaitObject *self, PyObject *args) { + return __Pyx_Coroutine_Throw(self->coroutine, args); +} +static PyObject *__Pyx_CoroutineAwait_Close(__pyx_CoroutineAwaitObject *self, PyObject *arg) { + CYTHON_UNUSED_VAR(arg); + return __Pyx_Coroutine_Close(self->coroutine); +} +static PyObject *__Pyx_CoroutineAwait_self(PyObject *self) { + Py_INCREF(self); + return self; +} +#if !CYTHON_COMPILING_IN_PYPY +static PyObject *__Pyx_CoroutineAwait_no_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) { + CYTHON_UNUSED_VAR(type); + CYTHON_UNUSED_VAR(args); + CYTHON_UNUSED_VAR(kwargs); + PyErr_SetString(PyExc_TypeError, "cannot instantiate type, use 'await coroutine' instead"); + return NULL; +} +#endif +static PyObject *__Pyx_CoroutineAwait_reduce_ex(__pyx_CoroutineAwaitObject *self, PyObject *arg) { + CYTHON_UNUSED_VAR(arg); + PyErr_Format(PyExc_TypeError, "cannot pickle '%.200s' object", + Py_TYPE(self)->tp_name); + return NULL; +} +static PyMethodDef __pyx_CoroutineAwait_methods[] = { + {"send", (PyCFunction) __Pyx_CoroutineAwait_Send, METH_O, + (char*) PyDoc_STR("send(arg) -> send 'arg' into coroutine,\nreturn next yielded value or raise StopIteration.")}, + {"throw", (PyCFunction) __Pyx_CoroutineAwait_Throw, METH_VARARGS, + (char*) PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in coroutine,\nreturn next yielded value or raise StopIteration.")}, + {"close", (PyCFunction) __Pyx_CoroutineAwait_Close, METH_NOARGS, + (char*) PyDoc_STR("close() -> raise GeneratorExit inside coroutine.")}, + {"__reduce_ex__", (PyCFunction) __Pyx_CoroutineAwait_reduce_ex, METH_O, 0}, + {"__reduce__", (PyCFunction) __Pyx_CoroutineAwait_reduce_ex, METH_NOARGS, 0}, + {0, 0, 0, 0} +}; +#if CYTHON_USE_TYPE_SPECS +static PyType_Slot __pyx_CoroutineAwaitType_slots[] = { + {Py_tp_dealloc, (void *)__Pyx_CoroutineAwait_dealloc}, + {Py_tp_traverse, (void *)__Pyx_CoroutineAwait_traverse}, + {Py_tp_clear, (void *)__Pyx_CoroutineAwait_clear}, +#if !CYTHON_COMPILING_IN_PYPY + {Py_tp_new, (void *)__Pyx_CoroutineAwait_no_new}, +#endif + {Py_tp_methods, (void *)__pyx_CoroutineAwait_methods}, + {Py_tp_iter, (void *)__Pyx_CoroutineAwait_self}, + {Py_tp_iternext, (void *)__Pyx_CoroutineAwait_Next}, + {0, 0}, +}; +static PyType_Spec __pyx_CoroutineAwaitType_spec = { + __PYX_TYPE_MODULE_PREFIX "coroutine_wrapper", + sizeof(__pyx_CoroutineAwaitObject), + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, + __pyx_CoroutineAwaitType_slots +}; +#else +static PyTypeObject __pyx_CoroutineAwaitType_type = { + PyVarObject_HEAD_INIT(0, 0) + __PYX_TYPE_MODULE_PREFIX "coroutine_wrapper", + sizeof(__pyx_CoroutineAwaitObject), + 0, + (destructor) __Pyx_CoroutineAwait_dealloc, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, + PyDoc_STR("A wrapper object implementing __await__ for coroutines."), + (traverseproc) __Pyx_CoroutineAwait_traverse, + (inquiry) __Pyx_CoroutineAwait_clear, + 0, + 0, + __Pyx_CoroutineAwait_self, + (iternextfunc) __Pyx_CoroutineAwait_Next, + __pyx_CoroutineAwait_methods, + 0 , + 0 , + 0, + 0, + 0, + 0, + 0, + 0, + 0, +#if !CYTHON_COMPILING_IN_PYPY + __Pyx_CoroutineAwait_no_new, +#else + 0, +#endif + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +#if PY_VERSION_HEX >= 0x030400a1 + 0, +#endif +#if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) + 0, +#endif +#if __PYX_NEED_TP_PRINT_SLOT + 0, +#endif +#if PY_VERSION_HEX >= 0x030C0000 + 0, +#endif +#if PY_VERSION_HEX >= 0x030d00A4 + 0, +#endif +#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 + 0, +#endif +}; +#endif +#if PY_VERSION_HEX < 0x030500B1 || defined(__Pyx_IterableCoroutine_USED) || CYTHON_USE_ASYNC_SLOTS +static CYTHON_INLINE PyObject *__Pyx__Coroutine_await(PyObject *coroutine) { + __pyx_CoroutineAwaitObject *await = PyObject_GC_New(__pyx_CoroutineAwaitObject, __pyx_CoroutineAwaitType); + if (unlikely(!await)) return NULL; + Py_INCREF(coroutine); + await->coroutine = coroutine; + PyObject_GC_Track(await); + return (PyObject*)await; +} +#endif +#if PY_VERSION_HEX < 0x030500B1 +static PyObject *__Pyx_Coroutine_await_method(PyObject *coroutine, PyObject *arg) { + CYTHON_UNUSED_VAR(arg); + return __Pyx__Coroutine_await(coroutine); +} +#endif +#if defined(__Pyx_IterableCoroutine_USED) || CYTHON_USE_ASYNC_SLOTS +static PyObject *__Pyx_Coroutine_await(PyObject *coroutine) { + if (unlikely(!coroutine || !__Pyx_Coroutine_Check(coroutine))) { + PyErr_SetString(PyExc_TypeError, "invalid input, expected coroutine"); + return NULL; + } + return __Pyx__Coroutine_await(coroutine); +} +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 && PY_VERSION_HEX < 0x030500B1 +static PyObject *__Pyx_Coroutine_compare(PyObject *obj, PyObject *other, int op) { + PyObject* result; + switch (op) { + case Py_EQ: result = (other == obj) ? Py_True : Py_False; break; + case Py_NE: result = (other != obj) ? Py_True : Py_False; break; + default: + result = Py_NotImplemented; + } + Py_INCREF(result); + return result; +} +#endif +static PyMethodDef __pyx_Coroutine_methods[] = { + {"send", (PyCFunction) __Pyx_Coroutine_Send, METH_O, + (char*) PyDoc_STR("send(arg) -> send 'arg' into coroutine,\nreturn next iterated value or raise StopIteration.")}, + {"throw", (PyCFunction) __Pyx_Coroutine_Throw, METH_VARARGS, + (char*) PyDoc_STR("throw(typ[,val[,tb]]) -> raise exception in coroutine,\nreturn next iterated value or raise StopIteration.")}, + {"close", (PyCFunction) __Pyx_Coroutine_Close_Method, METH_NOARGS, + (char*) PyDoc_STR("close() -> raise GeneratorExit inside coroutine.")}, +#if PY_VERSION_HEX < 0x030500B1 + {"__await__", (PyCFunction) __Pyx_Coroutine_await_method, METH_NOARGS, + (char*) PyDoc_STR("__await__() -> return an iterator to be used in await expression.")}, +#endif + {0, 0, 0, 0} +}; +static PyMemberDef __pyx_Coroutine_memberlist[] = { + {(char *) "cr_running", T_BOOL, offsetof(__pyx_CoroutineObject, is_running), READONLY, NULL}, + {(char*) "cr_await", T_OBJECT, offsetof(__pyx_CoroutineObject, yieldfrom), READONLY, + (char*) PyDoc_STR("object being awaited, or None")}, + {(char*) "cr_code", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_code), READONLY, NULL}, + {(char *) "__module__", T_OBJECT, offsetof(__pyx_CoroutineObject, gi_modulename), 0, 0}, +#if CYTHON_USE_TYPE_SPECS + {(char *) "__weaklistoffset__", T_PYSSIZET, offsetof(__pyx_CoroutineObject, gi_weakreflist), READONLY, 0}, +#endif + {0, 0, 0, 0, 0} +}; +static PyGetSetDef __pyx_Coroutine_getsets[] = { + {(char *) "__name__", (getter)__Pyx_Coroutine_get_name, (setter)__Pyx_Coroutine_set_name, + (char*) PyDoc_STR("name of the coroutine"), 0}, + {(char *) "__qualname__", (getter)__Pyx_Coroutine_get_qualname, (setter)__Pyx_Coroutine_set_qualname, + (char*) PyDoc_STR("qualified name of the coroutine"), 0}, + {(char *) "cr_frame", (getter)__Pyx_Coroutine_get_frame, NULL, + (char*) PyDoc_STR("Frame of the coroutine"), 0}, + {0, 0, 0, 0, 0} +}; +#if CYTHON_USE_TYPE_SPECS +static PyType_Slot __pyx_CoroutineType_slots[] = { + {Py_tp_dealloc, (void *)__Pyx_Coroutine_dealloc}, + {Py_am_await, (void *)&__Pyx_Coroutine_await}, + {Py_tp_traverse, (void *)__Pyx_Coroutine_traverse}, + {Py_tp_methods, (void *)__pyx_Coroutine_methods}, + {Py_tp_members, (void *)__pyx_Coroutine_memberlist}, + {Py_tp_getset, (void *)__pyx_Coroutine_getsets}, + {Py_tp_getattro, (void *) __Pyx_PyObject_GenericGetAttrNoDict}, +#if CYTHON_USE_TP_FINALIZE + {Py_tp_finalize, (void *)__Pyx_Coroutine_del}, +#endif + {0, 0}, +}; +static PyType_Spec __pyx_CoroutineType_spec = { + __PYX_TYPE_MODULE_PREFIX "coroutine", + sizeof(__pyx_CoroutineObject), + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE, + __pyx_CoroutineType_slots +}; +#else +#if CYTHON_USE_ASYNC_SLOTS +static __Pyx_PyAsyncMethodsStruct __pyx_Coroutine_as_async = { + __Pyx_Coroutine_await, + 0, + 0, +#if PY_VERSION_HEX >= 0x030A00A3 + 0, +#endif +}; +#endif +static PyTypeObject __pyx_CoroutineType_type = { + PyVarObject_HEAD_INIT(0, 0) + __PYX_TYPE_MODULE_PREFIX "coroutine", + sizeof(__pyx_CoroutineObject), + 0, + (destructor) __Pyx_Coroutine_dealloc, + 0, + 0, + 0, +#if CYTHON_USE_ASYNC_SLOTS + &__pyx_Coroutine_as_async, +#else + 0, +#endif + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_HAVE_FINALIZE, + 0, + (traverseproc) __Pyx_Coroutine_traverse, + 0, +#if CYTHON_USE_ASYNC_SLOTS && CYTHON_COMPILING_IN_CPYTHON && PY_MAJOR_VERSION >= 3 && PY_VERSION_HEX < 0x030500B1 + __Pyx_Coroutine_compare, +#else + 0, +#endif + offsetof(__pyx_CoroutineObject, gi_weakreflist), + 0, + 0, + __pyx_Coroutine_methods, + __pyx_Coroutine_memberlist, + __pyx_Coroutine_getsets, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +#if CYTHON_USE_TP_FINALIZE + 0, +#else + __Pyx_Coroutine_del, +#endif + 0, +#if CYTHON_USE_TP_FINALIZE + __Pyx_Coroutine_del, +#elif PY_VERSION_HEX >= 0x030400a1 + 0, +#endif +#if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) + 0, +#endif +#if __PYX_NEED_TP_PRINT_SLOT + 0, +#endif +#if PY_VERSION_HEX >= 0x030C0000 + 0, +#endif +#if PY_VERSION_HEX >= 0x030d00A4 + 0, +#endif +#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 + 0, +#endif +}; +#endif +static int __pyx_Coroutine_init(PyObject *module) { + CYTHON_MAYBE_UNUSED_VAR(module); +#if CYTHON_USE_TYPE_SPECS + __pyx_CoroutineType = __Pyx_FetchCommonTypeFromSpec(module, &__pyx_CoroutineType_spec, NULL); +#else + __pyx_CoroutineType_type.tp_getattro = __Pyx_PyObject_GenericGetAttrNoDict; + __pyx_CoroutineType = __Pyx_FetchCommonType(&__pyx_CoroutineType_type); +#endif + if (unlikely(!__pyx_CoroutineType)) + return -1; +#ifdef __Pyx_IterableCoroutine_USED + if (unlikely(__pyx_IterableCoroutine_init(module) == -1)) + return -1; +#endif +#if CYTHON_USE_TYPE_SPECS + __pyx_CoroutineAwaitType = __Pyx_FetchCommonTypeFromSpec(module, &__pyx_CoroutineAwaitType_spec, NULL); +#else + __pyx_CoroutineAwaitType = __Pyx_FetchCommonType(&__pyx_CoroutineAwaitType_type); +#endif + if (unlikely(!__pyx_CoroutineAwaitType)) + return -1; + return 0; +} + +/* GetAwaitIter */ +static CYTHON_INLINE PyObject *__Pyx_Coroutine_GetAwaitableIter(PyObject *o) { +#ifdef __Pyx_Coroutine_USED + if (__Pyx_Coroutine_Check(o)) { + return __Pyx_NewRef(o); + } +#endif + return __Pyx__Coroutine_GetAwaitableIter(o); +} +static void __Pyx_Coroutine_AwaitableIterError(PyObject *source) { +#if PY_VERSION_HEX >= 0x030600B3 && PY_VERSION_HEX < 0x030d0000 || defined(_PyErr_FormatFromCause) + __Pyx_TypeName source_type_name = __Pyx_PyType_GetName(Py_TYPE(source)); + _PyErr_FormatFromCause(PyExc_TypeError, + "'async for' received an invalid object from __anext__: " __Pyx_FMT_TYPENAME, source_type_name); + __Pyx_DECREF_TypeName(source_type_name); +#elif PY_MAJOR_VERSION >= 3 + PyObject *exc, *val, *val2, *tb; + __Pyx_TypeName source_type_name = __Pyx_PyType_GetName(Py_TYPE(source)); + assert(PyErr_Occurred()); + PyErr_Fetch(&exc, &val, &tb); + PyErr_NormalizeException(&exc, &val, &tb); + if (tb != NULL) { + PyException_SetTraceback(val, tb); + Py_DECREF(tb); + } + Py_DECREF(exc); + assert(!PyErr_Occurred()); + PyErr_Format(PyExc_TypeError, + "'async for' received an invalid object from __anext__: " __Pyx_FMT_TYPENAME, source_type_name); + __Pyx_DECREF_TypeName(source_type_name); + PyErr_Fetch(&exc, &val2, &tb); + PyErr_NormalizeException(&exc, &val2, &tb); + Py_INCREF(val); + PyException_SetCause(val2, val); + PyException_SetContext(val2, val); + PyErr_Restore(exc, val2, tb); +#else + CYTHON_UNUSED_VAR(source); +#endif +} +static PyObject *__Pyx__Coroutine_GetAwaitableIter(PyObject *obj) { + PyObject *res; +#if CYTHON_USE_ASYNC_SLOTS + __Pyx_PyAsyncMethodsStruct* am = __Pyx_PyType_AsAsync(obj); + if (likely(am && am->am_await)) { + res = (*am->am_await)(obj); + } else +#endif +#if PY_VERSION_HEX >= 0x030500B2 || defined(PyCoro_CheckExact) + if (PyCoro_CheckExact(obj)) { + return __Pyx_NewRef(obj); + } else +#endif +#if CYTHON_COMPILING_IN_CPYTHON && defined(CO_ITERABLE_COROUTINE) +#if PY_VERSION_HEX >= 0x030C00A6 + if (PyGen_CheckExact(obj) && (PyGen_GetCode((PyGenObject*)obj)->co_flags & CO_ITERABLE_COROUTINE)) { +#else + if (PyGen_CheckExact(obj) && ((PyGenObject*)obj)->gi_code && ((PyCodeObject *)((PyGenObject*)obj)->gi_code)->co_flags & CO_ITERABLE_COROUTINE) { +#endif + return __Pyx_NewRef(obj); + } else +#endif + { + PyObject *method = NULL; + int is_method = __Pyx_PyObject_GetMethod(obj, __pyx_n_s_await, &method); + if (likely(is_method)) { + res = __Pyx_PyObject_CallOneArg(method, obj); + } else if (likely(method)) { + res = __Pyx_PyObject_CallNoArg(method); + } else + goto slot_error; + Py_DECREF(method); + } + if (unlikely(!res)) { + __Pyx_Coroutine_AwaitableIterError(obj); + goto bad; + } + if (unlikely(!PyIter_Check(res))) { + __Pyx_TypeName res_type_name = __Pyx_PyType_GetName(Py_TYPE(res)); + PyErr_Format(PyExc_TypeError, + "__await__() returned non-iterator of type '" __Pyx_FMT_TYPENAME "'", res_type_name); + __Pyx_DECREF_TypeName(res_type_name); + Py_CLEAR(res); + } else { + int is_coroutine = 0; + #ifdef __Pyx_Coroutine_USED + is_coroutine |= __Pyx_Coroutine_Check(res); + #endif + #if PY_VERSION_HEX >= 0x030500B2 || defined(PyCoro_CheckExact) + is_coroutine |= PyCoro_CheckExact(res); + #endif + if (unlikely(is_coroutine)) { + /* __await__ must return an *iterator*, not + a coroutine or another awaitable (see PEP 492) */ + PyErr_SetString(PyExc_TypeError, + "__await__() returned a coroutine"); + Py_CLEAR(res); + } + } + return res; +slot_error: + { + __Pyx_TypeName obj_type_name = __Pyx_PyType_GetName(Py_TYPE(obj)); + PyErr_Format(PyExc_TypeError, + "object " __Pyx_FMT_TYPENAME " can't be used in 'await' expression", obj_type_name); + __Pyx_DECREF_TypeName(obj_type_name); + } +bad: + return NULL; +} + +/* CoroutineYieldFrom */ + static PyObject* __Pyx__Coroutine_Yield_From_Generic(__pyx_CoroutineObject *gen, PyObject *source) { + PyObject *retval; + PyObject *source_gen = __Pyx__Coroutine_GetAwaitableIter(source); + if (unlikely(!source_gen)) { + return NULL; + } + if (__Pyx_Coroutine_Check(source_gen)) { + retval = __Pyx_Generator_Next(source_gen); + } else { + retval = __Pyx_PyObject_GetIterNextFunc(source_gen)(source_gen); + } + if (retval) { + gen->yieldfrom = source_gen; + return retval; + } + Py_DECREF(source_gen); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_Coroutine_Yield_From(__pyx_CoroutineObject *gen, PyObject *source) { + PyObject *retval; + if (__Pyx_Coroutine_Check(source)) { + if (unlikely(((__pyx_CoroutineObject*)source)->yieldfrom)) { + PyErr_SetString( + PyExc_RuntimeError, + "coroutine is being awaited already"); + return NULL; + } + retval = __Pyx_Generator_Next(source); +#ifdef __Pyx_AsyncGen_USED + } else if (__pyx_PyAsyncGenASend_CheckExact(source)) { + retval = __Pyx_async_gen_asend_iternext(source); +#endif + } else { + return __Pyx__Coroutine_Yield_From_Generic(gen, source); + } + if (retval) { + Py_INCREF(source); + gen->yieldfrom = source; + } + return retval; +} + +/* ReturnWithStopIteration */ + static void __Pyx__ReturnWithStopIteration(PyObject* value) { + PyObject *exc, *args; +#if CYTHON_COMPILING_IN_CPYTHON + __Pyx_PyThreadState_declare + if (PY_VERSION_HEX >= 0x030C00A6 + || unlikely(PyTuple_Check(value) || PyExceptionInstance_Check(value))) { + args = PyTuple_New(1); + if (unlikely(!args)) return; + Py_INCREF(value); + PyTuple_SET_ITEM(args, 0, value); + exc = PyType_Type.tp_call(PyExc_StopIteration, args, NULL); + Py_DECREF(args); + if (!exc) return; + } else { + Py_INCREF(value); + exc = value; + } + #if CYTHON_FAST_THREAD_STATE + __Pyx_PyThreadState_assign + #if CYTHON_USE_EXC_INFO_STACK + if (!__pyx_tstate->exc_info->exc_value) + #else + if (!__pyx_tstate->exc_type) + #endif + { + Py_INCREF(PyExc_StopIteration); + __Pyx_ErrRestore(PyExc_StopIteration, exc, NULL); + return; + } + #endif +#else + args = PyTuple_Pack(1, value); + if (unlikely(!args)) return; + exc = PyObject_Call(PyExc_StopIteration, args, NULL); + Py_DECREF(args); + if (unlikely(!exc)) return; +#endif + PyErr_SetObject(PyExc_StopIteration, exc); + Py_DECREF(exc); +} + +/* pep479 */ + static void __Pyx_Generator_Replace_StopIteration(int in_async_gen) { + PyObject *exc, *val, *tb, *cur_exc; + __Pyx_PyThreadState_declare + #ifdef __Pyx_StopAsyncIteration_USED + int is_async_stopiteration = 0; + #endif + CYTHON_MAYBE_UNUSED_VAR(in_async_gen); + cur_exc = PyErr_Occurred(); + if (likely(!__Pyx_PyErr_GivenExceptionMatches(cur_exc, PyExc_StopIteration))) { + #ifdef __Pyx_StopAsyncIteration_USED + if (in_async_gen && unlikely(__Pyx_PyErr_GivenExceptionMatches(cur_exc, __Pyx_PyExc_StopAsyncIteration))) { + is_async_stopiteration = 1; + } else + #endif + return; + } + __Pyx_PyThreadState_assign + __Pyx_GetException(&exc, &val, &tb); + Py_XDECREF(exc); + Py_XDECREF(val); + Py_XDECREF(tb); + PyErr_SetString(PyExc_RuntimeError, + #ifdef __Pyx_StopAsyncIteration_USED + is_async_stopiteration ? "async generator raised StopAsyncIteration" : + in_async_gen ? "async generator raised StopIteration" : + #endif + "generator raised StopIteration"); +} + +/* PyObjectCallMethod0 */ + static PyObject* __Pyx_PyObject_CallMethod0(PyObject* obj, PyObject* method_name) { + PyObject *method = NULL, *result = NULL; + int is_method = __Pyx_PyObject_GetMethod(obj, method_name, &method); + if (likely(is_method)) { + result = __Pyx_PyObject_CallOneArg(method, obj); + Py_DECREF(method); + return result; + } + if (unlikely(!method)) goto bad; + result = __Pyx_PyObject_CallNoArg(method); + Py_DECREF(method); +bad: + return result; +} + +/* ValidateBasesTuple */ + #if CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API || CYTHON_USE_TYPE_SPECS +static int __Pyx_validate_bases_tuple(const char *type_name, Py_ssize_t dictoffset, PyObject *bases) { + Py_ssize_t i, n; +#if CYTHON_ASSUME_SAFE_MACROS + n = PyTuple_GET_SIZE(bases); +#else + n = PyTuple_Size(bases); + if (n < 0) return -1; +#endif + for (i = 1; i < n; i++) + { +#if CYTHON_AVOID_BORROWED_REFS + PyObject *b0 = PySequence_GetItem(bases, i); + if (!b0) return -1; +#elif CYTHON_ASSUME_SAFE_MACROS + PyObject *b0 = PyTuple_GET_ITEM(bases, i); +#else + PyObject *b0 = PyTuple_GetItem(bases, i); + if (!b0) return -1; +#endif + PyTypeObject *b; +#if PY_MAJOR_VERSION < 3 + if (PyClass_Check(b0)) + { + PyErr_Format(PyExc_TypeError, "base class '%.200s' is an old-style class", + PyString_AS_STRING(((PyClassObject*)b0)->cl_name)); +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + return -1; + } +#endif + b = (PyTypeObject*) b0; + if (!__Pyx_PyType_HasFeature(b, Py_TPFLAGS_HEAPTYPE)) + { + __Pyx_TypeName b_name = __Pyx_PyType_GetName(b); + PyErr_Format(PyExc_TypeError, + "base class '" __Pyx_FMT_TYPENAME "' is not a heap type", b_name); + __Pyx_DECREF_TypeName(b_name); +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + return -1; + } + if (dictoffset == 0) + { + Py_ssize_t b_dictoffset = 0; +#if CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY + b_dictoffset = b->tp_dictoffset; +#else + PyObject *py_b_dictoffset = PyObject_GetAttrString((PyObject*)b, "__dictoffset__"); + if (!py_b_dictoffset) goto dictoffset_return; + b_dictoffset = PyLong_AsSsize_t(py_b_dictoffset); + Py_DECREF(py_b_dictoffset); + if (b_dictoffset == -1 && PyErr_Occurred()) goto dictoffset_return; +#endif + if (b_dictoffset) { + { + __Pyx_TypeName b_name = __Pyx_PyType_GetName(b); + PyErr_Format(PyExc_TypeError, + "extension type '%.200s' has no __dict__ slot, " + "but base type '" __Pyx_FMT_TYPENAME "' has: " + "either add 'cdef dict __dict__' to the extension type " + "or add '__slots__ = [...]' to the base type", + type_name, b_name); + __Pyx_DECREF_TypeName(b_name); + } +#if !(CYTHON_USE_TYPE_SLOTS || CYTHON_COMPILING_IN_PYPY) + dictoffset_return: +#endif +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + return -1; + } + } +#if CYTHON_AVOID_BORROWED_REFS + Py_DECREF(b0); +#endif + } + return 0; +} +#endif + +/* PyType_Ready */ + static int __Pyx_PyType_Ready(PyTypeObject *t) { +#if CYTHON_USE_TYPE_SPECS || !(CYTHON_COMPILING_IN_CPYTHON || CYTHON_COMPILING_IN_LIMITED_API) || defined(PYSTON_MAJOR_VERSION) + (void)__Pyx_PyObject_CallMethod0; +#if CYTHON_USE_TYPE_SPECS + (void)__Pyx_validate_bases_tuple; +#endif + return PyType_Ready(t); +#else + int r; + PyObject *bases = __Pyx_PyType_GetSlot(t, tp_bases, PyObject*); + if (bases && unlikely(__Pyx_validate_bases_tuple(t->tp_name, t->tp_dictoffset, bases) == -1)) + return -1; +#if PY_VERSION_HEX >= 0x03050000 && !defined(PYSTON_MAJOR_VERSION) + { + int gc_was_enabled; + #if PY_VERSION_HEX >= 0x030A00b1 + gc_was_enabled = PyGC_Disable(); + (void)__Pyx_PyObject_CallMethod0; + #else + PyObject *ret, *py_status; + PyObject *gc = NULL; + #if PY_VERSION_HEX >= 0x030700a1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM+0 >= 0x07030400) + gc = PyImport_GetModule(__pyx_kp_u_gc); + #endif + if (unlikely(!gc)) gc = PyImport_Import(__pyx_kp_u_gc); + if (unlikely(!gc)) return -1; + py_status = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_isenabled); + if (unlikely(!py_status)) { + Py_DECREF(gc); + return -1; + } + gc_was_enabled = __Pyx_PyObject_IsTrue(py_status); + Py_DECREF(py_status); + if (gc_was_enabled > 0) { + ret = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_disable); + if (unlikely(!ret)) { + Py_DECREF(gc); + return -1; + } + Py_DECREF(ret); + } else if (unlikely(gc_was_enabled == -1)) { + Py_DECREF(gc); + return -1; + } + #endif + t->tp_flags |= Py_TPFLAGS_HEAPTYPE; +#if PY_VERSION_HEX >= 0x030A0000 + t->tp_flags |= Py_TPFLAGS_IMMUTABLETYPE; +#endif +#else + (void)__Pyx_PyObject_CallMethod0; +#endif + r = PyType_Ready(t); +#if PY_VERSION_HEX >= 0x03050000 && !defined(PYSTON_MAJOR_VERSION) + t->tp_flags &= ~Py_TPFLAGS_HEAPTYPE; + #if PY_VERSION_HEX >= 0x030A00b1 + if (gc_was_enabled) + PyGC_Enable(); + #else + if (gc_was_enabled) { + PyObject *tp, *v, *tb; + PyErr_Fetch(&tp, &v, &tb); + ret = __Pyx_PyObject_CallMethod0(gc, __pyx_kp_u_enable); + if (likely(ret || r == -1)) { + Py_XDECREF(ret); + PyErr_Restore(tp, v, tb); + } else { + Py_XDECREF(tp); + Py_XDECREF(v); + Py_XDECREF(tb); + r = -1; + } + } + Py_DECREF(gc); + #endif + } +#endif + return r; +#endif +} + +/* Import */ + static PyObject *__Pyx_Import(PyObject *name, PyObject *from_list, int level) { + PyObject *module = 0; + PyObject *empty_dict = 0; + PyObject *empty_list = 0; + #if PY_MAJOR_VERSION < 3 + PyObject *py_import; + py_import = __Pyx_PyObject_GetAttrStr(__pyx_b, __pyx_n_s_import); + if (unlikely(!py_import)) + goto bad; + if (!from_list) { + empty_list = PyList_New(0); + if (unlikely(!empty_list)) + goto bad; + from_list = empty_list; + } + #endif + empty_dict = PyDict_New(); + if (unlikely(!empty_dict)) + goto bad; + { + #if PY_MAJOR_VERSION >= 3 + if (level == -1) { + if (strchr(__Pyx_MODULE_NAME, '.') != NULL) { + module = PyImport_ImportModuleLevelObject( + name, __pyx_d, empty_dict, from_list, 1); + if (unlikely(!module)) { + if (unlikely(!PyErr_ExceptionMatches(PyExc_ImportError))) + goto bad; + PyErr_Clear(); + } + } + level = 0; + } + #endif + if (!module) { + #if PY_MAJOR_VERSION < 3 + PyObject *py_level = PyInt_FromLong(level); + if (unlikely(!py_level)) + goto bad; + module = PyObject_CallFunctionObjArgs(py_import, + name, __pyx_d, empty_dict, from_list, py_level, (PyObject *)NULL); + Py_DECREF(py_level); + #else + module = PyImport_ImportModuleLevelObject( + name, __pyx_d, empty_dict, from_list, level); + #endif + } + } +bad: + Py_XDECREF(empty_dict); + Py_XDECREF(empty_list); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(py_import); + #endif + return module; +} + +/* ImportDottedModule */ + #if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx__ImportDottedModule_Error(PyObject *name, PyObject *parts_tuple, Py_ssize_t count) { + PyObject *partial_name = NULL, *slice = NULL, *sep = NULL; + if (unlikely(PyErr_Occurred())) { + PyErr_Clear(); + } + if (likely(PyTuple_GET_SIZE(parts_tuple) == count)) { + partial_name = name; + } else { + slice = PySequence_GetSlice(parts_tuple, 0, count); + if (unlikely(!slice)) + goto bad; + sep = PyUnicode_FromStringAndSize(".", 1); + if (unlikely(!sep)) + goto bad; + partial_name = PyUnicode_Join(sep, slice); + } + PyErr_Format( +#if PY_MAJOR_VERSION < 3 + PyExc_ImportError, + "No module named '%s'", PyString_AS_STRING(partial_name)); +#else +#if PY_VERSION_HEX >= 0x030600B1 + PyExc_ModuleNotFoundError, +#else + PyExc_ImportError, +#endif + "No module named '%U'", partial_name); +#endif +bad: + Py_XDECREF(sep); + Py_XDECREF(slice); + Py_XDECREF(partial_name); + return NULL; +} +#endif +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx__ImportDottedModule_Lookup(PyObject *name) { + PyObject *imported_module; +#if PY_VERSION_HEX < 0x030700A1 || (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM < 0x07030400) + PyObject *modules = PyImport_GetModuleDict(); + if (unlikely(!modules)) + return NULL; + imported_module = __Pyx_PyDict_GetItemStr(modules, name); + Py_XINCREF(imported_module); +#else + imported_module = PyImport_GetModule(name); +#endif + return imported_module; +} +#endif +#if PY_MAJOR_VERSION >= 3 +static PyObject *__Pyx_ImportDottedModule_WalkParts(PyObject *module, PyObject *name, PyObject *parts_tuple) { + Py_ssize_t i, nparts; + nparts = PyTuple_GET_SIZE(parts_tuple); + for (i=1; i < nparts && module; i++) { + PyObject *part, *submodule; +#if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + part = PyTuple_GET_ITEM(parts_tuple, i); +#else + part = PySequence_ITEM(parts_tuple, i); +#endif + submodule = __Pyx_PyObject_GetAttrStrNoError(module, part); +#if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) + Py_DECREF(part); +#endif + Py_DECREF(module); + module = submodule; + } + if (unlikely(!module)) { + return __Pyx__ImportDottedModule_Error(name, parts_tuple, i); + } + return module; +} +#endif +static PyObject *__Pyx__ImportDottedModule(PyObject *name, PyObject *parts_tuple) { +#if PY_MAJOR_VERSION < 3 + PyObject *module, *from_list, *star = __pyx_n_s__2; + CYTHON_UNUSED_VAR(parts_tuple); + from_list = PyList_New(1); + if (unlikely(!from_list)) + return NULL; + Py_INCREF(star); + PyList_SET_ITEM(from_list, 0, star); + module = __Pyx_Import(name, from_list, 0); + Py_DECREF(from_list); + return module; +#else + PyObject *imported_module; + PyObject *module = __Pyx_Import(name, NULL, 0); + if (!parts_tuple || unlikely(!module)) + return module; + imported_module = __Pyx__ImportDottedModule_Lookup(name); + if (likely(imported_module)) { + Py_DECREF(module); + return imported_module; + } + PyErr_Clear(); + return __Pyx_ImportDottedModule_WalkParts(module, name, parts_tuple); +#endif +} +static PyObject *__Pyx_ImportDottedModule(PyObject *name, PyObject *parts_tuple) { +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX >= 0x030400B1 + PyObject *module = __Pyx__ImportDottedModule_Lookup(name); + if (likely(module)) { + PyObject *spec = __Pyx_PyObject_GetAttrStrNoError(module, __pyx_n_s_spec); + if (likely(spec)) { + PyObject *unsafe = __Pyx_PyObject_GetAttrStrNoError(spec, __pyx_n_s_initializing); + if (likely(!unsafe || !__Pyx_PyObject_IsTrue(unsafe))) { + Py_DECREF(spec); + spec = NULL; + } + Py_XDECREF(unsafe); + } + if (likely(!spec)) { + PyErr_Clear(); + return module; + } + Py_DECREF(spec); + Py_DECREF(module); + } else if (PyErr_Occurred()) { + PyErr_Clear(); + } +#endif + return __Pyx__ImportDottedModule(name, parts_tuple); +} + +/* ImportFrom */ + static PyObject* __Pyx_ImportFrom(PyObject* module, PyObject* name) { + PyObject* value = __Pyx_PyObject_GetAttrStr(module, name); + if (unlikely(!value) && PyErr_ExceptionMatches(PyExc_AttributeError)) { + const char* module_name_str = 0; + PyObject* module_name = 0; + PyObject* module_dot = 0; + PyObject* full_name = 0; + PyErr_Clear(); + module_name_str = PyModule_GetName(module); + if (unlikely(!module_name_str)) { goto modbad; } + module_name = PyUnicode_FromString(module_name_str); + if (unlikely(!module_name)) { goto modbad; } + module_dot = PyUnicode_Concat(module_name, __pyx_kp_u__3); + if (unlikely(!module_dot)) { goto modbad; } + full_name = PyUnicode_Concat(module_dot, name); + if (unlikely(!full_name)) { goto modbad; } + #if PY_VERSION_HEX < 0x030700A1 || (CYTHON_COMPILING_IN_PYPY && PYPY_VERSION_NUM < 0x07030400) + { + PyObject *modules = PyImport_GetModuleDict(); + if (unlikely(!modules)) + goto modbad; + value = PyObject_GetItem(modules, full_name); + } + #else + value = PyImport_GetModule(full_name); + #endif + modbad: + Py_XDECREF(full_name); + Py_XDECREF(module_dot); + Py_XDECREF(module_name); + } + if (unlikely(!value)) { + PyErr_Format(PyExc_ImportError, + #if PY_MAJOR_VERSION < 3 + "cannot import name %.230s", PyString_AS_STRING(name)); + #else + "cannot import name %S", name); + #endif + } + return value; +} + +/* Py3UpdateBases */ + static PyObject* +__Pyx_PEP560_update_bases(PyObject *bases) +{ + Py_ssize_t i, j, size_bases; + PyObject *base, *meth, *new_base, *result, *new_bases = NULL; + size_bases = PyTuple_GET_SIZE(bases); + for (i = 0; i < size_bases; i++) { + base = PyTuple_GET_ITEM(bases, i); + if (PyType_Check(base)) { + if (new_bases) { + if (PyList_Append(new_bases, base) < 0) { + goto error; + } + } + continue; + } + meth = __Pyx_PyObject_GetAttrStrNoError(base, __pyx_n_s_mro_entries); + if (!meth && PyErr_Occurred()) { + goto error; + } + if (!meth) { + if (new_bases) { + if (PyList_Append(new_bases, base) < 0) { + goto error; + } + } + continue; + } + new_base = __Pyx_PyObject_CallOneArg(meth, bases); + Py_DECREF(meth); + if (!new_base) { + goto error; + } + if (!PyTuple_Check(new_base)) { + PyErr_SetString(PyExc_TypeError, + "__mro_entries__ must return a tuple"); + Py_DECREF(new_base); + goto error; + } + if (!new_bases) { + if (!(new_bases = PyList_New(i))) { + goto error; + } + for (j = 0; j < i; j++) { + base = PyTuple_GET_ITEM(bases, j); + PyList_SET_ITEM(new_bases, j, base); + Py_INCREF(base); + } + } + j = PyList_GET_SIZE(new_bases); + if (PyList_SetSlice(new_bases, j, j, new_base) < 0) { + goto error; + } + Py_DECREF(new_base); + } + if (!new_bases) { + Py_INCREF(bases); + return bases; + } + result = PyList_AsTuple(new_bases); + Py_DECREF(new_bases); + return result; +error: + Py_XDECREF(new_bases); + return NULL; +} + +/* CalculateMetaclass */ + static PyObject *__Pyx_CalculateMetaclass(PyTypeObject *metaclass, PyObject *bases) { + Py_ssize_t i, nbases; +#if CYTHON_ASSUME_SAFE_MACROS + nbases = PyTuple_GET_SIZE(bases); +#else + nbases = PyTuple_Size(bases); + if (nbases < 0) return NULL; +#endif + for (i=0; i < nbases; i++) { + PyTypeObject *tmptype; +#if CYTHON_ASSUME_SAFE_MACROS + PyObject *tmp = PyTuple_GET_ITEM(bases, i); +#else + PyObject *tmp = PyTuple_GetItem(bases, i); + if (!tmp) return NULL; +#endif + tmptype = Py_TYPE(tmp); +#if PY_MAJOR_VERSION < 3 + if (tmptype == &PyClass_Type) + continue; +#endif + if (!metaclass) { + metaclass = tmptype; + continue; + } + if (PyType_IsSubtype(metaclass, tmptype)) + continue; + if (PyType_IsSubtype(tmptype, metaclass)) { + metaclass = tmptype; + continue; + } + PyErr_SetString(PyExc_TypeError, + "metaclass conflict: " + "the metaclass of a derived class " + "must be a (non-strict) subclass " + "of the metaclasses of all its bases"); + return NULL; + } + if (!metaclass) { +#if PY_MAJOR_VERSION < 3 + metaclass = &PyClass_Type; +#else + metaclass = &PyType_Type; +#endif + } + Py_INCREF((PyObject*) metaclass); + return (PyObject*) metaclass; +} + +/* PyVectorcallFastCallDict */ + #if CYTHON_METH_FASTCALL +static PyObject *__Pyx_PyVectorcall_FastCallDict_kw(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw) +{ + PyObject *res = NULL; + PyObject *kwnames; + PyObject **newargs; + PyObject **kwvalues; + Py_ssize_t i, pos; + size_t j; + PyObject *key, *value; + unsigned long keys_are_strings; + Py_ssize_t nkw = PyDict_GET_SIZE(kw); + newargs = (PyObject **)PyMem_Malloc((nargs + (size_t)nkw) * sizeof(args[0])); + if (unlikely(newargs == NULL)) { + PyErr_NoMemory(); + return NULL; + } + for (j = 0; j < nargs; j++) newargs[j] = args[j]; + kwnames = PyTuple_New(nkw); + if (unlikely(kwnames == NULL)) { + PyMem_Free(newargs); + return NULL; + } + kwvalues = newargs + nargs; + pos = i = 0; + keys_are_strings = Py_TPFLAGS_UNICODE_SUBCLASS; + while (PyDict_Next(kw, &pos, &key, &value)) { + keys_are_strings &= Py_TYPE(key)->tp_flags; + Py_INCREF(key); + Py_INCREF(value); + PyTuple_SET_ITEM(kwnames, i, key); + kwvalues[i] = value; + i++; + } + if (unlikely(!keys_are_strings)) { + PyErr_SetString(PyExc_TypeError, "keywords must be strings"); + goto cleanup; + } + res = vc(func, newargs, nargs, kwnames); +cleanup: + Py_DECREF(kwnames); + for (i = 0; i < nkw; i++) + Py_DECREF(kwvalues[i]); + PyMem_Free(newargs); + return res; +} +static CYTHON_INLINE PyObject *__Pyx_PyVectorcall_FastCallDict(PyObject *func, __pyx_vectorcallfunc vc, PyObject *const *args, size_t nargs, PyObject *kw) +{ + if (likely(kw == NULL) || PyDict_GET_SIZE(kw) == 0) { + return vc(func, args, nargs, NULL); + } + return __Pyx_PyVectorcall_FastCallDict_kw(func, vc, args, nargs, kw); +} +#endif + +/* CythonFunctionShared */ + #if CYTHON_COMPILING_IN_LIMITED_API +static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc) { + if (__Pyx_CyFunction_Check(func)) { + return PyCFunction_GetFunction(((__pyx_CyFunctionObject*)func)->func) == (PyCFunction) cfunc; + } else if (PyCFunction_Check(func)) { + return PyCFunction_GetFunction(func) == (PyCFunction) cfunc; + } + return 0; +} +#else +static CYTHON_INLINE int __Pyx__IsSameCyOrCFunction(PyObject *func, void *cfunc) { + return __Pyx_CyOrPyCFunction_Check(func) && __Pyx_CyOrPyCFunction_GET_FUNCTION(func) == (PyCFunction) cfunc; +} +#endif +static CYTHON_INLINE void __Pyx__CyFunction_SetClassObj(__pyx_CyFunctionObject* f, PyObject* classobj) { +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + __Pyx_Py_XDECREF_SET( + __Pyx_CyFunction_GetClassObj(f), + ((classobj) ? __Pyx_NewRef(classobj) : NULL)); +#else + __Pyx_Py_XDECREF_SET( + ((PyCMethodObject *) (f))->mm_class, + (PyTypeObject*)((classobj) ? __Pyx_NewRef(classobj) : NULL)); +#endif +} +static PyObject * +__Pyx_CyFunction_get_doc(__pyx_CyFunctionObject *op, void *closure) +{ + CYTHON_UNUSED_VAR(closure); + if (unlikely(op->func_doc == NULL)) { +#if CYTHON_COMPILING_IN_LIMITED_API + op->func_doc = PyObject_GetAttrString(op->func, "__doc__"); + if (unlikely(!op->func_doc)) return NULL; +#else + if (((PyCFunctionObject*)op)->m_ml->ml_doc) { +#if PY_MAJOR_VERSION >= 3 + op->func_doc = PyUnicode_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc); +#else + op->func_doc = PyString_FromString(((PyCFunctionObject*)op)->m_ml->ml_doc); +#endif + if (unlikely(op->func_doc == NULL)) + return NULL; + } else { + Py_INCREF(Py_None); + return Py_None; + } +#endif + } + Py_INCREF(op->func_doc); + return op->func_doc; +} +static int +__Pyx_CyFunction_set_doc(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (value == NULL) { + value = Py_None; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_doc, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_name(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (unlikely(op->func_name == NULL)) { +#if CYTHON_COMPILING_IN_LIMITED_API + op->func_name = PyObject_GetAttrString(op->func, "__name__"); +#elif PY_MAJOR_VERSION >= 3 + op->func_name = PyUnicode_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name); +#else + op->func_name = PyString_InternFromString(((PyCFunctionObject*)op)->m_ml->ml_name); +#endif + if (unlikely(op->func_name == NULL)) + return NULL; + } + Py_INCREF(op->func_name); + return op->func_name; +} +static int +__Pyx_CyFunction_set_name(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) +#else + if (unlikely(value == NULL || !PyString_Check(value))) +#endif + { + PyErr_SetString(PyExc_TypeError, + "__name__ must be set to a string object"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_name, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_qualname(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + Py_INCREF(op->func_qualname); + return op->func_qualname; +} +static int +__Pyx_CyFunction_set_qualname(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); +#if PY_MAJOR_VERSION >= 3 + if (unlikely(value == NULL || !PyUnicode_Check(value))) +#else + if (unlikely(value == NULL || !PyString_Check(value))) +#endif + { + PyErr_SetString(PyExc_TypeError, + "__qualname__ must be set to a string object"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_qualname, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_dict(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (unlikely(op->func_dict == NULL)) { + op->func_dict = PyDict_New(); + if (unlikely(op->func_dict == NULL)) + return NULL; + } + Py_INCREF(op->func_dict); + return op->func_dict; +} +static int +__Pyx_CyFunction_set_dict(__pyx_CyFunctionObject *op, PyObject *value, void *context) +{ + CYTHON_UNUSED_VAR(context); + if (unlikely(value == NULL)) { + PyErr_SetString(PyExc_TypeError, + "function's dictionary may not be deleted"); + return -1; + } + if (unlikely(!PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "setting function's dictionary to a non-dict"); + return -1; + } + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->func_dict, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_globals(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(context); + Py_INCREF(op->func_globals); + return op->func_globals; +} +static PyObject * +__Pyx_CyFunction_get_closure(__pyx_CyFunctionObject *op, void *context) +{ + CYTHON_UNUSED_VAR(op); + CYTHON_UNUSED_VAR(context); + Py_INCREF(Py_None); + return Py_None; +} +static PyObject * +__Pyx_CyFunction_get_code(__pyx_CyFunctionObject *op, void *context) +{ + PyObject* result = (op->func_code) ? op->func_code : Py_None; + CYTHON_UNUSED_VAR(context); + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_init_defaults(__pyx_CyFunctionObject *op) { + int result = 0; + PyObject *res = op->defaults_getter((PyObject *) op); + if (unlikely(!res)) + return -1; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + op->defaults_tuple = PyTuple_GET_ITEM(res, 0); + Py_INCREF(op->defaults_tuple); + op->defaults_kwdict = PyTuple_GET_ITEM(res, 1); + Py_INCREF(op->defaults_kwdict); + #else + op->defaults_tuple = __Pyx_PySequence_ITEM(res, 0); + if (unlikely(!op->defaults_tuple)) result = -1; + else { + op->defaults_kwdict = __Pyx_PySequence_ITEM(res, 1); + if (unlikely(!op->defaults_kwdict)) result = -1; + } + #endif + Py_DECREF(res); + return result; +} +static int +__Pyx_CyFunction_set_defaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + if (!value) { + value = Py_None; + } else if (unlikely(value != Py_None && !PyTuple_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "__defaults__ must be set to a tuple object"); + return -1; + } + PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__defaults__ will not " + "currently affect the values used in function calls", 1); + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->defaults_tuple, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_defaults(__pyx_CyFunctionObject *op, void *context) { + PyObject* result = op->defaults_tuple; + CYTHON_UNUSED_VAR(context); + if (unlikely(!result)) { + if (op->defaults_getter) { + if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL; + result = op->defaults_tuple; + } else { + result = Py_None; + } + } + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_set_kwdefaults(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + if (!value) { + value = Py_None; + } else if (unlikely(value != Py_None && !PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "__kwdefaults__ must be set to a dict object"); + return -1; + } + PyErr_WarnEx(PyExc_RuntimeWarning, "changes to cyfunction.__kwdefaults__ will not " + "currently affect the values used in function calls", 1); + Py_INCREF(value); + __Pyx_Py_XDECREF_SET(op->defaults_kwdict, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_kwdefaults(__pyx_CyFunctionObject *op, void *context) { + PyObject* result = op->defaults_kwdict; + CYTHON_UNUSED_VAR(context); + if (unlikely(!result)) { + if (op->defaults_getter) { + if (unlikely(__Pyx_CyFunction_init_defaults(op) < 0)) return NULL; + result = op->defaults_kwdict; + } else { + result = Py_None; + } + } + Py_INCREF(result); + return result; +} +static int +__Pyx_CyFunction_set_annotations(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + if (!value || value == Py_None) { + value = NULL; + } else if (unlikely(!PyDict_Check(value))) { + PyErr_SetString(PyExc_TypeError, + "__annotations__ must be set to a dict object"); + return -1; + } + Py_XINCREF(value); + __Pyx_Py_XDECREF_SET(op->func_annotations, value); + return 0; +} +static PyObject * +__Pyx_CyFunction_get_annotations(__pyx_CyFunctionObject *op, void *context) { + PyObject* result = op->func_annotations; + CYTHON_UNUSED_VAR(context); + if (unlikely(!result)) { + result = PyDict_New(); + if (unlikely(!result)) return NULL; + op->func_annotations = result; + } + Py_INCREF(result); + return result; +} +static PyObject * +__Pyx_CyFunction_get_is_coroutine(__pyx_CyFunctionObject *op, void *context) { + int is_coroutine; + CYTHON_UNUSED_VAR(context); + if (op->func_is_coroutine) { + return __Pyx_NewRef(op->func_is_coroutine); + } + is_coroutine = op->flags & __Pyx_CYFUNCTION_COROUTINE; +#if PY_VERSION_HEX >= 0x03050000 + if (is_coroutine) { + PyObject *module, *fromlist, *marker = __pyx_n_s_is_coroutine; + fromlist = PyList_New(1); + if (unlikely(!fromlist)) return NULL; + Py_INCREF(marker); +#if CYTHON_ASSUME_SAFE_MACROS + PyList_SET_ITEM(fromlist, 0, marker); +#else + if (unlikely(PyList_SetItem(fromlist, 0, marker) < 0)) { + Py_DECREF(marker); + Py_DECREF(fromlist); + return NULL; + } +#endif + module = PyImport_ImportModuleLevelObject(__pyx_n_s_asyncio_coroutines, NULL, NULL, fromlist, 0); + Py_DECREF(fromlist); + if (unlikely(!module)) goto ignore; + op->func_is_coroutine = __Pyx_PyObject_GetAttrStr(module, marker); + Py_DECREF(module); + if (likely(op->func_is_coroutine)) { + return __Pyx_NewRef(op->func_is_coroutine); + } +ignore: + PyErr_Clear(); + } +#endif + op->func_is_coroutine = __Pyx_PyBool_FromLong(is_coroutine); + return __Pyx_NewRef(op->func_is_coroutine); +} +#if CYTHON_COMPILING_IN_LIMITED_API +static PyObject * +__Pyx_CyFunction_get_module(__pyx_CyFunctionObject *op, void *context) { + CYTHON_UNUSED_VAR(context); + return PyObject_GetAttrString(op->func, "__module__"); +} +static int +__Pyx_CyFunction_set_module(__pyx_CyFunctionObject *op, PyObject* value, void *context) { + CYTHON_UNUSED_VAR(context); + return PyObject_SetAttrString(op->func, "__module__", value); +} +#endif +static PyGetSetDef __pyx_CyFunction_getsets[] = { + {(char *) "func_doc", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, + {(char *) "__doc__", (getter)__Pyx_CyFunction_get_doc, (setter)__Pyx_CyFunction_set_doc, 0, 0}, + {(char *) "func_name", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, + {(char *) "__name__", (getter)__Pyx_CyFunction_get_name, (setter)__Pyx_CyFunction_set_name, 0, 0}, + {(char *) "__qualname__", (getter)__Pyx_CyFunction_get_qualname, (setter)__Pyx_CyFunction_set_qualname, 0, 0}, + {(char *) "func_dict", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, + {(char *) "__dict__", (getter)__Pyx_CyFunction_get_dict, (setter)__Pyx_CyFunction_set_dict, 0, 0}, + {(char *) "func_globals", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, + {(char *) "__globals__", (getter)__Pyx_CyFunction_get_globals, 0, 0, 0}, + {(char *) "func_closure", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, + {(char *) "__closure__", (getter)__Pyx_CyFunction_get_closure, 0, 0, 0}, + {(char *) "func_code", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, + {(char *) "__code__", (getter)__Pyx_CyFunction_get_code, 0, 0, 0}, + {(char *) "func_defaults", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, + {(char *) "__defaults__", (getter)__Pyx_CyFunction_get_defaults, (setter)__Pyx_CyFunction_set_defaults, 0, 0}, + {(char *) "__kwdefaults__", (getter)__Pyx_CyFunction_get_kwdefaults, (setter)__Pyx_CyFunction_set_kwdefaults, 0, 0}, + {(char *) "__annotations__", (getter)__Pyx_CyFunction_get_annotations, (setter)__Pyx_CyFunction_set_annotations, 0, 0}, + {(char *) "_is_coroutine", (getter)__Pyx_CyFunction_get_is_coroutine, 0, 0, 0}, +#if CYTHON_COMPILING_IN_LIMITED_API + {"__module__", (getter)__Pyx_CyFunction_get_module, (setter)__Pyx_CyFunction_set_module, 0, 0}, +#endif + {0, 0, 0, 0, 0} +}; +static PyMemberDef __pyx_CyFunction_members[] = { +#if !CYTHON_COMPILING_IN_LIMITED_API + {(char *) "__module__", T_OBJECT, offsetof(PyCFunctionObject, m_module), 0, 0}, +#endif +#if CYTHON_USE_TYPE_SPECS + {(char *) "__dictoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_dict), READONLY, 0}, +#if CYTHON_METH_FASTCALL +#if CYTHON_BACKPORT_VECTORCALL + {(char *) "__vectorcalloffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_vectorcall), READONLY, 0}, +#else +#if !CYTHON_COMPILING_IN_LIMITED_API + {(char *) "__vectorcalloffset__", T_PYSSIZET, offsetof(PyCFunctionObject, vectorcall), READONLY, 0}, +#endif +#endif +#endif +#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API + {(char *) "__weaklistoffset__", T_PYSSIZET, offsetof(__pyx_CyFunctionObject, func_weakreflist), READONLY, 0}, +#else + {(char *) "__weaklistoffset__", T_PYSSIZET, offsetof(PyCFunctionObject, m_weakreflist), READONLY, 0}, +#endif +#endif + {0, 0, 0, 0, 0} +}; +static PyObject * +__Pyx_CyFunction_reduce(__pyx_CyFunctionObject *m, PyObject *args) +{ + CYTHON_UNUSED_VAR(args); +#if PY_MAJOR_VERSION >= 3 + Py_INCREF(m->func_qualname); + return m->func_qualname; +#else + return PyString_FromString(((PyCFunctionObject*)m)->m_ml->ml_name); +#endif +} +static PyMethodDef __pyx_CyFunction_methods[] = { + {"__reduce__", (PyCFunction)__Pyx_CyFunction_reduce, METH_VARARGS, 0}, + {0, 0, 0, 0} +}; +#if PY_VERSION_HEX < 0x030500A0 || CYTHON_COMPILING_IN_LIMITED_API +#define __Pyx_CyFunction_weakreflist(cyfunc) ((cyfunc)->func_weakreflist) +#else +#define __Pyx_CyFunction_weakreflist(cyfunc) (((PyCFunctionObject*)cyfunc)->m_weakreflist) +#endif +static PyObject *__Pyx_CyFunction_Init(__pyx_CyFunctionObject *op, PyMethodDef *ml, int flags, PyObject* qualname, + PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { +#if !CYTHON_COMPILING_IN_LIMITED_API + PyCFunctionObject *cf = (PyCFunctionObject*) op; +#endif + if (unlikely(op == NULL)) + return NULL; +#if CYTHON_COMPILING_IN_LIMITED_API + op->func = PyCFunction_NewEx(ml, (PyObject*)op, module); + if (unlikely(!op->func)) return NULL; +#endif + op->flags = flags; + __Pyx_CyFunction_weakreflist(op) = NULL; +#if !CYTHON_COMPILING_IN_LIMITED_API + cf->m_ml = ml; + cf->m_self = (PyObject *) op; +#endif + Py_XINCREF(closure); + op->func_closure = closure; +#if !CYTHON_COMPILING_IN_LIMITED_API + Py_XINCREF(module); + cf->m_module = module; +#endif + op->func_dict = NULL; + op->func_name = NULL; + Py_INCREF(qualname); + op->func_qualname = qualname; + op->func_doc = NULL; +#if PY_VERSION_HEX < 0x030900B1 || CYTHON_COMPILING_IN_LIMITED_API + op->func_classobj = NULL; +#else + ((PyCMethodObject*)op)->mm_class = NULL; +#endif + op->func_globals = globals; + Py_INCREF(op->func_globals); + Py_XINCREF(code); + op->func_code = code; + op->defaults_pyobjects = 0; + op->defaults_size = 0; + op->defaults = NULL; + op->defaults_tuple = NULL; + op->defaults_kwdict = NULL; + op->defaults_getter = NULL; + op->func_annotations = NULL; + op->func_is_coroutine = NULL; +#if CYTHON_METH_FASTCALL + switch (ml->ml_flags & (METH_VARARGS | METH_FASTCALL | METH_NOARGS | METH_O | METH_KEYWORDS | METH_METHOD)) { + case METH_NOARGS: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_NOARGS; + break; + case METH_O: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_O; + break; + case METH_METHOD | METH_FASTCALL | METH_KEYWORDS: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD; + break; + case METH_FASTCALL | METH_KEYWORDS: + __Pyx_CyFunction_func_vectorcall(op) = __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS; + break; + case METH_VARARGS | METH_KEYWORDS: + __Pyx_CyFunction_func_vectorcall(op) = NULL; + break; + default: + PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction"); + Py_DECREF(op); + return NULL; + } +#endif + return (PyObject *) op; +} +static int +__Pyx_CyFunction_clear(__pyx_CyFunctionObject *m) +{ + Py_CLEAR(m->func_closure); +#if CYTHON_COMPILING_IN_LIMITED_API + Py_CLEAR(m->func); +#else + Py_CLEAR(((PyCFunctionObject*)m)->m_module); +#endif + Py_CLEAR(m->func_dict); + Py_CLEAR(m->func_name); + Py_CLEAR(m->func_qualname); + Py_CLEAR(m->func_doc); + Py_CLEAR(m->func_globals); + Py_CLEAR(m->func_code); +#if !CYTHON_COMPILING_IN_LIMITED_API +#if PY_VERSION_HEX < 0x030900B1 + Py_CLEAR(__Pyx_CyFunction_GetClassObj(m)); +#else + { + PyObject *cls = (PyObject*) ((PyCMethodObject *) (m))->mm_class; + ((PyCMethodObject *) (m))->mm_class = NULL; + Py_XDECREF(cls); + } +#endif +#endif + Py_CLEAR(m->defaults_tuple); + Py_CLEAR(m->defaults_kwdict); + Py_CLEAR(m->func_annotations); + Py_CLEAR(m->func_is_coroutine); + if (m->defaults) { + PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); + int i; + for (i = 0; i < m->defaults_pyobjects; i++) + Py_XDECREF(pydefaults[i]); + PyObject_Free(m->defaults); + m->defaults = NULL; + } + return 0; +} +static void __Pyx__CyFunction_dealloc(__pyx_CyFunctionObject *m) +{ + if (__Pyx_CyFunction_weakreflist(m) != NULL) + PyObject_ClearWeakRefs((PyObject *) m); + __Pyx_CyFunction_clear(m); + __Pyx_PyHeapTypeObject_GC_Del(m); +} +static void __Pyx_CyFunction_dealloc(__pyx_CyFunctionObject *m) +{ + PyObject_GC_UnTrack(m); + __Pyx__CyFunction_dealloc(m); +} +static int __Pyx_CyFunction_traverse(__pyx_CyFunctionObject *m, visitproc visit, void *arg) +{ + Py_VISIT(m->func_closure); +#if CYTHON_COMPILING_IN_LIMITED_API + Py_VISIT(m->func); +#else + Py_VISIT(((PyCFunctionObject*)m)->m_module); +#endif + Py_VISIT(m->func_dict); + Py_VISIT(m->func_name); + Py_VISIT(m->func_qualname); + Py_VISIT(m->func_doc); + Py_VISIT(m->func_globals); + Py_VISIT(m->func_code); +#if !CYTHON_COMPILING_IN_LIMITED_API + Py_VISIT(__Pyx_CyFunction_GetClassObj(m)); +#endif + Py_VISIT(m->defaults_tuple); + Py_VISIT(m->defaults_kwdict); + Py_VISIT(m->func_is_coroutine); + if (m->defaults) { + PyObject **pydefaults = __Pyx_CyFunction_Defaults(PyObject *, m); + int i; + for (i = 0; i < m->defaults_pyobjects; i++) + Py_VISIT(pydefaults[i]); + } + return 0; +} +static PyObject* +__Pyx_CyFunction_repr(__pyx_CyFunctionObject *op) +{ +#if PY_MAJOR_VERSION >= 3 + return PyUnicode_FromFormat("", + op->func_qualname, (void *)op); +#else + return PyString_FromFormat("", + PyString_AsString(op->func_qualname), (void *)op); +#endif +} +static PyObject * __Pyx_CyFunction_CallMethod(PyObject *func, PyObject *self, PyObject *arg, PyObject *kw) { +#if CYTHON_COMPILING_IN_LIMITED_API + PyObject *f = ((__pyx_CyFunctionObject*)func)->func; + PyObject *py_name = NULL; + PyCFunction meth; + int flags; + meth = PyCFunction_GetFunction(f); + if (unlikely(!meth)) return NULL; + flags = PyCFunction_GetFlags(f); + if (unlikely(flags < 0)) return NULL; +#else + PyCFunctionObject* f = (PyCFunctionObject*)func; + PyCFunction meth = f->m_ml->ml_meth; + int flags = f->m_ml->ml_flags; +#endif + Py_ssize_t size; + switch (flags & (METH_VARARGS | METH_KEYWORDS | METH_NOARGS | METH_O)) { + case METH_VARARGS: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) + return (*meth)(self, arg); + break; + case METH_VARARGS | METH_KEYWORDS: + return (*(PyCFunctionWithKeywords)(void*)meth)(self, arg, kw); + case METH_NOARGS: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) { +#if CYTHON_ASSUME_SAFE_MACROS + size = PyTuple_GET_SIZE(arg); +#else + size = PyTuple_Size(arg); + if (unlikely(size < 0)) return NULL; +#endif + if (likely(size == 0)) + return (*meth)(self, NULL); +#if CYTHON_COMPILING_IN_LIMITED_API + py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); + if (!py_name) return NULL; + PyErr_Format(PyExc_TypeError, + "%.200S() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + py_name, size); + Py_DECREF(py_name); +#else + PyErr_Format(PyExc_TypeError, + "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + f->m_ml->ml_name, size); +#endif + return NULL; + } + break; + case METH_O: + if (likely(kw == NULL || PyDict_Size(kw) == 0)) { +#if CYTHON_ASSUME_SAFE_MACROS + size = PyTuple_GET_SIZE(arg); +#else + size = PyTuple_Size(arg); + if (unlikely(size < 0)) return NULL; +#endif + if (likely(size == 1)) { + PyObject *result, *arg0; + #if CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + arg0 = PyTuple_GET_ITEM(arg, 0); + #else + arg0 = __Pyx_PySequence_ITEM(arg, 0); if (unlikely(!arg0)) return NULL; + #endif + result = (*meth)(self, arg0); + #if !(CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS) + Py_DECREF(arg0); + #endif + return result; + } +#if CYTHON_COMPILING_IN_LIMITED_API + py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); + if (!py_name) return NULL; + PyErr_Format(PyExc_TypeError, + "%.200S() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + py_name, size); + Py_DECREF(py_name); +#else + PyErr_Format(PyExc_TypeError, + "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + f->m_ml->ml_name, size); +#endif + return NULL; + } + break; + default: + PyErr_SetString(PyExc_SystemError, "Bad call flags for CyFunction"); + return NULL; + } +#if CYTHON_COMPILING_IN_LIMITED_API + py_name = __Pyx_CyFunction_get_name((__pyx_CyFunctionObject*)func, NULL); + if (!py_name) return NULL; + PyErr_Format(PyExc_TypeError, "%.200S() takes no keyword arguments", + py_name); + Py_DECREF(py_name); +#else + PyErr_Format(PyExc_TypeError, "%.200s() takes no keyword arguments", + f->m_ml->ml_name); +#endif + return NULL; +} +static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *arg, PyObject *kw) { + PyObject *self, *result; +#if CYTHON_COMPILING_IN_LIMITED_API + self = PyCFunction_GetSelf(((__pyx_CyFunctionObject*)func)->func); + if (unlikely(!self) && PyErr_Occurred()) return NULL; +#else + self = ((PyCFunctionObject*)func)->m_self; +#endif + result = __Pyx_CyFunction_CallMethod(func, self, arg, kw); + return result; +} +static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) { + PyObject *result; + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func; +#if CYTHON_METH_FASTCALL + __pyx_vectorcallfunc vc = __Pyx_CyFunction_func_vectorcall(cyfunc); + if (vc) { +#if CYTHON_ASSUME_SAFE_MACROS + return __Pyx_PyVectorcall_FastCallDict(func, vc, &PyTuple_GET_ITEM(args, 0), (size_t)PyTuple_GET_SIZE(args), kw); +#else + (void) &__Pyx_PyVectorcall_FastCallDict; + return PyVectorcall_Call(func, args, kw); +#endif + } +#endif + if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { + Py_ssize_t argc; + PyObject *new_args; + PyObject *self; +#if CYTHON_ASSUME_SAFE_MACROS + argc = PyTuple_GET_SIZE(args); +#else + argc = PyTuple_Size(args); + if (unlikely(!argc) < 0) return NULL; +#endif + new_args = PyTuple_GetSlice(args, 1, argc); + if (unlikely(!new_args)) + return NULL; + self = PyTuple_GetItem(args, 0); + if (unlikely(!self)) { + Py_DECREF(new_args); +#if PY_MAJOR_VERSION > 2 + PyErr_Format(PyExc_TypeError, + "unbound method %.200S() needs an argument", + cyfunc->func_qualname); +#else + PyErr_SetString(PyExc_TypeError, + "unbound method needs an argument"); +#endif + return NULL; + } + result = __Pyx_CyFunction_CallMethod(func, self, new_args, kw); + Py_DECREF(new_args); + } else { + result = __Pyx_CyFunction_Call(func, args, kw); + } + return result; +} +#if CYTHON_METH_FASTCALL +static CYTHON_INLINE int __Pyx_CyFunction_Vectorcall_CheckArgs(__pyx_CyFunctionObject *cyfunc, Py_ssize_t nargs, PyObject *kwnames) +{ + int ret = 0; + if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) { + if (unlikely(nargs < 1)) { + PyErr_Format(PyExc_TypeError, "%.200s() needs an argument", + ((PyCFunctionObject*)cyfunc)->m_ml->ml_name); + return -1; + } + ret = 1; + } + if (unlikely(kwnames) && unlikely(PyTuple_GET_SIZE(kwnames))) { + PyErr_Format(PyExc_TypeError, + "%.200s() takes no keyword arguments", ((PyCFunctionObject*)cyfunc)->m_ml->ml_name); + return -1; + } + return ret; +} +static PyObject * __Pyx_CyFunction_Vectorcall_NOARGS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + if (unlikely(nargs != 0)) { + PyErr_Format(PyExc_TypeError, + "%.200s() takes no arguments (%" CYTHON_FORMAT_SSIZE_T "d given)", + def->ml_name, nargs); + return NULL; + } + return def->ml_meth(self, NULL); +} +static PyObject * __Pyx_CyFunction_Vectorcall_O(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, kwnames)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + if (unlikely(nargs != 1)) { + PyErr_Format(PyExc_TypeError, + "%.200s() takes exactly one argument (%" CYTHON_FORMAT_SSIZE_T "d given)", + def->ml_name, nargs); + return NULL; + } + return def->ml_meth(self, args[0]); +} +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + return ((__Pyx_PyCFunctionFastWithKeywords)(void(*)(void))def->ml_meth)(self, args, nargs, kwnames); +} +static PyObject * __Pyx_CyFunction_Vectorcall_FASTCALL_KEYWORDS_METHOD(PyObject *func, PyObject *const *args, size_t nargsf, PyObject *kwnames) +{ + __pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *)func; + PyMethodDef* def = ((PyCFunctionObject*)cyfunc)->m_ml; + PyTypeObject *cls = (PyTypeObject *) __Pyx_CyFunction_GetClassObj(cyfunc); +#if CYTHON_BACKPORT_VECTORCALL + Py_ssize_t nargs = (Py_ssize_t)nargsf; +#else + Py_ssize_t nargs = PyVectorcall_NARGS(nargsf); +#endif + PyObject *self; + switch (__Pyx_CyFunction_Vectorcall_CheckArgs(cyfunc, nargs, NULL)) { + case 1: + self = args[0]; + args += 1; + nargs -= 1; + break; + case 0: + self = ((PyCFunctionObject*)cyfunc)->m_self; + break; + default: + return NULL; + } + return ((__Pyx_PyCMethod)(void(*)(void))def->ml_meth)(self, cls, args, (size_t)nargs, kwnames); +} +#endif +#if CYTHON_USE_TYPE_SPECS +static PyType_Slot __pyx_CyFunctionType_slots[] = { + {Py_tp_dealloc, (void *)__Pyx_CyFunction_dealloc}, + {Py_tp_repr, (void *)__Pyx_CyFunction_repr}, + {Py_tp_call, (void *)__Pyx_CyFunction_CallAsMethod}, + {Py_tp_traverse, (void *)__Pyx_CyFunction_traverse}, + {Py_tp_clear, (void *)__Pyx_CyFunction_clear}, + {Py_tp_methods, (void *)__pyx_CyFunction_methods}, + {Py_tp_members, (void *)__pyx_CyFunction_members}, + {Py_tp_getset, (void *)__pyx_CyFunction_getsets}, + {Py_tp_descr_get, (void *)__Pyx_PyMethod_New}, + {0, 0}, +}; +static PyType_Spec __pyx_CyFunctionType_spec = { + __PYX_TYPE_MODULE_PREFIX "cython_function_or_method", + sizeof(__pyx_CyFunctionObject), + 0, +#ifdef Py_TPFLAGS_METHOD_DESCRIPTOR + Py_TPFLAGS_METHOD_DESCRIPTOR | +#endif +#if (defined(_Py_TPFLAGS_HAVE_VECTORCALL) && CYTHON_METH_FASTCALL) + _Py_TPFLAGS_HAVE_VECTORCALL | +#endif + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, + __pyx_CyFunctionType_slots +}; +#else +static PyTypeObject __pyx_CyFunctionType_type = { + PyVarObject_HEAD_INIT(0, 0) + __PYX_TYPE_MODULE_PREFIX "cython_function_or_method", + sizeof(__pyx_CyFunctionObject), + 0, + (destructor) __Pyx_CyFunction_dealloc, +#if !CYTHON_METH_FASTCALL + 0, +#elif CYTHON_BACKPORT_VECTORCALL + (printfunc)offsetof(__pyx_CyFunctionObject, func_vectorcall), +#else + offsetof(PyCFunctionObject, vectorcall), +#endif + 0, + 0, +#if PY_MAJOR_VERSION < 3 + 0, +#else + 0, +#endif + (reprfunc) __Pyx_CyFunction_repr, + 0, + 0, + 0, + 0, + __Pyx_CyFunction_CallAsMethod, + 0, + 0, + 0, + 0, +#ifdef Py_TPFLAGS_METHOD_DESCRIPTOR + Py_TPFLAGS_METHOD_DESCRIPTOR | +#endif +#if defined(_Py_TPFLAGS_HAVE_VECTORCALL) && CYTHON_METH_FASTCALL + _Py_TPFLAGS_HAVE_VECTORCALL | +#endif + Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC | Py_TPFLAGS_BASETYPE, + 0, + (traverseproc) __Pyx_CyFunction_traverse, + (inquiry) __Pyx_CyFunction_clear, + 0, +#if PY_VERSION_HEX < 0x030500A0 + offsetof(__pyx_CyFunctionObject, func_weakreflist), +#else + offsetof(PyCFunctionObject, m_weakreflist), +#endif + 0, + 0, + __pyx_CyFunction_methods, + __pyx_CyFunction_members, + __pyx_CyFunction_getsets, + 0, + 0, + __Pyx_PyMethod_New, + 0, + offsetof(__pyx_CyFunctionObject, func_dict), + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, +#if PY_VERSION_HEX >= 0x030400a1 + 0, +#endif +#if PY_VERSION_HEX >= 0x030800b1 && (!CYTHON_COMPILING_IN_PYPY || PYPY_VERSION_NUM >= 0x07030800) + 0, +#endif +#if __PYX_NEED_TP_PRINT_SLOT + 0, +#endif +#if PY_VERSION_HEX >= 0x030C0000 + 0, +#endif +#if PY_VERSION_HEX >= 0x030d00A4 + 0, +#endif +#if CYTHON_COMPILING_IN_PYPY && PY_VERSION_HEX >= 0x03090000 && PY_VERSION_HEX < 0x030a0000 + 0, +#endif +}; +#endif +static int __pyx_CyFunction_init(PyObject *module) { +#if CYTHON_USE_TYPE_SPECS + __pyx_CyFunctionType = __Pyx_FetchCommonTypeFromSpec(module, &__pyx_CyFunctionType_spec, NULL); +#else + CYTHON_UNUSED_VAR(module); + __pyx_CyFunctionType = __Pyx_FetchCommonType(&__pyx_CyFunctionType_type); +#endif + if (unlikely(__pyx_CyFunctionType == NULL)) { + return -1; + } + return 0; +} +static CYTHON_INLINE void *__Pyx_CyFunction_InitDefaults(PyObject *func, size_t size, int pyobjects) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults = PyObject_Malloc(size); + if (unlikely(!m->defaults)) + return PyErr_NoMemory(); + memset(m->defaults, 0, size); + m->defaults_pyobjects = pyobjects; + m->defaults_size = size; + return m->defaults; +} +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsTuple(PyObject *func, PyObject *tuple) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults_tuple = tuple; + Py_INCREF(tuple); +} +static CYTHON_INLINE void __Pyx_CyFunction_SetDefaultsKwDict(PyObject *func, PyObject *dict) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->defaults_kwdict = dict; + Py_INCREF(dict); +} +static CYTHON_INLINE void __Pyx_CyFunction_SetAnnotationsDict(PyObject *func, PyObject *dict) { + __pyx_CyFunctionObject *m = (__pyx_CyFunctionObject *) func; + m->func_annotations = dict; + Py_INCREF(dict); +} + +/* CythonFunction */ + static PyObject *__Pyx_CyFunction_New(PyMethodDef *ml, int flags, PyObject* qualname, + PyObject *closure, PyObject *module, PyObject* globals, PyObject* code) { + PyObject *op = __Pyx_CyFunction_Init( + PyObject_GC_New(__pyx_CyFunctionObject, __pyx_CyFunctionType), + ml, flags, qualname, closure, module, globals, code + ); + if (likely(op)) { + PyObject_GC_Track(op); + } + return op; +} + +/* PyObjectLookupSpecial */ + #if CYTHON_USE_PYTYPE_LOOKUP && CYTHON_USE_TYPE_SLOTS +static CYTHON_INLINE PyObject* __Pyx__PyObject_LookupSpecial(PyObject* obj, PyObject* attr_name, int with_error) { + PyObject *res; + PyTypeObject *tp = Py_TYPE(obj); +#if PY_MAJOR_VERSION < 3 + if (unlikely(PyInstance_Check(obj))) + return with_error ? __Pyx_PyObject_GetAttrStr(obj, attr_name) : __Pyx_PyObject_GetAttrStrNoError(obj, attr_name); +#endif + res = _PyType_Lookup(tp, attr_name); + if (likely(res)) { + descrgetfunc f = Py_TYPE(res)->tp_descr_get; + if (!f) { + Py_INCREF(res); + } else { + res = f(res, obj, (PyObject *)tp); + } + } else if (with_error) { + PyErr_SetObject(PyExc_AttributeError, attr_name); + } + return res; +} +#endif + +/* Py3ClassCreate */ + static PyObject *__Pyx_Py3MetaclassPrepare(PyObject *metaclass, PyObject *bases, PyObject *name, + PyObject *qualname, PyObject *mkw, PyObject *modname, PyObject *doc) { + PyObject *ns; + if (metaclass) { + PyObject *prep = __Pyx_PyObject_GetAttrStrNoError(metaclass, __pyx_n_s_prepare); + if (prep) { + PyObject *pargs[3] = {NULL, name, bases}; + ns = __Pyx_PyObject_FastCallDict(prep, pargs+1, 2 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET, mkw); + Py_DECREF(prep); + } else { + if (unlikely(PyErr_Occurred())) + return NULL; + ns = PyDict_New(); + } + } else { + ns = PyDict_New(); + } + if (unlikely(!ns)) + return NULL; + if (unlikely(PyObject_SetItem(ns, __pyx_n_s_module, modname) < 0)) goto bad; +#if PY_VERSION_HEX >= 0x03030000 + if (unlikely(PyObject_SetItem(ns, __pyx_n_s_qualname, qualname) < 0)) goto bad; +#else + CYTHON_MAYBE_UNUSED_VAR(qualname); +#endif + if (unlikely(doc && PyObject_SetItem(ns, __pyx_n_s_doc, doc) < 0)) goto bad; + return ns; +bad: + Py_DECREF(ns); + return NULL; +} +#if PY_VERSION_HEX < 0x030600A4 && CYTHON_PEP487_INIT_SUBCLASS +static int __Pyx_SetNamesPEP487(PyObject *type_obj) { + PyTypeObject *type = (PyTypeObject*) type_obj; + PyObject *names_to_set, *key, *value, *set_name, *tmp; + Py_ssize_t i = 0; +#if CYTHON_USE_TYPE_SLOTS + names_to_set = PyDict_Copy(type->tp_dict); +#else + { + PyObject *d = PyObject_GetAttr(type_obj, __pyx_n_s_dict); + names_to_set = NULL; + if (likely(d)) { + PyObject *names_to_set = PyDict_New(); + int ret = likely(names_to_set) ? PyDict_Update(names_to_set, d) : -1; + Py_DECREF(d); + if (unlikely(ret < 0)) + Py_CLEAR(names_to_set); + } + } +#endif + if (unlikely(names_to_set == NULL)) + goto bad; + while (PyDict_Next(names_to_set, &i, &key, &value)) { + set_name = __Pyx_PyObject_LookupSpecialNoError(value, __pyx_n_s_set_name); + if (unlikely(set_name != NULL)) { + tmp = __Pyx_PyObject_Call2Args(set_name, type_obj, key); + Py_DECREF(set_name); + if (unlikely(tmp == NULL)) { + __Pyx_TypeName value_type_name = + __Pyx_PyType_GetName(Py_TYPE(value)); + __Pyx_TypeName type_name = __Pyx_PyType_GetName(type); + PyErr_Format(PyExc_RuntimeError, +#if PY_MAJOR_VERSION >= 3 + "Error calling __set_name__ on '" __Pyx_FMT_TYPENAME "' instance %R " "in '" __Pyx_FMT_TYPENAME "'", + value_type_name, key, type_name); +#else + "Error calling __set_name__ on '" __Pyx_FMT_TYPENAME "' instance %.100s in '" __Pyx_FMT_TYPENAME "'", + value_type_name, + PyString_Check(key) ? PyString_AS_STRING(key) : "?", + type_name); +#endif + goto bad; + } else { + Py_DECREF(tmp); + } + } + else if (unlikely(PyErr_Occurred())) { + goto bad; + } + } + Py_DECREF(names_to_set); + return 0; +bad: + Py_XDECREF(names_to_set); + return -1; +} +static PyObject *__Pyx_InitSubclassPEP487(PyObject *type_obj, PyObject *mkw) { +#if CYTHON_USE_TYPE_SLOTS && CYTHON_ASSUME_SAFE_MACROS && !CYTHON_AVOID_BORROWED_REFS + PyTypeObject *type = (PyTypeObject*) type_obj; + PyObject *mro = type->tp_mro; + Py_ssize_t i, nbases; + if (unlikely(!mro)) goto done; + (void) &__Pyx_GetBuiltinName; + Py_INCREF(mro); + nbases = PyTuple_GET_SIZE(mro); + assert(PyTuple_GET_ITEM(mro, 0) == type_obj); + for (i = 1; i < nbases-1; i++) { + PyObject *base, *dict, *meth; + base = PyTuple_GET_ITEM(mro, i); + dict = ((PyTypeObject *)base)->tp_dict; + meth = __Pyx_PyDict_GetItemStrWithError(dict, __pyx_n_s_init_subclass); + if (unlikely(meth)) { + descrgetfunc f = Py_TYPE(meth)->tp_descr_get; + PyObject *res; + Py_INCREF(meth); + if (likely(f)) { + res = f(meth, NULL, type_obj); + Py_DECREF(meth); + if (unlikely(!res)) goto bad; + meth = res; + } + res = __Pyx_PyObject_FastCallDict(meth, NULL, 0, mkw); + Py_DECREF(meth); + if (unlikely(!res)) goto bad; + Py_DECREF(res); + goto done; + } else if (unlikely(PyErr_Occurred())) { + goto bad; + } + } +done: + Py_XDECREF(mro); + return type_obj; +bad: + Py_XDECREF(mro); + Py_DECREF(type_obj); + return NULL; +#else + PyObject *super_type, *super, *func, *res; +#if CYTHON_COMPILING_IN_PYPY && !defined(PySuper_Type) + super_type = __Pyx_GetBuiltinName(__pyx_n_s_super); +#else + super_type = (PyObject*) &PySuper_Type; + (void) &__Pyx_GetBuiltinName; +#endif + super = likely(super_type) ? __Pyx_PyObject_Call2Args(super_type, type_obj, type_obj) : NULL; +#if CYTHON_COMPILING_IN_PYPY && !defined(PySuper_Type) + Py_XDECREF(super_type); +#endif + if (unlikely(!super)) { + Py_CLEAR(type_obj); + goto done; + } + func = __Pyx_PyObject_GetAttrStrNoError(super, __pyx_n_s_init_subclass); + Py_DECREF(super); + if (likely(!func)) { + if (unlikely(PyErr_Occurred())) + Py_CLEAR(type_obj); + goto done; + } + res = __Pyx_PyObject_FastCallDict(func, NULL, 0, mkw); + Py_DECREF(func); + if (unlikely(!res)) + Py_CLEAR(type_obj); + Py_XDECREF(res); +done: + return type_obj; +#endif +} +#endif +static PyObject *__Pyx_Py3ClassCreate(PyObject *metaclass, PyObject *name, PyObject *bases, + PyObject *dict, PyObject *mkw, + int calculate_metaclass, int allow_py2_metaclass) { + PyObject *result; + PyObject *owned_metaclass = NULL; + PyObject *margs[4] = {NULL, name, bases, dict}; + if (allow_py2_metaclass) { + owned_metaclass = PyObject_GetItem(dict, __pyx_n_s_metaclass); + if (owned_metaclass) { + metaclass = owned_metaclass; + } else if (likely(PyErr_ExceptionMatches(PyExc_KeyError))) { + PyErr_Clear(); + } else { + return NULL; + } + } + if (calculate_metaclass && (!metaclass || PyType_Check(metaclass))) { + metaclass = __Pyx_CalculateMetaclass((PyTypeObject*) metaclass, bases); + Py_XDECREF(owned_metaclass); + if (unlikely(!metaclass)) + return NULL; + owned_metaclass = metaclass; + } + result = __Pyx_PyObject_FastCallDict(metaclass, margs+1, 3 | __Pyx_PY_VECTORCALL_ARGUMENTS_OFFSET, +#if PY_VERSION_HEX < 0x030600A4 + (metaclass == (PyObject*)&PyType_Type) ? NULL : mkw +#else + mkw +#endif + ); + Py_XDECREF(owned_metaclass); +#if PY_VERSION_HEX < 0x030600A4 && CYTHON_PEP487_INIT_SUBCLASS + if (likely(result) && likely(PyType_Check(result))) { + if (unlikely(__Pyx_SetNamesPEP487(result) < 0)) { + Py_CLEAR(result); + } else { + result = __Pyx_InitSubclassPEP487(result, mkw); + } + } +#else + (void) &__Pyx_GetBuiltinName; +#endif + return result; +} + +/* CLineInTraceback */ + #ifndef CYTHON_CLINE_IN_TRACEBACK +static int __Pyx_CLineForTraceback(PyThreadState *tstate, int c_line) { + PyObject *use_cline; + PyObject *ptype, *pvalue, *ptraceback; +#if CYTHON_COMPILING_IN_CPYTHON + PyObject **cython_runtime_dict; +#endif + CYTHON_MAYBE_UNUSED_VAR(tstate); + if (unlikely(!__pyx_cython_runtime)) { + return c_line; + } + __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); +#if CYTHON_COMPILING_IN_CPYTHON + cython_runtime_dict = _PyObject_GetDictPtr(__pyx_cython_runtime); + if (likely(cython_runtime_dict)) { + __PYX_PY_DICT_LOOKUP_IF_MODIFIED( + use_cline, *cython_runtime_dict, + __Pyx_PyDict_GetItemStr(*cython_runtime_dict, __pyx_n_s_cline_in_traceback)) + } else +#endif + { + PyObject *use_cline_obj = __Pyx_PyObject_GetAttrStrNoError(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback); + if (use_cline_obj) { + use_cline = PyObject_Not(use_cline_obj) ? Py_False : Py_True; + Py_DECREF(use_cline_obj); + } else { + PyErr_Clear(); + use_cline = NULL; + } + } + if (!use_cline) { + c_line = 0; + (void) PyObject_SetAttr(__pyx_cython_runtime, __pyx_n_s_cline_in_traceback, Py_False); + } + else if (use_cline == Py_False || (use_cline != Py_True && PyObject_Not(use_cline) != 0)) { + c_line = 0; + } + __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); + return c_line; +} +#endif + +/* CodeObjectCache */ + #if !CYTHON_COMPILING_IN_LIMITED_API +static int __pyx_bisect_code_objects(__Pyx_CodeObjectCacheEntry* entries, int count, int code_line) { + int start = 0, mid = 0, end = count - 1; + if (end >= 0 && code_line > entries[end].code_line) { + return count; + } + while (start < end) { + mid = start + (end - start) / 2; + if (code_line < entries[mid].code_line) { + end = mid; + } else if (code_line > entries[mid].code_line) { + start = mid + 1; + } else { + return mid; + } + } + if (code_line <= entries[mid].code_line) { + return mid; + } else { + return mid + 1; + } +} +static PyCodeObject *__pyx_find_code_object(int code_line) { + PyCodeObject* code_object; + int pos; + if (unlikely(!code_line) || unlikely(!__pyx_code_cache.entries)) { + return NULL; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if (unlikely(pos >= __pyx_code_cache.count) || unlikely(__pyx_code_cache.entries[pos].code_line != code_line)) { + return NULL; + } + code_object = __pyx_code_cache.entries[pos].code_object; + Py_INCREF(code_object); + return code_object; +} +static void __pyx_insert_code_object(int code_line, PyCodeObject* code_object) { + int pos, i; + __Pyx_CodeObjectCacheEntry* entries = __pyx_code_cache.entries; + if (unlikely(!code_line)) { + return; + } + if (unlikely(!entries)) { + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Malloc(64*sizeof(__Pyx_CodeObjectCacheEntry)); + if (likely(entries)) { + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = 64; + __pyx_code_cache.count = 1; + entries[0].code_line = code_line; + entries[0].code_object = code_object; + Py_INCREF(code_object); + } + return; + } + pos = __pyx_bisect_code_objects(__pyx_code_cache.entries, __pyx_code_cache.count, code_line); + if ((pos < __pyx_code_cache.count) && unlikely(__pyx_code_cache.entries[pos].code_line == code_line)) { + PyCodeObject* tmp = entries[pos].code_object; + entries[pos].code_object = code_object; + Py_DECREF(tmp); + return; + } + if (__pyx_code_cache.count == __pyx_code_cache.max_count) { + int new_max = __pyx_code_cache.max_count + 64; + entries = (__Pyx_CodeObjectCacheEntry*)PyMem_Realloc( + __pyx_code_cache.entries, ((size_t)new_max) * sizeof(__Pyx_CodeObjectCacheEntry)); + if (unlikely(!entries)) { + return; + } + __pyx_code_cache.entries = entries; + __pyx_code_cache.max_count = new_max; + } + for (i=__pyx_code_cache.count; i>pos; i--) { + entries[i] = entries[i-1]; + } + entries[pos].code_line = code_line; + entries[pos].code_object = code_object; + __pyx_code_cache.count++; + Py_INCREF(code_object); +} +#endif + +/* AddTraceback */ + #include "compile.h" +#include "frameobject.h" +#include "traceback.h" +#if PY_VERSION_HEX >= 0x030b00a6 && !CYTHON_COMPILING_IN_LIMITED_API + #ifndef Py_BUILD_CORE + #define Py_BUILD_CORE 1 + #endif + #include "internal/pycore_frame.h" +#endif +#if CYTHON_COMPILING_IN_LIMITED_API +static PyObject *__Pyx_PyCode_Replace_For_AddTraceback(PyObject *code, PyObject *scratch_dict, + PyObject *firstlineno, PyObject *name) { + PyObject *replace = NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "co_firstlineno", firstlineno))) return NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "co_name", name))) return NULL; + replace = PyObject_GetAttrString(code, "replace"); + if (likely(replace)) { + PyObject *result; + result = PyObject_Call(replace, __pyx_empty_tuple, scratch_dict); + Py_DECREF(replace); + return result; + } + PyErr_Clear(); + #if __PYX_LIMITED_VERSION_HEX < 0x030780000 + { + PyObject *compiled = NULL, *result = NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "code", code))) return NULL; + if (unlikely(PyDict_SetItemString(scratch_dict, "type", (PyObject*)(&PyType_Type)))) return NULL; + compiled = Py_CompileString( + "out = type(code)(\n" + " code.co_argcount, code.co_kwonlyargcount, code.co_nlocals, code.co_stacksize,\n" + " code.co_flags, code.co_code, code.co_consts, code.co_names,\n" + " code.co_varnames, code.co_filename, co_name, co_firstlineno,\n" + " code.co_lnotab)\n", "", Py_file_input); + if (!compiled) return NULL; + result = PyEval_EvalCode(compiled, scratch_dict, scratch_dict); + Py_DECREF(compiled); + if (!result) PyErr_Print(); + Py_DECREF(result); + result = PyDict_GetItemString(scratch_dict, "out"); + if (result) Py_INCREF(result); + return result; + } + #else + return NULL; + #endif +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyObject *code_object = NULL, *py_py_line = NULL, *py_funcname = NULL, *dict = NULL; + PyObject *replace = NULL, *getframe = NULL, *frame = NULL; + PyObject *exc_type, *exc_value, *exc_traceback; + int success = 0; + if (c_line) { + (void) __pyx_cfilenm; + (void) __Pyx_CLineForTraceback(__Pyx_PyThreadState_Current, c_line); + } + PyErr_Fetch(&exc_type, &exc_value, &exc_traceback); + code_object = Py_CompileString("_getframe()", filename, Py_eval_input); + if (unlikely(!code_object)) goto bad; + py_py_line = PyLong_FromLong(py_line); + if (unlikely(!py_py_line)) goto bad; + py_funcname = PyUnicode_FromString(funcname); + if (unlikely(!py_funcname)) goto bad; + dict = PyDict_New(); + if (unlikely(!dict)) goto bad; + { + PyObject *old_code_object = code_object; + code_object = __Pyx_PyCode_Replace_For_AddTraceback(code_object, dict, py_py_line, py_funcname); + Py_DECREF(old_code_object); + } + if (unlikely(!code_object)) goto bad; + getframe = PySys_GetObject("_getframe"); + if (unlikely(!getframe)) goto bad; + if (unlikely(PyDict_SetItemString(dict, "_getframe", getframe))) goto bad; + frame = PyEval_EvalCode(code_object, dict, dict); + if (unlikely(!frame) || frame == Py_None) goto bad; + success = 1; + bad: + PyErr_Restore(exc_type, exc_value, exc_traceback); + Py_XDECREF(code_object); + Py_XDECREF(py_py_line); + Py_XDECREF(py_funcname); + Py_XDECREF(dict); + Py_XDECREF(replace); + if (success) { + PyTraceBack_Here( + (struct _frame*)frame); + } + Py_XDECREF(frame); +} +#else +static PyCodeObject* __Pyx_CreateCodeObjectForTraceback( + const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = NULL; + PyObject *py_funcname = NULL; + #if PY_MAJOR_VERSION < 3 + PyObject *py_srcfile = NULL; + py_srcfile = PyString_FromString(filename); + if (!py_srcfile) goto bad; + #endif + if (c_line) { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + if (!py_funcname) goto bad; + #else + py_funcname = PyUnicode_FromFormat( "%s (%s:%d)", funcname, __pyx_cfilenm, c_line); + if (!py_funcname) goto bad; + funcname = PyUnicode_AsUTF8(py_funcname); + if (!funcname) goto bad; + #endif + } + else { + #if PY_MAJOR_VERSION < 3 + py_funcname = PyString_FromString(funcname); + if (!py_funcname) goto bad; + #endif + } + #if PY_MAJOR_VERSION < 3 + py_code = __Pyx_PyCode_New( + 0, + 0, + 0, + 0, + 0, + 0, + __pyx_empty_bytes, /*PyObject *code,*/ + __pyx_empty_tuple, /*PyObject *consts,*/ + __pyx_empty_tuple, /*PyObject *names,*/ + __pyx_empty_tuple, /*PyObject *varnames,*/ + __pyx_empty_tuple, /*PyObject *freevars,*/ + __pyx_empty_tuple, /*PyObject *cellvars,*/ + py_srcfile, /*PyObject *filename,*/ + py_funcname, /*PyObject *name,*/ + py_line, + __pyx_empty_bytes /*PyObject *lnotab*/ + ); + Py_DECREF(py_srcfile); + #else + py_code = PyCode_NewEmpty(filename, funcname, py_line); + #endif + Py_XDECREF(py_funcname); + return py_code; +bad: + Py_XDECREF(py_funcname); + #if PY_MAJOR_VERSION < 3 + Py_XDECREF(py_srcfile); + #endif + return NULL; +} +static void __Pyx_AddTraceback(const char *funcname, int c_line, + int py_line, const char *filename) { + PyCodeObject *py_code = 0; + PyFrameObject *py_frame = 0; + PyThreadState *tstate = __Pyx_PyThreadState_Current; + PyObject *ptype, *pvalue, *ptraceback; + if (c_line) { + c_line = __Pyx_CLineForTraceback(tstate, c_line); + } + py_code = __pyx_find_code_object(c_line ? -c_line : py_line); + if (!py_code) { + __Pyx_ErrFetchInState(tstate, &ptype, &pvalue, &ptraceback); + py_code = __Pyx_CreateCodeObjectForTraceback( + funcname, c_line, py_line, filename); + if (!py_code) { + /* If the code object creation fails, then we should clear the + fetched exception references and propagate the new exception */ + Py_XDECREF(ptype); + Py_XDECREF(pvalue); + Py_XDECREF(ptraceback); + goto bad; + } + __Pyx_ErrRestoreInState(tstate, ptype, pvalue, ptraceback); + __pyx_insert_code_object(c_line ? -c_line : py_line, py_code); + } + py_frame = PyFrame_New( + tstate, /*PyThreadState *tstate,*/ + py_code, /*PyCodeObject *code,*/ + __pyx_d, /*PyObject *globals,*/ + 0 /*PyObject *locals*/ + ); + if (!py_frame) goto bad; + __Pyx_PyFrame_SetLineNumber(py_frame, py_line); + PyTraceBack_Here(py_frame); +bad: + Py_XDECREF(py_code); + Py_XDECREF(py_frame); +} +#endif + +/* CIntToPy */ + static CYTHON_INLINE PyObject* __Pyx_PyInt_From_long(long value) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; + if (is_unsigned) { + if (sizeof(long) < sizeof(long)) { + return PyInt_FromLong((long) value); + } else if (sizeof(long) <= sizeof(unsigned long)) { + return PyLong_FromUnsignedLong((unsigned long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(unsigned PY_LONG_LONG)) { + return PyLong_FromUnsignedLongLong((unsigned PY_LONG_LONG) value); +#endif + } + } else { + if (sizeof(long) <= sizeof(long)) { + return PyInt_FromLong((long) value); +#ifdef HAVE_LONG_LONG + } else if (sizeof(long) <= sizeof(PY_LONG_LONG)) { + return PyLong_FromLongLong((PY_LONG_LONG) value); +#endif + } + } + { + unsigned char *bytes = (unsigned char *)&value; +#if !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX >= 0x030d00A4 + if (is_unsigned) { + return PyLong_FromUnsignedNativeBytes(bytes, sizeof(value), -1); + } else { + return PyLong_FromNativeBytes(bytes, sizeof(value), -1); + } +#elif !CYTHON_COMPILING_IN_LIMITED_API && PY_VERSION_HEX < 0x030d0000 + int one = 1; int little = (int)*(unsigned char *)&one; + return _PyLong_FromByteArray(bytes, sizeof(long), + little, !is_unsigned); +#else + int one = 1; int little = (int)*(unsigned char *)&one; + PyObject *from_bytes, *result = NULL; + PyObject *py_bytes = NULL, *arg_tuple = NULL, *kwds = NULL, *order_str = NULL; + from_bytes = PyObject_GetAttrString((PyObject*)&PyLong_Type, "from_bytes"); + if (!from_bytes) return NULL; + py_bytes = PyBytes_FromStringAndSize((char*)bytes, sizeof(long)); + if (!py_bytes) goto limited_bad; + order_str = PyUnicode_FromString(little ? "little" : "big"); + if (!order_str) goto limited_bad; + arg_tuple = PyTuple_Pack(2, py_bytes, order_str); + if (!arg_tuple) goto limited_bad; + if (!is_unsigned) { + kwds = PyDict_New(); + if (!kwds) goto limited_bad; + if (PyDict_SetItemString(kwds, "signed", __Pyx_NewRef(Py_True))) goto limited_bad; + } + result = PyObject_Call(from_bytes, arg_tuple, kwds); + limited_bad: + Py_XDECREF(kwds); + Py_XDECREF(arg_tuple); + Py_XDECREF(order_str); + Py_XDECREF(py_bytes); + Py_XDECREF(from_bytes); + return result; +#endif + } +} + +/* FormatTypeName */ + #if CYTHON_COMPILING_IN_LIMITED_API +static __Pyx_TypeName +__Pyx_PyType_GetName(PyTypeObject* tp) +{ + PyObject *name = __Pyx_PyObject_GetAttrStr((PyObject *)tp, + __pyx_n_s_name); + if (unlikely(name == NULL) || unlikely(!PyUnicode_Check(name))) { + PyErr_Clear(); + Py_XDECREF(name); + name = __Pyx_NewRef(__pyx_n_s__8); + } + return name; +} +#endif + +/* CIntFromPyVerify */ + #define __PYX_VERIFY_RETURN_INT(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 0) +#define __PYX_VERIFY_RETURN_INT_EXC(target_type, func_type, func_value)\ + __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, 1) +#define __PYX__VERIFY_RETURN_INT(target_type, func_type, func_value, exc)\ + {\ + func_type value = func_value;\ + if (sizeof(target_type) < sizeof(func_type)) {\ + if (unlikely(value != (func_type) (target_type) value)) {\ + func_type zero = 0;\ + if (exc && unlikely(value == (func_type)-1 && PyErr_Occurred()))\ + return (target_type) -1;\ + if (is_unsigned && unlikely(value < zero))\ + goto raise_neg_overflow;\ + else\ + goto raise_overflow;\ + }\ + }\ + return (target_type) value;\ + } + +/* CIntFromPy */ + static CYTHON_INLINE long __Pyx_PyInt_As_long(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const long neg_one = (long) -1, const_zero = (long) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if ((sizeof(long) < sizeof(long))) { + __PYX_VERIFY_RETURN_INT(long, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (long) val; + } + } +#endif + if (unlikely(!PyLong_Check(x))) { + long val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (long) -1; + val = __Pyx_PyInt_As_long(tmp); + Py_DECREF(tmp); + return val; + } + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + if (unlikely(__Pyx_PyLong_IsNeg(x))) { + goto raise_neg_overflow; + } else if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_DigitCount(x)) { + case 2: + if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) >= 2 * PyLong_SHIFT)) { + return (long) (((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 3: + if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) >= 3 * PyLong_SHIFT)) { + return (long) (((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + case 4: + if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) >= 4 * PyLong_SHIFT)) { + return (long) (((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0])); + } + } + break; + } + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7 + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (long) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if ((sizeof(long) <= sizeof(unsigned long))) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(long) <= sizeof(unsigned PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(long, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(long, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_SignedDigitCount(x)) { + case -2: + if ((8 * sizeof(long) - 1 > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) { + return (long) (((long)-1)*(((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 2: + if ((8 * sizeof(long) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) { + return (long) ((((((long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -3: + if ((8 * sizeof(long) - 1 > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) { + return (long) (((long)-1)*(((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 3: + if ((8 * sizeof(long) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) { + return (long) ((((((((long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case -4: + if ((8 * sizeof(long) - 1 > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) { + return (long) (((long)-1)*(((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + case 4: + if ((8 * sizeof(long) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(long, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(long) - 1 > 4 * PyLong_SHIFT)) { + return (long) ((((((((((long)digits[3]) << PyLong_SHIFT) | (long)digits[2]) << PyLong_SHIFT) | (long)digits[1]) << PyLong_SHIFT) | (long)digits[0]))); + } + } + break; + } + } +#endif + if ((sizeof(long) <= sizeof(long))) { + __PYX_VERIFY_RETURN_INT_EXC(long, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(long) <= sizeof(PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(long, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { + long val; + int ret = -1; +#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API + Py_ssize_t bytes_copied = PyLong_AsNativeBytes( + x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0)); + if (unlikely(bytes_copied == -1)) { + } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) { + goto raise_overflow; + } else { + ret = 0; + } +#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray) + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + ret = _PyLong_AsByteArray((PyLongObject *)x, + bytes, sizeof(val), + is_little, !is_unsigned); +#else + PyObject *v; + PyObject *stepval = NULL, *mask = NULL, *shift = NULL; + int bits, remaining_bits, is_negative = 0; + int chunk_size = (sizeof(long) < 8) ? 30 : 62; + if (likely(PyLong_CheckExact(x))) { + v = __Pyx_NewRef(x); + } else { + v = PyNumber_Long(x); + if (unlikely(!v)) return (long) -1; + assert(PyLong_CheckExact(v)); + } + { + int result = PyObject_RichCompareBool(v, Py_False, Py_LT); + if (unlikely(result < 0)) { + Py_DECREF(v); + return (long) -1; + } + is_negative = result == 1; + } + if (is_unsigned && unlikely(is_negative)) { + Py_DECREF(v); + goto raise_neg_overflow; + } else if (is_negative) { + stepval = PyNumber_Invert(v); + Py_DECREF(v); + if (unlikely(!stepval)) + return (long) -1; + } else { + stepval = v; + } + v = NULL; + val = (long) 0; + mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done; + shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done; + for (bits = 0; bits < (int) sizeof(long) * 8 - chunk_size; bits += chunk_size) { + PyObject *tmp, *digit; + long idigit; + digit = PyNumber_And(stepval, mask); + if (unlikely(!digit)) goto done; + idigit = PyLong_AsLong(digit); + Py_DECREF(digit); + if (unlikely(idigit < 0)) goto done; + val |= ((long) idigit) << bits; + tmp = PyNumber_Rshift(stepval, shift); + if (unlikely(!tmp)) goto done; + Py_DECREF(stepval); stepval = tmp; + } + Py_DECREF(shift); shift = NULL; + Py_DECREF(mask); mask = NULL; + { + long idigit = PyLong_AsLong(stepval); + if (unlikely(idigit < 0)) goto done; + remaining_bits = ((int) sizeof(long) * 8) - bits - (is_unsigned ? 0 : 1); + if (unlikely(idigit >= (1L << remaining_bits))) + goto raise_overflow; + val |= ((long) idigit) << bits; + } + if (!is_unsigned) { + if (unlikely(val & (((long) 1) << (sizeof(long) * 8 - 1)))) + goto raise_overflow; + if (is_negative) + val = ~val; + } + ret = 0; + done: + Py_XDECREF(shift); + Py_XDECREF(mask); + Py_XDECREF(stepval); +#endif + if (unlikely(ret)) + return (long) -1; + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to long"); + return (long) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to long"); + return (long) -1; +} + +/* CIntFromPy */ + static CYTHON_INLINE int __Pyx_PyInt_As_int(PyObject *x) { +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wconversion" +#endif + const int neg_one = (int) -1, const_zero = (int) 0; +#ifdef __Pyx_HAS_GCC_DIAGNOSTIC +#pragma GCC diagnostic pop +#endif + const int is_unsigned = neg_one > const_zero; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x))) { + if ((sizeof(int) < sizeof(long))) { + __PYX_VERIFY_RETURN_INT(int, long, PyInt_AS_LONG(x)) + } else { + long val = PyInt_AS_LONG(x); + if (is_unsigned && unlikely(val < 0)) { + goto raise_neg_overflow; + } + return (int) val; + } + } +#endif + if (unlikely(!PyLong_Check(x))) { + int val; + PyObject *tmp = __Pyx_PyNumber_IntOrLong(x); + if (!tmp) return (int) -1; + val = __Pyx_PyInt_As_int(tmp); + Py_DECREF(tmp); + return val; + } + if (is_unsigned) { +#if CYTHON_USE_PYLONG_INTERNALS + if (unlikely(__Pyx_PyLong_IsNeg(x))) { + goto raise_neg_overflow; + } else if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_upylong, __Pyx_PyLong_CompactValueUnsigned(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_DigitCount(x)) { + case 2: + if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) >= 2 * PyLong_SHIFT)) { + return (int) (((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 3: + if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) >= 3 * PyLong_SHIFT)) { + return (int) (((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + case 4: + if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) >= 4 * PyLong_SHIFT)) { + return (int) (((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0])); + } + } + break; + } + } +#endif +#if CYTHON_COMPILING_IN_CPYTHON && PY_VERSION_HEX < 0x030C00A7 + if (unlikely(Py_SIZE(x) < 0)) { + goto raise_neg_overflow; + } +#else + { + int result = PyObject_RichCompareBool(x, Py_False, Py_LT); + if (unlikely(result < 0)) + return (int) -1; + if (unlikely(result == 1)) + goto raise_neg_overflow; + } +#endif + if ((sizeof(int) <= sizeof(unsigned long))) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned long, PyLong_AsUnsignedLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(int) <= sizeof(unsigned PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(int, unsigned PY_LONG_LONG, PyLong_AsUnsignedLongLong(x)) +#endif + } + } else { +#if CYTHON_USE_PYLONG_INTERNALS + if (__Pyx_PyLong_IsCompact(x)) { + __PYX_VERIFY_RETURN_INT(int, __Pyx_compact_pylong, __Pyx_PyLong_CompactValue(x)) + } else { + const digit* digits = __Pyx_PyLong_Digits(x); + assert(__Pyx_PyLong_DigitCount(x) > 1); + switch (__Pyx_PyLong_SignedDigitCount(x)) { + case -2: + if ((8 * sizeof(int) - 1 > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) { + return (int) (((int)-1)*(((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 2: + if ((8 * sizeof(int) > 1 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 2 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) { + return (int) ((((((int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -3: + if ((8 * sizeof(int) - 1 > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) { + return (int) (((int)-1)*(((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 3: + if ((8 * sizeof(int) > 2 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 3 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) { + return (int) ((((((((int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case -4: + if ((8 * sizeof(int) - 1 > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, long, -(long) (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) { + return (int) (((int)-1)*(((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + case 4: + if ((8 * sizeof(int) > 3 * PyLong_SHIFT)) { + if ((8 * sizeof(unsigned long) > 4 * PyLong_SHIFT)) { + __PYX_VERIFY_RETURN_INT(int, unsigned long, (((((((((unsigned long)digits[3]) << PyLong_SHIFT) | (unsigned long)digits[2]) << PyLong_SHIFT) | (unsigned long)digits[1]) << PyLong_SHIFT) | (unsigned long)digits[0]))) + } else if ((8 * sizeof(int) - 1 > 4 * PyLong_SHIFT)) { + return (int) ((((((((((int)digits[3]) << PyLong_SHIFT) | (int)digits[2]) << PyLong_SHIFT) | (int)digits[1]) << PyLong_SHIFT) | (int)digits[0]))); + } + } + break; + } + } +#endif + if ((sizeof(int) <= sizeof(long))) { + __PYX_VERIFY_RETURN_INT_EXC(int, long, PyLong_AsLong(x)) +#ifdef HAVE_LONG_LONG + } else if ((sizeof(int) <= sizeof(PY_LONG_LONG))) { + __PYX_VERIFY_RETURN_INT_EXC(int, PY_LONG_LONG, PyLong_AsLongLong(x)) +#endif + } + } + { + int val; + int ret = -1; +#if PY_VERSION_HEX >= 0x030d00A6 && !CYTHON_COMPILING_IN_LIMITED_API + Py_ssize_t bytes_copied = PyLong_AsNativeBytes( + x, &val, sizeof(val), Py_ASNATIVEBYTES_NATIVE_ENDIAN | (is_unsigned ? Py_ASNATIVEBYTES_UNSIGNED_BUFFER | Py_ASNATIVEBYTES_REJECT_NEGATIVE : 0)); + if (unlikely(bytes_copied == -1)) { + } else if (unlikely(bytes_copied > (Py_ssize_t) sizeof(val))) { + goto raise_overflow; + } else { + ret = 0; + } +#elif PY_VERSION_HEX < 0x030d0000 && !(CYTHON_COMPILING_IN_PYPY || CYTHON_COMPILING_IN_LIMITED_API) || defined(_PyLong_AsByteArray) + int one = 1; int is_little = (int)*(unsigned char *)&one; + unsigned char *bytes = (unsigned char *)&val; + ret = _PyLong_AsByteArray((PyLongObject *)x, + bytes, sizeof(val), + is_little, !is_unsigned); +#else + PyObject *v; + PyObject *stepval = NULL, *mask = NULL, *shift = NULL; + int bits, remaining_bits, is_negative = 0; + int chunk_size = (sizeof(long) < 8) ? 30 : 62; + if (likely(PyLong_CheckExact(x))) { + v = __Pyx_NewRef(x); + } else { + v = PyNumber_Long(x); + if (unlikely(!v)) return (int) -1; + assert(PyLong_CheckExact(v)); + } + { + int result = PyObject_RichCompareBool(v, Py_False, Py_LT); + if (unlikely(result < 0)) { + Py_DECREF(v); + return (int) -1; + } + is_negative = result == 1; + } + if (is_unsigned && unlikely(is_negative)) { + Py_DECREF(v); + goto raise_neg_overflow; + } else if (is_negative) { + stepval = PyNumber_Invert(v); + Py_DECREF(v); + if (unlikely(!stepval)) + return (int) -1; + } else { + stepval = v; + } + v = NULL; + val = (int) 0; + mask = PyLong_FromLong((1L << chunk_size) - 1); if (unlikely(!mask)) goto done; + shift = PyLong_FromLong(chunk_size); if (unlikely(!shift)) goto done; + for (bits = 0; bits < (int) sizeof(int) * 8 - chunk_size; bits += chunk_size) { + PyObject *tmp, *digit; + long idigit; + digit = PyNumber_And(stepval, mask); + if (unlikely(!digit)) goto done; + idigit = PyLong_AsLong(digit); + Py_DECREF(digit); + if (unlikely(idigit < 0)) goto done; + val |= ((int) idigit) << bits; + tmp = PyNumber_Rshift(stepval, shift); + if (unlikely(!tmp)) goto done; + Py_DECREF(stepval); stepval = tmp; + } + Py_DECREF(shift); shift = NULL; + Py_DECREF(mask); mask = NULL; + { + long idigit = PyLong_AsLong(stepval); + if (unlikely(idigit < 0)) goto done; + remaining_bits = ((int) sizeof(int) * 8) - bits - (is_unsigned ? 0 : 1); + if (unlikely(idigit >= (1L << remaining_bits))) + goto raise_overflow; + val |= ((int) idigit) << bits; + } + if (!is_unsigned) { + if (unlikely(val & (((int) 1) << (sizeof(int) * 8 - 1)))) + goto raise_overflow; + if (is_negative) + val = ~val; + } + ret = 0; + done: + Py_XDECREF(shift); + Py_XDECREF(mask); + Py_XDECREF(stepval); +#endif + if (unlikely(ret)) + return (int) -1; + return val; + } +raise_overflow: + PyErr_SetString(PyExc_OverflowError, + "value too large to convert to int"); + return (int) -1; +raise_neg_overflow: + PyErr_SetString(PyExc_OverflowError, + "can't convert negative value to int"); + return (int) -1; +} + +/* FastTypeChecks */ + #if CYTHON_COMPILING_IN_CPYTHON +static int __Pyx_InBases(PyTypeObject *a, PyTypeObject *b) { + while (a) { + a = __Pyx_PyType_GetSlot(a, tp_base, PyTypeObject*); + if (a == b) + return 1; + } + return b == &PyBaseObject_Type; +} +static CYTHON_INLINE int __Pyx_IsSubtype(PyTypeObject *a, PyTypeObject *b) { + PyObject *mro; + if (a == b) return 1; + mro = a->tp_mro; + if (likely(mro)) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + if (PyTuple_GET_ITEM(mro, i) == (PyObject *)b) + return 1; + } + return 0; + } + return __Pyx_InBases(a, b); +} +static CYTHON_INLINE int __Pyx_IsAnySubtype2(PyTypeObject *cls, PyTypeObject *a, PyTypeObject *b) { + PyObject *mro; + if (cls == a || cls == b) return 1; + mro = cls->tp_mro; + if (likely(mro)) { + Py_ssize_t i, n; + n = PyTuple_GET_SIZE(mro); + for (i = 0; i < n; i++) { + PyObject *base = PyTuple_GET_ITEM(mro, i); + if (base == (PyObject *)a || base == (PyObject *)b) + return 1; + } + return 0; + } + return __Pyx_InBases(cls, a) || __Pyx_InBases(cls, b); +} +#if PY_MAJOR_VERSION == 2 +static int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject* exc_type2) { + PyObject *exception, *value, *tb; + int res; + __Pyx_PyThreadState_declare + __Pyx_PyThreadState_assign + __Pyx_ErrFetch(&exception, &value, &tb); + res = exc_type1 ? PyObject_IsSubclass(err, exc_type1) : 0; + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + if (!res) { + res = PyObject_IsSubclass(err, exc_type2); + if (unlikely(res == -1)) { + PyErr_WriteUnraisable(err); + res = 0; + } + } + __Pyx_ErrRestore(exception, value, tb); + return res; +} +#else +static CYTHON_INLINE int __Pyx_inner_PyErr_GivenExceptionMatches2(PyObject *err, PyObject* exc_type1, PyObject *exc_type2) { + if (exc_type1) { + return __Pyx_IsAnySubtype2((PyTypeObject*)err, (PyTypeObject*)exc_type1, (PyTypeObject*)exc_type2); + } else { + return __Pyx_IsSubtype((PyTypeObject*)err, (PyTypeObject*)exc_type2); + } +} +#endif +static int __Pyx_PyErr_GivenExceptionMatchesTuple(PyObject *exc_type, PyObject *tuple) { + Py_ssize_t i, n; + assert(PyExceptionClass_Check(exc_type)); + n = PyTuple_GET_SIZE(tuple); +#if PY_MAJOR_VERSION >= 3 + for (i=0; i= 0x030B00A4 + return Py_Version & ~0xFFUL; +#else + const char* rt_version = Py_GetVersion(); + unsigned long version = 0; + unsigned long factor = 0x01000000UL; + unsigned int digit = 0; + int i = 0; + while (factor) { + while ('0' <= rt_version[i] && rt_version[i] <= '9') { + digit = digit * 10 + (unsigned int) (rt_version[i] - '0'); + ++i; + } + version += factor * digit; + if (rt_version[i] != '.') + break; + digit = 0; + factor >>= 8; + ++i; + } + return version; +#endif +} +static int __Pyx_check_binary_version(unsigned long ct_version, unsigned long rt_version, int allow_newer) { + const unsigned long MAJOR_MINOR = 0xFFFF0000UL; + if ((rt_version & MAJOR_MINOR) == (ct_version & MAJOR_MINOR)) + return 0; + if (likely(allow_newer && (rt_version & MAJOR_MINOR) > (ct_version & MAJOR_MINOR))) + return 1; + { + char message[200]; + PyOS_snprintf(message, sizeof(message), + "compile time Python version %d.%d " + "of module '%.100s' " + "%s " + "runtime version %d.%d", + (int) (ct_version >> 24), (int) ((ct_version >> 16) & 0xFF), + __Pyx_MODULE_NAME, + (allow_newer) ? "was newer than" : "does not match", + (int) (rt_version >> 24), (int) ((rt_version >> 16) & 0xFF) + ); + return PyErr_WarnEx(NULL, message, 1); + } +} + +/* InitStrings */ + #if PY_MAJOR_VERSION >= 3 +static int __Pyx_InitString(__Pyx_StringTabEntry t, PyObject **str) { + if (t.is_unicode | t.is_str) { + if (t.intern) { + *str = PyUnicode_InternFromString(t.s); + } else if (t.encoding) { + *str = PyUnicode_Decode(t.s, t.n - 1, t.encoding, NULL); + } else { + *str = PyUnicode_FromStringAndSize(t.s, t.n - 1); + } + } else { + *str = PyBytes_FromStringAndSize(t.s, t.n - 1); + } + if (!*str) + return -1; + if (PyObject_Hash(*str) == -1) + return -1; + return 0; +} +#endif +static int __Pyx_InitStrings(__Pyx_StringTabEntry *t) { + while (t->p) { + #if PY_MAJOR_VERSION >= 3 + __Pyx_InitString(*t, t->p); + #else + if (t->is_unicode) { + *t->p = PyUnicode_DecodeUTF8(t->s, t->n - 1, NULL); + } else if (t->intern) { + *t->p = PyString_InternFromString(t->s); + } else { + *t->p = PyString_FromStringAndSize(t->s, t->n - 1); + } + if (!*t->p) + return -1; + if (PyObject_Hash(*t->p) == -1) + return -1; + #endif + ++t; + } + return 0; +} + +#include +static CYTHON_INLINE Py_ssize_t __Pyx_ssize_strlen(const char *s) { + size_t len = strlen(s); + if (unlikely(len > (size_t) PY_SSIZE_T_MAX)) { + PyErr_SetString(PyExc_OverflowError, "byte string is too long"); + return -1; + } + return (Py_ssize_t) len; +} +static CYTHON_INLINE PyObject* __Pyx_PyUnicode_FromString(const char* c_str) { + Py_ssize_t len = __Pyx_ssize_strlen(c_str); + if (unlikely(len < 0)) return NULL; + return __Pyx_PyUnicode_FromStringAndSize(c_str, len); +} +static CYTHON_INLINE PyObject* __Pyx_PyByteArray_FromString(const char* c_str) { + Py_ssize_t len = __Pyx_ssize_strlen(c_str); + if (unlikely(len < 0)) return NULL; + return PyByteArray_FromStringAndSize(c_str, len); +} +static CYTHON_INLINE const char* __Pyx_PyObject_AsString(PyObject* o) { + Py_ssize_t ignore; + return __Pyx_PyObject_AsStringAndSize(o, &ignore); +} +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT +#if !CYTHON_PEP393_ENABLED +static const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + char* defenc_c; + PyObject* defenc = _PyUnicode_AsDefaultEncodedString(o, NULL); + if (!defenc) return NULL; + defenc_c = PyBytes_AS_STRING(defenc); +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + { + char* end = defenc_c + PyBytes_GET_SIZE(defenc); + char* c; + for (c = defenc_c; c < end; c++) { + if ((unsigned char) (*c) >= 128) { + PyUnicode_AsASCIIString(o); + return NULL; + } + } + } +#endif + *length = PyBytes_GET_SIZE(defenc); + return defenc_c; +} +#else +static CYTHON_INLINE const char* __Pyx_PyUnicode_AsStringAndSize(PyObject* o, Py_ssize_t *length) { + if (unlikely(__Pyx_PyUnicode_READY(o) == -1)) return NULL; +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + if (likely(PyUnicode_IS_ASCII(o))) { + *length = PyUnicode_GET_LENGTH(o); + return PyUnicode_AsUTF8(o); + } else { + PyUnicode_AsASCIIString(o); + return NULL; + } +#else + return PyUnicode_AsUTF8AndSize(o, length); +#endif +} +#endif +#endif +static CYTHON_INLINE const char* __Pyx_PyObject_AsStringAndSize(PyObject* o, Py_ssize_t *length) { +#if __PYX_DEFAULT_STRING_ENCODING_IS_ASCII || __PYX_DEFAULT_STRING_ENCODING_IS_DEFAULT + if ( +#if PY_MAJOR_VERSION < 3 && __PYX_DEFAULT_STRING_ENCODING_IS_ASCII + __Pyx_sys_getdefaultencoding_not_ascii && +#endif + PyUnicode_Check(o)) { + return __Pyx_PyUnicode_AsStringAndSize(o, length); + } else +#endif +#if (!CYTHON_COMPILING_IN_PYPY && !CYTHON_COMPILING_IN_LIMITED_API) || (defined(PyByteArray_AS_STRING) && defined(PyByteArray_GET_SIZE)) + if (PyByteArray_Check(o)) { + *length = PyByteArray_GET_SIZE(o); + return PyByteArray_AS_STRING(o); + } else +#endif + { + char* result; + int r = PyBytes_AsStringAndSize(o, &result, length); + if (unlikely(r < 0)) { + return NULL; + } else { + return result; + } + } +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrue(PyObject* x) { + int is_true = x == Py_True; + if (is_true | (x == Py_False) | (x == Py_None)) return is_true; + else return PyObject_IsTrue(x); +} +static CYTHON_INLINE int __Pyx_PyObject_IsTrueAndDecref(PyObject* x) { + int retval; + if (unlikely(!x)) return -1; + retval = __Pyx_PyObject_IsTrue(x); + Py_DECREF(x); + return retval; +} +static PyObject* __Pyx_PyNumber_IntOrLongWrongResultType(PyObject* result, const char* type_name) { + __Pyx_TypeName result_type_name = __Pyx_PyType_GetName(Py_TYPE(result)); +#if PY_MAJOR_VERSION >= 3 + if (PyLong_Check(result)) { + if (PyErr_WarnFormat(PyExc_DeprecationWarning, 1, + "__int__ returned non-int (type " __Pyx_FMT_TYPENAME "). " + "The ability to return an instance of a strict subclass of int is deprecated, " + "and may be removed in a future version of Python.", + result_type_name)) { + __Pyx_DECREF_TypeName(result_type_name); + Py_DECREF(result); + return NULL; + } + __Pyx_DECREF_TypeName(result_type_name); + return result; + } +#endif + PyErr_Format(PyExc_TypeError, + "__%.4s__ returned non-%.4s (type " __Pyx_FMT_TYPENAME ")", + type_name, type_name, result_type_name); + __Pyx_DECREF_TypeName(result_type_name); + Py_DECREF(result); + return NULL; +} +static CYTHON_INLINE PyObject* __Pyx_PyNumber_IntOrLong(PyObject* x) { +#if CYTHON_USE_TYPE_SLOTS + PyNumberMethods *m; +#endif + const char *name = NULL; + PyObject *res = NULL; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_Check(x) || PyLong_Check(x))) +#else + if (likely(PyLong_Check(x))) +#endif + return __Pyx_NewRef(x); +#if CYTHON_USE_TYPE_SLOTS + m = Py_TYPE(x)->tp_as_number; + #if PY_MAJOR_VERSION < 3 + if (m && m->nb_int) { + name = "int"; + res = m->nb_int(x); + } + else if (m && m->nb_long) { + name = "long"; + res = m->nb_long(x); + } + #else + if (likely(m && m->nb_int)) { + name = "int"; + res = m->nb_int(x); + } + #endif +#else + if (!PyBytes_CheckExact(x) && !PyUnicode_CheckExact(x)) { + res = PyNumber_Int(x); + } +#endif + if (likely(res)) { +#if PY_MAJOR_VERSION < 3 + if (unlikely(!PyInt_Check(res) && !PyLong_Check(res))) { +#else + if (unlikely(!PyLong_CheckExact(res))) { +#endif + return __Pyx_PyNumber_IntOrLongWrongResultType(res, name); + } + } + else if (!PyErr_Occurred()) { + PyErr_SetString(PyExc_TypeError, + "an integer is required"); + } + return res; +} +static CYTHON_INLINE Py_ssize_t __Pyx_PyIndex_AsSsize_t(PyObject* b) { + Py_ssize_t ival; + PyObject *x; +#if PY_MAJOR_VERSION < 3 + if (likely(PyInt_CheckExact(b))) { + if (sizeof(Py_ssize_t) >= sizeof(long)) + return PyInt_AS_LONG(b); + else + return PyInt_AsSsize_t(b); + } +#endif + if (likely(PyLong_CheckExact(b))) { + #if CYTHON_USE_PYLONG_INTERNALS + if (likely(__Pyx_PyLong_IsCompact(b))) { + return __Pyx_PyLong_CompactValue(b); + } else { + const digit* digits = __Pyx_PyLong_Digits(b); + const Py_ssize_t size = __Pyx_PyLong_SignedDigitCount(b); + switch (size) { + case 2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return (Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -2: + if (8 * sizeof(Py_ssize_t) > 2 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -3: + if (8 * sizeof(Py_ssize_t) > 3 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case 4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return (Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + case -4: + if (8 * sizeof(Py_ssize_t) > 4 * PyLong_SHIFT) { + return -(Py_ssize_t) (((((((((size_t)digits[3]) << PyLong_SHIFT) | (size_t)digits[2]) << PyLong_SHIFT) | (size_t)digits[1]) << PyLong_SHIFT) | (size_t)digits[0])); + } + break; + } + } + #endif + return PyLong_AsSsize_t(b); + } + x = PyNumber_Index(b); + if (!x) return -1; + ival = PyInt_AsSsize_t(x); + Py_DECREF(x); + return ival; +} +static CYTHON_INLINE Py_hash_t __Pyx_PyIndex_AsHash_t(PyObject* o) { + if (sizeof(Py_hash_t) == sizeof(Py_ssize_t)) { + return (Py_hash_t) __Pyx_PyIndex_AsSsize_t(o); +#if PY_MAJOR_VERSION < 3 + } else if (likely(PyInt_CheckExact(o))) { + return PyInt_AS_LONG(o); +#endif + } else { + Py_ssize_t ival; + PyObject *x; + x = PyNumber_Index(o); + if (!x) return -1; + ival = PyInt_AsLong(x); + Py_DECREF(x); + return ival; + } +} +static CYTHON_INLINE PyObject * __Pyx_PyBool_FromLong(long b) { + return b ? __Pyx_NewRef(Py_True) : __Pyx_NewRef(Py_False); +} +static CYTHON_INLINE PyObject * __Pyx_PyInt_FromSize_t(size_t ival) { + return PyInt_FromSize_t(ival); +} + + +/* #### Code section: utility_code_pragmas_end ### */ +#ifdef _MSC_VER +#pragma warning( pop ) +#endif + + + +/* #### Code section: end ### */ +#endif /* Py_PYTHON_H */ diff --git a/core/feature_manager.py b/bot/core/feature_manager.py similarity index 100% rename from core/feature_manager.py rename to bot/core/feature_manager.py diff --git a/data/config.py b/bot/data/config.py similarity index 100% rename from data/config.py rename to bot/data/config.py diff --git a/db/database.py b/bot/db/database.py similarity index 100% rename from db/database.py rename to bot/db/database.py diff --git a/filters/admin.py b/bot/filters/admin.py similarity index 100% rename from filters/admin.py rename to bot/filters/admin.py diff --git a/function/function.py b/bot/function/function.py similarity index 100% rename from function/function.py rename to bot/function/function.py diff --git a/function/send_ads.py b/bot/function/send_ads.py similarity index 100% rename from function/send_ads.py rename to bot/function/send_ads.py diff --git a/handlers/__init__.py b/bot/handlers/__init__.py similarity index 100% rename from handlers/__init__.py rename to bot/handlers/__init__.py diff --git a/handlers/admins/admin_settings/add_admin.py b/bot/handlers/admins/admin_settings/add_admin.py similarity index 99% rename from handlers/admins/admin_settings/add_admin.py rename to bot/handlers/admins/admin_settings/add_admin.py index 641137c..7de4131 100755 --- a/handlers/admins/admin_settings/add_admin.py +++ b/bot/handlers/admins/admin_settings/add_admin.py @@ -2,7 +2,7 @@ from aiogram import types from aiogram.fsm.context import FSMContext from filters.admin import IsAdmin, SelectAdmin -from function.translator import translator +from api.translator import translator from keyboards.inline.admin_btn import admin_setting from keyboards.inline.close_btn import close_btn from loader import dp, bot, db diff --git a/handlers/admins/admin_settings/add_admin_first_step.py b/bot/handlers/admins/admin_settings/add_admin_first_step.py similarity index 98% rename from handlers/admins/admin_settings/add_admin_first_step.py rename to bot/handlers/admins/admin_settings/add_admin_first_step.py index b362506..9123a1e 100755 --- a/handlers/admins/admin_settings/add_admin_first_step.py +++ b/bot/handlers/admins/admin_settings/add_admin_first_step.py @@ -2,7 +2,7 @@ from aiogram import types, F from aiogram.fsm.context import FSMContext from filters.admin import IsAdmin, SelectAdmin -from function.translator import translator +from api.translator import translator from keyboards.inline.admin_btn import admin_setting from keyboards.inline.button import AdminCallback from keyboards.inline.close_btn import close_btn diff --git a/handlers/admins/admin_settings/admin_setting.py b/bot/handlers/admins/admin_settings/admin_setting.py similarity index 98% rename from handlers/admins/admin_settings/admin_setting.py rename to bot/handlers/admins/admin_settings/admin_setting.py index 83a9b3e..d034d9c 100755 --- a/handlers/admins/admin_settings/admin_setting.py +++ b/bot/handlers/admins/admin_settings/admin_setting.py @@ -2,7 +2,7 @@ from aiogram import types, F from aiogram.fsm.context import FSMContext from filters.admin import IsAdmin, SelectAdmin -from function.translator import translator +from api.translator import translator from keyboards.inline.admin_btn import admin_setting from keyboards.inline.button import AdminCallback from keyboards.inline.close_btn import close_btn diff --git a/handlers/admins/admin_settings/attach_admins.py b/bot/handlers/admins/admin_settings/attach_admins.py similarity index 99% rename from handlers/admins/admin_settings/attach_admins.py rename to bot/handlers/admins/admin_settings/attach_admins.py index fb03c68..563c43a 100755 --- a/handlers/admins/admin_settings/attach_admins.py +++ b/bot/handlers/admins/admin_settings/attach_admins.py @@ -4,7 +4,7 @@ from data.config import ADMIN from filters.admin import IsAdmin, SelectAdmin from function.function import x_or_y -from function.translator import translator +from api.translator import translator from keyboards.inline.admin_btn import attach_admin_btn from keyboards.inline.button import AdminSetting from keyboards.inline.close_btn import close_btn diff --git a/handlers/admins/admin_settings/edit_admin.py b/bot/handlers/admins/admin_settings/edit_admin.py similarity index 99% rename from handlers/admins/admin_settings/edit_admin.py rename to bot/handlers/admins/admin_settings/edit_admin.py index 0e66be4..c1a38e5 100755 --- a/handlers/admins/admin_settings/edit_admin.py +++ b/bot/handlers/admins/admin_settings/edit_admin.py @@ -4,7 +4,7 @@ from data.config import ADMIN from filters.admin import IsAdmin, SelectAdmin from function.function import x_or_y -from function.translator import translator +from api.translator import translator from keyboards.inline.close_btn import close_btn from loader import dp, bot, db from states.admin_state import AdminState diff --git a/handlers/admins/callback_query/main_admin_panel.py b/bot/handlers/admins/callback_query/main_admin_panel.py similarity index 98% rename from handlers/admins/callback_query/main_admin_panel.py rename to bot/handlers/admins/callback_query/main_admin_panel.py index 42571f1..031d615 100755 --- a/handlers/admins/callback_query/main_admin_panel.py +++ b/bot/handlers/admins/callback_query/main_admin_panel.py @@ -5,7 +5,7 @@ from keyboards.inline.admin_btn import main_admin_panel_btn from filters.admin import IsAdmin from aiogram.fsm.context import FSMContext -from function.translator import translator +from api.translator import translator @dp.callback_query(AdminCallback.filter(F.action == "main_adm_panel"), IsAdmin()) diff --git a/handlers/admins/channel_settings/add_channel.py b/bot/handlers/admins/channel_settings/add_channel.py similarity index 98% rename from handlers/admins/channel_settings/add_channel.py rename to bot/handlers/admins/channel_settings/add_channel.py index ec882e0..895a85b 100755 --- a/handlers/admins/channel_settings/add_channel.py +++ b/bot/handlers/admins/channel_settings/add_channel.py @@ -5,7 +5,7 @@ from keyboards.inline.close_btn import close_btn from filters.admin import IsAdmin, SelectAdmin from aiogram.fsm.context import FSMContext -from function.translator import translator +from api.translator import translator from states.admin_state import AdminState @dp.callback_query(AdminCallback.filter(F.action == "add_channel"), IsAdmin()) diff --git a/handlers/admins/channel_settings/channel_setting.py b/bot/handlers/admins/channel_settings/channel_setting.py similarity index 99% rename from handlers/admins/channel_settings/channel_setting.py rename to bot/handlers/admins/channel_settings/channel_setting.py index cc91e49..33b5d9a 100755 --- a/handlers/admins/channel_settings/channel_setting.py +++ b/bot/handlers/admins/channel_settings/channel_setting.py @@ -6,7 +6,7 @@ from keyboards.inline.close_btn import close_btn from filters.admin import IsAdmin, SelectAdmin from aiogram.fsm.context import FSMContext -from function.translator import translator +from api.translator import translator from data.config import ADMIN diff --git a/handlers/admins/channel_settings/delete_channel.py b/bot/handlers/admins/channel_settings/delete_channel.py similarity index 99% rename from handlers/admins/channel_settings/delete_channel.py rename to bot/handlers/admins/channel_settings/delete_channel.py index 802f9f2..1c464ee 100755 --- a/handlers/admins/channel_settings/delete_channel.py +++ b/bot/handlers/admins/channel_settings/delete_channel.py @@ -5,7 +5,7 @@ from keyboards.inline.close_btn import close_btn from filters.admin import IsAdmin, SelectAdmin from aiogram.fsm.context import FSMContext -from function.translator import translator +from api.translator import translator from data.config import ADMIN @dp.callback_query(IsAdmin(), AdminCallback.filter(F.action == "delete_channel")) diff --git a/handlers/admins/channel_settings/get_id.py b/bot/handlers/admins/channel_settings/get_id.py similarity index 99% rename from handlers/admins/channel_settings/get_id.py rename to bot/handlers/admins/channel_settings/get_id.py index c3ab59f..a3e1d58 100755 --- a/handlers/admins/channel_settings/get_id.py +++ b/bot/handlers/admins/channel_settings/get_id.py @@ -5,7 +5,7 @@ from keyboards.inline.close_btn import close_btn from filters.admin import IsAdmin, SelectAdmin from aiogram.fsm.context import FSMContext -from function.translator import translator +from api.translator import translator from states.admin_state import AdminState from data.config import yil_oy_kun, soat_minut_sekund diff --git a/handlers/admins/channel_settings/mandatory_membership.py b/bot/handlers/admins/channel_settings/mandatory_membership.py similarity index 98% rename from handlers/admins/channel_settings/mandatory_membership.py rename to bot/handlers/admins/channel_settings/mandatory_membership.py index 45e1444..8b60680 100755 --- a/handlers/admins/channel_settings/mandatory_membership.py +++ b/bot/handlers/admins/channel_settings/mandatory_membership.py @@ -6,7 +6,7 @@ from keyboards.inline.close_btn import close_btn from filters.admin import IsAdmin, SelectAdmin from aiogram.fsm.context import FSMContext -from function.translator import translator +from api.translator import translator @dp.callback_query(AdminCallback.filter(F.action == "mandatory_membership"), IsAdmin()) diff --git a/handlers/admins/channel_settings/remove_channel.py b/bot/handlers/admins/channel_settings/remove_channel.py similarity index 99% rename from handlers/admins/channel_settings/remove_channel.py rename to bot/handlers/admins/channel_settings/remove_channel.py index 4604e07..1da271e 100755 --- a/handlers/admins/channel_settings/remove_channel.py +++ b/bot/handlers/admins/channel_settings/remove_channel.py @@ -6,7 +6,7 @@ from keyboards.inline.admin_btn import main_btn from filters.admin import IsAdmin, SelectAdmin from aiogram.fsm.context import FSMContext -from function.translator import translator +from api.translator import translator from data.config import ADMIN from aiogram.utils.keyboard import InlineKeyboardBuilder diff --git a/handlers/admins/check_usr/attach_usr.py b/bot/handlers/admins/check_usr/attach_usr.py similarity index 99% rename from handlers/admins/check_usr/attach_usr.py rename to bot/handlers/admins/check_usr/attach_usr.py index 16f64ad..8a09083 100755 --- a/handlers/admins/check_usr/attach_usr.py +++ b/bot/handlers/admins/check_usr/attach_usr.py @@ -5,7 +5,7 @@ from keyboards.inline.admin_btn import block_user from filters.admin import IsAdmin, SelectAdmin from aiogram.fsm.context import FSMContext -from function.translator import translator +from api.translator import translator from states.admin_state import AdminState diff --git a/handlers/admins/check_usr/block_users.py b/bot/handlers/admins/check_usr/block_users.py similarity index 99% rename from handlers/admins/check_usr/block_users.py rename to bot/handlers/admins/check_usr/block_users.py index 3337428..73dcf0d 100755 --- a/handlers/admins/check_usr/block_users.py +++ b/bot/handlers/admins/check_usr/block_users.py @@ -5,7 +5,7 @@ from keyboards.inline.close_btn import close_btn from filters.admin import IsAdmin, SelectAdmin from aiogram.fsm.context import FSMContext -from function.translator import translator +from api.translator import translator from states.admin_state import AdminState from data.config import ADMIN diff --git a/handlers/admins/check_usr/check_usr.py b/bot/handlers/admins/check_usr/check_usr.py similarity index 98% rename from handlers/admins/check_usr/check_usr.py rename to bot/handlers/admins/check_usr/check_usr.py index c426b1c..df46c9e 100755 --- a/handlers/admins/check_usr/check_usr.py +++ b/bot/handlers/admins/check_usr/check_usr.py @@ -5,7 +5,7 @@ from keyboards.inline.close_btn import close_btn from filters.admin import IsAdmin, SelectAdmin from aiogram.fsm.context import FSMContext -from function.translator import translator +from api.translator import translator from states.admin_state import AdminState @dp.callback_query(AdminCallback.filter(F.action == "check_user"), IsAdmin()) diff --git a/handlers/admins/check_usr/send_ads_message.py b/bot/handlers/admins/check_usr/send_ads_message.py similarity index 98% rename from handlers/admins/check_usr/send_ads_message.py rename to bot/handlers/admins/check_usr/send_ads_message.py index c05c312..6f212ef 100755 --- a/handlers/admins/check_usr/send_ads_message.py +++ b/bot/handlers/admins/check_usr/send_ads_message.py @@ -4,7 +4,7 @@ from keyboards.inline.close_btn import close_btn from filters.admin import IsAdmin, SelectAdmin from aiogram.fsm.context import FSMContext -from function.translator import translator +from api.translator import translator from states.admin_state import AdminState @dp.message(AdminState.send_message_to_user, IsAdmin()) diff --git a/handlers/admins/check_usr/send_message.py b/bot/handlers/admins/check_usr/send_message.py similarity index 98% rename from handlers/admins/check_usr/send_message.py rename to bot/handlers/admins/check_usr/send_message.py index 6cf0309..72d0ea1 100755 --- a/handlers/admins/check_usr/send_message.py +++ b/bot/handlers/admins/check_usr/send_message.py @@ -5,7 +5,7 @@ from keyboards.inline.close_btn import close_btn from filters.admin import IsAdmin, SelectAdmin from aiogram.fsm.context import FSMContext -from function.translator import translator +from api.translator import translator from states.admin_state import AdminState @dp.callback_query(IsAdmin(), BlockUser.filter(F.action == "send_message")) diff --git a/handlers/admins/main_panel.py b/bot/handlers/admins/main_panel.py similarity index 98% rename from handlers/admins/main_panel.py rename to bot/handlers/admins/main_panel.py index a5924eb..6ac331b 100755 --- a/handlers/admins/main_panel.py +++ b/bot/handlers/admins/main_panel.py @@ -5,7 +5,7 @@ from keyboards.inline.admin_btn import main_admin_panel_btn from filters.admin import IsAdmin from aiogram.fsm.context import FSMContext -from function.translator import translator +from api.translator import translator @dp.message(Command(commands='admin'), IsAdmin()) diff --git a/handlers/admins/send_ads/get_message.py b/bot/handlers/admins/send_ads/get_message.py similarity index 99% rename from handlers/admins/send_ads/get_message.py rename to bot/handlers/admins/send_ads/get_message.py index 3a312aa..6a63189 100755 --- a/handlers/admins/send_ads/get_message.py +++ b/bot/handlers/admins/send_ads/get_message.py @@ -5,7 +5,7 @@ from aiogram.fsm.context import FSMContext from concurrent.futures import ProcessPoolExecutor from filters.admin import SelectAdmin, IsAdmin -from function.translator import translator +from api.translator import translator from keyboards.inline.admin_btn import main_admin_panel_btn, stop_advertisement from keyboards.inline.close_btn import close_btn from loader import dp, db, bot, file_db diff --git a/handlers/admins/send_ads/send_ads.py b/bot/handlers/admins/send_ads/send_ads.py similarity index 99% rename from handlers/admins/send_ads/send_ads.py rename to bot/handlers/admins/send_ads/send_ads.py index e92b5f0..26b5f02 100755 --- a/handlers/admins/send_ads/send_ads.py +++ b/bot/handlers/admins/send_ads/send_ads.py @@ -11,7 +11,7 @@ from aiogram.fsm.context import FSMContext from states.admin_state import AdminState from filters.admin import SelectAdmin, IsAdmin -from function.translator import translator +from api.translator import translator from data.config import ADMIN diff --git a/handlers/admins/send_ads/stop_ads.py b/bot/handlers/admins/send_ads/stop_ads.py similarity index 98% rename from handlers/admins/send_ads/stop_ads.py rename to bot/handlers/admins/send_ads/stop_ads.py index 5279417..d7e3510 100644 --- a/handlers/admins/send_ads/stop_ads.py +++ b/bot/handlers/admins/send_ads/stop_ads.py @@ -9,7 +9,7 @@ from aiogram.fsm.context import FSMContext from states.admin_state import AdminState from filters.admin import SelectAdmin, IsAdmin -from function.translator import translator +from api.translator import translator @dp.callback_query(AdminCallback.filter(F.action == "stop_ads"), IsAdmin()) diff --git a/handlers/admins/statistika/download_statistics.py b/bot/handlers/admins/statistika/download_statistics.py similarity index 98% rename from handlers/admins/statistika/download_statistics.py rename to bot/handlers/admins/statistika/download_statistics.py index 7b98810..28722e0 100755 --- a/handlers/admins/statistika/download_statistics.py +++ b/bot/handlers/admins/statistika/download_statistics.py @@ -8,7 +8,7 @@ from aiogram import F from aiogram.fsm.context import FSMContext from filters.admin import SelectAdmin, IsAdmin -from function.translator import translator +from api.translator import translator from data.config import yil_oy_kun, soat_minut_sekund diff --git a/handlers/admins/statistika/staristika.py b/bot/handlers/admins/statistika/staristika.py similarity index 98% rename from handlers/admins/statistika/staristika.py rename to bot/handlers/admins/statistika/staristika.py index e21e651..202bb16 100755 --- a/handlers/admins/statistika/staristika.py +++ b/bot/handlers/admins/statistika/staristika.py @@ -7,7 +7,7 @@ from aiogram import F from aiogram.fsm.context import FSMContext from filters.admin import SelectAdmin, IsAdmin -from function.translator import translator +from api.translator import translator from data.config import yil_oy_kun, soat_minut_sekund diff --git a/handlers/admins/super_admin.py b/bot/handlers/admins/super_admin.py similarity index 100% rename from handlers/admins/super_admin.py rename to bot/handlers/admins/super_admin.py diff --git a/handlers/errors/error_handler.py b/bot/handlers/errors/error_handler.py similarity index 100% rename from handlers/errors/error_handler.py rename to bot/handlers/errors/error_handler.py diff --git a/handlers/users/check_join.py b/bot/handlers/users/check_join.py similarity index 98% rename from handlers/users/check_join.py rename to bot/handlers/users/check_join.py index 1d510da..d8d44da 100755 --- a/handlers/users/check_join.py +++ b/bot/handlers/users/check_join.py @@ -1,7 +1,7 @@ import logging from loader import dp, bot, db from aiogram import types, F -from function.translator import translator +from api.translator import translator from aiogram.utils.keyboard import InlineKeyboardBuilder from keyboards.inline.button import MainCallback diff --git a/handlers/users/close.py b/bot/handlers/users/close.py similarity index 100% rename from handlers/users/close.py rename to bot/handlers/users/close.py diff --git a/handlers/users/help.py b/bot/handlers/users/help.py similarity index 97% rename from handlers/users/help.py rename to bot/handlers/users/help.py index 5c7e413..26dca58 100755 --- a/handlers/users/help.py +++ b/bot/handlers/users/help.py @@ -2,7 +2,7 @@ from aiogram import types from aiogram.filters import Command -from function.translator import translator +from api.translator import translator from loader import dp, bot from keyboards.inline.user import send_url diff --git a/handlers/users/start.py b/bot/handlers/users/start.py similarity index 77% rename from handlers/users/start.py rename to bot/handlers/users/start.py index 8e58532..34aedf4 100755 --- a/handlers/users/start.py +++ b/bot/handlers/users/start.py @@ -1,23 +1,12 @@ import logging from aiogram import types from aiogram.filters import CommandStart -from function.translator import translator -from loader import dp, bot, db +from loader import dp, bot, translator from keyboards.inline.user import send_url @dp.message(CommandStart()) async def start_handler(msg: types.Message): - """ - Handles the /start command by sending a greeting message and a button - for sharing the bot's URL. Also logs the user if they are not already in the database. - - Args: - msg (types.Message): The incoming message object. - - Returns: - None - """ try: # User and bot information user_id = msg.from_user.id diff --git a/keyboards/inline/admin_btn.py b/bot/keyboards/inline/admin_btn.py similarity index 68% rename from keyboards/inline/admin_btn.py rename to bot/keyboards/inline/admin_btn.py index 3eb6623..08f1b12 100644 --- a/keyboards/inline/admin_btn.py +++ b/bot/keyboards/inline/admin_btn.py @@ -2,7 +2,7 @@ from aiogram.utils.keyboard import InlineKeyboardBuilder from .button import AdminCallback, EditAdminSetting, AdminSetting, BlockUser from .close_btn import close_btn -from function.translator import translator +from api.translator import translator from filters.admin import SelectAdmin from data.config import ADMIN from loader import db, bot @@ -10,16 +10,6 @@ def main_btn(): - """ - Creates the main button for the admin panel. - - Returns: - InlineKeyboardMarkup: The markup for the main button. - False: Returns False if an error occurs. - - This function creates a button with the text '🏠Main!' and attaches a callback - action to navigate to the main admin panel. - """ try: btn = InlineKeyboardBuilder() btn.button(text=f'🏠Main!', @@ -31,21 +21,6 @@ def main_btn(): def main_admin_panel_btn(user_id, language_code): - """ - Creates the inline keyboard for the main admin panel. - - Parameters: - user_id (int): The ID of the current user. - language_code (str): The language code for translation. - - Returns: - InlineKeyboardMarkup: The markup for the main admin panel buttons. - False: Returns False if an error occurs. - - This function creates buttons for various admin actions based on the permissions - of the current user. Includes settings for admins, sending advertisements, viewing - statistics, checking users, and channel settings. - """ try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) @@ -80,20 +55,6 @@ def main_admin_panel_btn(user_id, language_code): async def admin_setting(user_id, language_code): - """ - Creates the inline keyboard for admin settings. - - Parameters: - user_id (int): The ID of the current user. - language_code (str): The language code for translation. - - Returns: - InlineKeyboardMarkup: The markup for admin settings buttons. - False: Returns False if an error occurs. - - This function creates a button for each existing admin and an option to add a new admin. - It lists all admins if the current user is the main admin or only relevant admins otherwise. - """ try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) @@ -118,21 +79,6 @@ async def admin_setting(user_id, language_code): def attach_admin(user_id, language_code): - """ - Creates the inline keyboard for managing admin settings. - - Parameters: - user_id (int): The ID of the current user. - language_code (str): The language code for translation. - - Returns: - InlineKeyboardMarkup: The markup for admin settings management buttons. - False: Returns False if an error occurs. - - This function creates buttons for each admin setting, allowing modifications - for sending messages, viewing statistics, downloading statistics, blocking users, - channel settings, adding, and deleting admins. - """ try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) @@ -176,22 +122,6 @@ def attach_admin(user_id, language_code): def attach_admin_btn(user_id, language_code): - """ - Creates the inline keyboard for managing admin settings. - - Parameters: - user_id (int): The ID of the current user. - language_code (str): The language code for translation. - - Returns: - InlineKeyboardMarkup: The markup for admin settings management buttons. - False: Returns False if an error occurs. - - This function is similar to `attach_admin` but may serve a slightly different purpose - in the application. It allows the modification of admin settings such as sending - messages, viewing and downloading statistics, blocking users, channel settings, - adding, and deleting admins. - """ try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) @@ -235,19 +165,6 @@ def attach_admin_btn(user_id, language_code): def channel_settings(language_code): - """ - Creates the inline keyboard for channel settings. - - Parameters: - language_code (str): The language code for translation. - - Returns: - InlineKeyboardMarkup: The markup for channel settings buttons. - False: Returns False if an error occurs. - - This function creates buttons to configure channel settings, including adding, - removing channels, and setting mandatory membership requirements. - """ try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) @@ -276,22 +193,6 @@ def channel_settings(language_code): def block_user(attention_user_id, language_code, user_id): - """ - Creates the inline keyboard for blocking or unblocking a user. - - Parameters: - user_id (int): The ID of the current user. - language_code (str): The language code for translation. - user_id (int): The ID of the user to be blocked or unblocked. - - Returns: - InlineKeyboardMarkup: The markup for block/unblock user buttons. - False: Returns False if an error occurs. - - This function creates a button to either block or unblock a user, depending on their - current status. If the user is not banned, it offers to block them; if they are banned, - it offers to unblock them. - """ try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) @@ -317,20 +218,6 @@ def block_user(attention_user_id, language_code, user_id): def download_statistika(user_id, language_code): - """ - Creates the inline keyboard for downloading statistics. - - Parameters: - user_id (int): The ID of the current user. - lalanguage_codeng (str): The language code for translation. - - Returns: - InlineKeyboardMarkup: The markup for download statistics button. - False: Returns False if an error occurs. - - This function creates a button for downloading statistics if the current user has - the permission to do so. - """ try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) @@ -348,36 +235,6 @@ def download_statistika(user_id, language_code): def stop_advertisement(): - """ - Creates an inline keyboard with a single "🚫 Stop!" button for stopping advertisements. - - This function utilizes the `InlineKeyboardBuilder` to construct an inline keyboard with a button - labeled "🚫 Stop!". The button's callback data is generated using the `AdminCallback` class, - specifying the action "stop_ads". This callback data is used by the bot to handle the button - press event appropriately. - - The function is wrapped in a try-except block to catch any exceptions that may occur during - the creation of the inline keyboard. If an exception is raised, the error is logged, and the - function returns `False` to indicate that the operation failed. - - Returns: - InlineKeyboardMarkup: The inline keyboard markup object containing the "🚫 Stop!" button, - if successfully created. - bool: Returns `False` if an exception occurs during the creation process. - - Exceptions: - If an exception is encountered, it is caught and logged using the logging module, with - an error message indicating the source of the error. - - Example Usage: - To create an inline keyboard for stopping ads: - - keyboard = stop_ads() - if keyboard: - await message.reply("Press the button to stop ads.", reply_markup=keyboard) - else: - await message.reply("Failed to create stop button.") - """ try: # Initialize the inline keyboard builder btn = InlineKeyboardBuilder() diff --git a/keyboards/inline/button.py b/bot/keyboards/inline/button.py similarity index 100% rename from keyboards/inline/button.py rename to bot/keyboards/inline/button.py diff --git a/keyboards/inline/close_btn.py b/bot/keyboards/inline/close_btn.py similarity index 100% rename from keyboards/inline/close_btn.py rename to bot/keyboards/inline/close_btn.py diff --git a/keyboards/inline/user.py b/bot/keyboards/inline/user.py similarity index 97% rename from keyboards/inline/user.py rename to bot/keyboards/inline/user.py index 56aef34..d6216b2 100644 --- a/keyboards/inline/user.py +++ b/bot/keyboards/inline/user.py @@ -1,6 +1,6 @@ import logging from aiogram.utils.keyboard import InlineKeyboardBuilder -from function.translator import translator +from api.translator import translator def send_url(language_code, url): diff --git a/loader.py b/bot/loader.py similarity index 96% rename from loader.py rename to bot/loader.py index 51eebb2..738a2fb 100755 --- a/loader.py +++ b/bot/loader.py @@ -6,7 +6,7 @@ from aiogram.client.bot import DefaultBotProperties # Yangi versiyadagi default sozlamalar uchun from data.config import * # Konfiguratsiyalarni import qilamiz from db.database import Database, MySQLHandler -from function.translator import Translator +from api.translator import Translator from core.feature_manager import FeatureManager diff --git a/main.py b/bot/main.py similarity index 100% rename from main.py rename to bot/main.py diff --git a/middlewares/__init__.py b/bot/middlewares/__init__.py similarity index 100% rename from middlewares/__init__.py rename to bot/middlewares/__init__.py diff --git a/middlewares/throttling.py b/bot/middlewares/throttling.py similarity index 99% rename from middlewares/throttling.py rename to bot/middlewares/throttling.py index 706a55f..f376445 100755 --- a/middlewares/throttling.py +++ b/bot/middlewares/throttling.py @@ -5,7 +5,7 @@ from aiogram import BaseMiddleware, types from aiogram.utils.keyboard import InlineKeyboardBuilder from keyboards.inline.button import MainCallback -from function.translator import translator +from api.translator import translator class ThrottlingMiddleware(BaseMiddleware): diff --git a/states/admin_state.py b/bot/states/admin_state.py similarity index 100% rename from states/admin_state.py rename to bot/states/admin_state.py diff --git a/utils/notify_admins.py b/bot/utils/notify_admins.py similarity index 100% rename from utils/notify_admins.py rename to bot/utils/notify_admins.py diff --git a/utils/set_bot_commands.py b/bot/utils/set_bot_commands.py similarity index 100% rename from utils/set_bot_commands.py rename to bot/utils/set_bot_commands.py diff --git a/docker-compose.test.yml b/docker-compose.test.yml deleted file mode 100644 index c14cebb..0000000 --- a/docker-compose.test.yml +++ /dev/null @@ -1,12 +0,0 @@ -services: - mysql: - image: mysql:8.4 - command: --default-authentication-plugin=mysql_native_password - environment: - MYSQL_ROOT_PASSWORD: root - MYSQL_DATABASE: app_db - ports: ["3306:3306"] - - redis: - image: redis:7-alpine - ports: ["6379:6379"] diff --git a/logs/logging.log b/logs/logging.log deleted file mode 100644 index e5cc4f4..0000000 --- a/logs/logging.log +++ /dev/null @@ -1,2 +0,0 @@ -dispatcher.py - start_polling - 527 - aiogram.dispatcher - INFO - Start polling -dispatcher.py - _polling - 341 - aiogram.dispatcher - INFO - Run polling for bot @Biloger_uzbot id=1430978281 - 'B' diff --git a/test.py b/test.py deleted file mode 100644 index 67e94f2..0000000 --- a/test.py +++ /dev/null @@ -1,164 +0,0 @@ -import asyncio -import time -from aiogram import Bot, Dispatcher, types, F -from aiogram.filters import Command -from aiogram.exceptions import TelegramAPIError -from db.database import Database -from data.config import * - - -db = Database(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) - -# Token va admin identifikatori -API_TOKEN = "1430978281:AAFbdRkUFtw3fVLqbU8_L9KJ-wy_9mwwNS4" -ADMIN_ID = 835558445 # O'zingizning admin ID raqamingiz - -bot = Bot(token=API_TOKEN) -dp = Dispatcher() - -# Foydalanuvchilar ro'yxatini oddiy to'plamda saqlaymiz (amaldagi loyihada ma'lumotlar bazasi orqali olib borish tavsiya etiladi) -registered_users = set() - -# Avvalgi keltirilgan Database modulidan db obyektini import qiling -# from your_database_module import db -# Misolda biz oldindan yaratilgan `db` obyektidan foydalanamiz - -# Broadcast jarayoni uchun 'settings' jadvalidagi kalitlar: -# "broadcast_total", "broadcast_sent", "broadcast_fail", "broadcast_start_time", "broadcast_stop" -# Ushbu funksiyalar orqali settings jadvaliga yozamiz: -def init_broadcast_settings(total, admin_id): - try: - db.insert_settings(admin_id, "broadcast_total", str(total)) - except Exception: - db.update_settings_key(admin_id, "broadcast_total", str(total)) - try: - db.insert_settings(admin_id, "broadcast_sent", "0") - except Exception: - db.update_settings_key(admin_id, "broadcast_sent", "0") - try: - db.insert_settings(admin_id, "broadcast_fail", "0") - except Exception: - db.update_settings_key(admin_id, "broadcast_fail", "0") - try: - db.insert_settings(admin_id, "broadcast_start_time", str(time.time())) - except Exception: - db.update_settings_key(admin_id, "broadcast_start_time", str(time.time())) - try: - db.insert_settings(admin_id, "broadcast_stop", "0") - except Exception: - db.update_settings_key(admin_id, "broadcast_stop", "0") - -def update_broadcast_setting(key, value, admin_id=ADMIN_ID): - try: - db.update_settings_key(admin_id, key, str(value)) - except Exception as e: - print("DB update error:", e) - -def get_broadcast_setting(key): - value = db.select_setting(key) - return value - -# /start handler – foydalanuvchini ro'yxatga qo'shish -@dp.message(Command("start")) -async def on_start(message: types.Message): - registered_users.add(message.from_user.id) - await message.answer("Botga xush kelibsiz! Siz ro'yxatga olindingiz.") - -# Global o'zgaruvchi: broadcasting jarayonining task obyektini saqlash -broadcast_task = None - -# /send komandasi – adminning broadcasting jarayonini ishga tushiradi -@dp.message(Command("send")) -async def broadcast_handler(message: types.Message): - global broadcast_task - if message.from_user.id != ADMIN_ID: - return # Faqat admin uchun - if not registered_users: - await message.answer("Hozircha foydalanuvchilar ro'yxati bo'sh.") - return - total_users = len(registered_users) - init_broadcast_settings(total_users, ADMIN_ID) - await message.answer("✅ Reklama jo'natish boshlandi.") - broadcast_task = asyncio.create_task(send_ads_to_all(message)) - -# /status komandasi – adminga real vaqt progressini ko'rsatadi -@dp.message(Command("status")) -async def status_handler(message: types.Message): - if message.from_user.id != ADMIN_ID: - return - try: - total = int(get_broadcast_setting("broadcast_total") or "0") - sent = int(get_broadcast_setting("broadcast_sent") or "0") - fail = int(get_broadcast_setting("broadcast_fail") or "0") - start_time = float(get_broadcast_setting("broadcast_start_time") or time.time()) - current_time = time.time() - elapsed = current_time - start_time - processed = sent + fail - remaining = total - processed - avg_time = elapsed / processed if processed > 0 else 0 - estimated_remaining = avg_time * remaining - status_text = ( - f"📊 Broadcast Status:\n" - f"Jami foydalanuvchilar: {total}\n" - f"Jo'natilgan: {sent}\n" - f"Xatoliklar: {fail}\n" - f"Qayta ishlangan: {processed}\n" - f"O'tgan vaqt: {int(elapsed)} soniya\n" - f"Taxminiy qolgan vaqt: {int(estimated_remaining)} soniya" - ) - await message.answer(status_text) - except Exception as err: - await message.answer(err) - -# /stop komandasi – admin broadcasting jarayonini to'xtatadi -@dp.message(Command("stop")) -async def stop_handler(message: types.Message): - if message.from_user.id != ADMIN_ID: - return - update_broadcast_setting("broadcast_stop", "1") - await message.answer("🚫 Broadcast to'xtatildi. Jarayon keyingi iteratsiyada to'xtaydi.") - -# Fon vazifasi: barcha foydalanuvchilarga xabar (adminning xabari)ni yuborish -async def send_ads_to_all(admin_message: types.Message): - total_users = len(registered_users) - sent_count = 0 - fail_count = 0 - start_time = time.time() - update_broadcast_setting("broadcast_start_time", start_time) - # Ro'yxat bo'ylab aylanamiz - for idx, user_id in enumerate(registered_users, start=1): - # Agar /stop komandasi orqali broadcast_stop 1 ga o'zgarsa, to'xtatamiz - if get_broadcast_setting("broadcast_stop") == "1": - break - try: - await bot.copy_message( - chat_id=user_id, - from_chat_id=admin_message.chat.id, - message_id=admin_message.message_id - ) - sent_count += 1 - except Exception as err: - fail_count += 1 - time.sleep(1000000000) - # Har bir xabar yuborilgandan so'ng progressni yangilaymiz - update_broadcast_setting("broadcast_sent", sent_count) - update_broadcast_setting("broadcast_fail", fail_count) - # Har 100 ta xabardan keyin 60 soniya kutish (daqiqasiga 100 ta tezlik) - if idx % 100 == 0: - await asyncio.sleep(60) - # Yakuniy hisobotni yangilaymiz va adminga jo'natamiz - update_broadcast_setting("broadcast_sent", sent_count) - update_broadcast_setting("broadcast_fail", fail_count) - report_text = ( - f"📊 Broadcast yakunlandi.\n" - f"Jo'natilgan: {sent_count}\n" - f"Xatoliklar: {fail_count}\n" - f"Jami foydalanuvchilar: {total_users}" - ) - try: - await bot.send_message(chat_id=ADMIN_ID, text=report_text) - except Exception: - pass - -if __name__ == "__main__": - asyncio.run(dp.start_polling(bot)) diff --git a/test/feature_manager.py b/test/feature_manager.py deleted file mode 100644 index 54ac8d7..0000000 --- a/test/feature_manager.py +++ /dev/null @@ -1,127 +0,0 @@ -import logging -from unittest.mock import MagicMock, patch - -import pytest -from redis import RedisError - -# Import the class under test -from core.feature_manager import FeatureManager - - -# ──────────────────────────── Fixtures ──────────────────────────── - -@pytest.fixture -def db_mock(): - """Return a mock of the Database adapter.""" - mock = MagicMock() - # select_feature → None by default (no record) - mock.select_feature.return_value = None - # update_feature returns number of affected rows (1 = updated, 0 = not found) - mock.update_feature.return_value = 1 - return mock - - -@pytest.fixture -def redis_mock(): - """Return a mock of the Redis client (decode_responses=True expected).""" - mock = MagicMock() - mock.hget.return_value = None # no value cached by default - return mock - - -@pytest.fixture -def logger(): - """Real logger (captures to pytest).""" - logging.basicConfig(level=logging.DEBUG) - return logging.getLogger("feature_manager_test") - - -@pytest.fixture -def fm(db_mock, redis_mock, logger): - """FeatureManager instance with mocked dependencies.""" - return FeatureManager(db=db_mock, redis_client=redis_mock, root_logger=logger) - - -# ──────────────────────────── Tests: Feature lookup ──────────────────────────── - -def test_feature_returns_cached_value(fm, redis_mock, db_mock): - """If Redis already has the flag, it should be returned and DB not queried.""" - redis_mock.hget.return_value = "1" # cached True - result = fm.feature("dark_mode") - assert result is True - redis_mock.hget.assert_called_once_with(fm._REDIS_HASH, "dark_mode") - # DB should be untouched - db_mock.select_feature.assert_not_called() - - -def test_feature_fallbacks_to_db_and_caches(fm, redis_mock, db_mock): - """If Redis miss but DB has value, it must be cached and returned.""" - redis_mock.hget.return_value = None - db_mock.select_feature.return_value = 0 # False in DB - - result = fm.feature("dark_mode") - assert result is False - - redis_mock.hset.assert_called_once_with(fm._REDIS_HASH, "dark_mode", 0) - db_mock.select_feature.assert_called_once_with("dark_mode") - - -@pytest.mark.parametrize("user_input, expected_bool", [("y", True), ("n", False)]) -@patch("builtins.input") -def test_feature_asks_user_when_not_found(mock_input, fm, redis_mock, db_mock, user_input, expected_bool): - """When not in Redis nor DB, ask user; persist answer to both stores.""" - mock_input.return_value = user_input - redis_mock.hget.return_value = None - db_mock.select_feature.return_value = None - - result = fm.feature("beta_flag") - - assert result is expected_bool - # Persist to DB & Redis - db_mock.insert_feature.assert_called_once_with(name="beta_flag", enabled=expected_bool) - redis_mock.hset.assert_called_once_with(fm._REDIS_HASH, "beta_flag", int(expected_bool)) - - -# ──────────────────────────── Tests: update_feature ──────────────────────────── - -def test_update_feature_updates_existing_flag(fm, redis_mock, db_mock): - """update_feature should call DB.update_feature and Redis.hset when flag exists.""" - db_mock.update_feature.return_value = 1 # one row updated - - fm.update_feature("dark_mode", enabled=True) - - db_mock.update_feature.assert_called_once_with(name="dark_mode", enabled=True) - db_mock.insert_feature.assert_not_called() - redis_mock.hset.assert_called_once_with(fm._REDIS_HASH, "dark_mode", 1) - - -def test_update_feature_inserts_when_not_exists(fm, redis_mock, db_mock): - """If DB.update_feature affects 0 rows, insert_feature must be called.""" - db_mock.update_feature.return_value = 0 - - fm.update_feature("new_flag", enabled=False) - - db_mock.update_feature.assert_called_once_with(name="new_flag", enabled=False) - db_mock.insert_feature.assert_called_once_with(name="new_flag", enabled=False) - redis_mock.hset.assert_called_once_with(fm._REDIS_HASH, "new_flag", 0) - - -# ──────────────────────────── Tests: error handling ──────────────────────────── - -def test_feature_redis_error_returns_false(fm, redis_mock, caplog): - """If Redis raises an error, feature() should log it and return False.""" - caplog.set_level(logging.ERROR) - redis_mock.hget.side_effect = RedisError("Redis down") - - result = fm.feature("unstable_flag") - - assert result is False - assert any("Redis down" in r.message for r in caplog.records) - - -def test_update_feature_redis_error_raises(fm, redis_mock): - """update_feature should re‑raise if RedisError occurs (transactional).""" - redis_mock.hset.side_effect = RedisError("write failed") - - with pytest.raises(RedisError): - fm.update_feature("any_flag", enabled=True) diff --git a/test/integration/test_feature_manager_live.py b/test/integration/test_feature_manager_live.py deleted file mode 100644 index 5b5949a..0000000 --- a/test/integration/test_feature_manager_live.py +++ /dev/null @@ -1,27 +0,0 @@ -import logging -from feature_manager import FeatureManager -from db.database import Database -from redis import Redis -import mysql.connector - -log = logging.getLogger("it") - -def _db(): - conn = mysql.connector.connect( - host="localhost", user="root", password="root", database="app_db" - ) - return Database(conn) # sizning adapteringiz (simple wrapper bo‘lishi mumkin) - -def _redis(): - return Redis(host="localhost", port=6379, decode_responses=True) - -def test_live_roundtrip(tmp_path): - fm = FeatureManager(db=_db(), redis_client=_redis(), root_logger=log) - name = "integration_flag" - - # new → user prompt'ni bypass qilish uchun _persist chaqiramiz - fm._persist(name, True) - assert fm.feature(name) is True - - fm.update_feature(name, enabled=False) - assert fm.feature(name) is False diff --git a/test/unit/test_feature_manager.py b/test/unit/test_feature_manager.py deleted file mode 100644 index e69de29..0000000 diff --git a/conftest.py b/tests/conftest.py similarity index 100% rename from conftest.py rename to tests/conftest.py From 938d65a5fb0c49f66cef5e8f1a30a4e4c5490835 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Tue, 13 May 2025 23:45:33 +0500 Subject: [PATCH 40/71] refactor: Update import paths and enhance setup commands; add pytest configuration and initial tests --- Makefile | 2 +- bot/__init__.py | 0 bot/api/translator.py | 8 ++-- bot/core/feature_manager.py | 2 +- bot/db/database.py | 5 +-- bot/handlers/__init__.py | 58 ++++++++++++++-------------- bot/handlers/errors/error_handler.py | 2 +- bot/handlers/users/start.py | 4 +- bot/keyboards/inline/user.py | 13 +------ bot/loader.py | 8 ++-- bot/main.py | 16 ++++---- bot/middlewares/throttling.py | 8 ++-- bot/utils/notify_admins.py | 6 +-- bot/utils/set_bot_commands.py | 2 +- pytest.ini | 7 ++++ requirements.txt | 7 +++- setup.py | 6 ++- tests/conftest.py | 43 --------------------- tests/handlers/users/test_start.py | 15 +++++++ tests/moduls/test_translator.py | 28 ++++++++++++++ 20 files changed, 121 insertions(+), 119 deletions(-) create mode 100644 bot/__init__.py create mode 100644 pytest.ini delete mode 100644 tests/conftest.py create mode 100644 tests/handlers/users/test_start.py create mode 100644 tests/moduls/test_translator.py diff --git a/Makefile b/Makefile index e4cc85e..d700efb 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ endif main: setup @echo "🚀 Running main.py…" - $(VENV_PY) main.py + $(VENV_PY) -m bot.main setup: requirements @echo "⚙️ Running setup.py…" diff --git a/bot/__init__.py b/bot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bot/api/translator.py b/bot/api/translator.py index 5ea62eb..46294e1 100644 --- a/bot/api/translator.py +++ b/bot/api/translator.py @@ -1,8 +1,8 @@ from typing import Optional from deep_translator import GoogleTranslator -from db.database import Database -from function.function import to_hash -from core.feature_manager import FeatureManager +from bot.db.database import Database +from bot.function.function import to_hash +from bot.core.feature_manager import FeatureManager class Translator: @@ -45,7 +45,7 @@ def translate(self, self.db.insert_translations(text_id=hash_index, dest_lang=dest, translated_content=translated) return translated else: - hash_index = self.db.insert_texts(hash_value=hash_value, text=text) + hash_index = self.db.insert_texts(hash_value=hash_value, raw_text=text) translated = GoogleTranslator(source=src, target=dest).translate(text) self.db.insert_translations(text_id=hash_index, dest_lang=dest, translated_content=translated) return translated diff --git a/bot/core/feature_manager.py b/bot/core/feature_manager.py index 86a5a50..2ebd2c6 100644 --- a/bot/core/feature_manager.py +++ b/bot/core/feature_manager.py @@ -1,6 +1,6 @@ import logging from typing import Optional -from db.database import Database +from bot.db.database import Database from redis import Redis, RedisError diff --git a/bot/db/database.py b/bot/db/database.py index 48d57b5..2bda13a 100755 --- a/bot/db/database.py +++ b/bot/db/database.py @@ -1,11 +1,10 @@ import logging import mysql.connector from aiogram import Bot -from function.function import to_hash +from bot.function.function import to_hash class Database: - def __init__(self, host, user, password, database): """ Initialize the Database object with connection parameters. @@ -274,7 +273,7 @@ def insert_texts(self, hash_value: str, raw_text: str): """ try: sql = "INSERT INTO `texts` (`hash_value`, `raw_text`) VALUES (%s, %s)" - values = (to_hash(hash_value), raw_text) + values = (hash_value, raw_text) self.cursor.execute(sql, values) self.connection.commit() return self.cursor.lastrowid diff --git a/bot/handlers/__init__.py b/bot/handlers/__init__.py index 8e14b20..0ab3f0d 100755 --- a/bot/handlers/__init__.py +++ b/bot/handlers/__init__.py @@ -1,41 +1,41 @@ from .errors import error_handler from .users import start -from .admins import main_panel +# from .admins import main_panel -from .admins.admin_settings import add_admin -from .admins.channel_settings import get_id -from .admins.check_usr import attach_usr -# from .admins.check_usr import send_ads_message -# from .admins.send_ads import get_message -from .admins import super_admin -from .users import help +# from .admins.admin_settings import add_admin +# from .admins.channel_settings import get_id +# from .admins.check_usr import attach_usr +# # from .admins.check_usr import send_ads_message +# # from .admins.send_ads import get_message +# from .admins import super_admin +# from .users import help -# from .users import check_usr -from .users import check_join +# # from .users import check_usr +# from .users import check_join -from .admins.admin_settings import admin_setting -from .admins.admin_settings import add_admin_first_step -from .admins.admin_settings import admin_setting -from .admins.admin_settings import attach_admins -from .admins.callback_query import main_admin_panel -from .admins.admin_settings import edit_admin +# from .admins.admin_settings import admin_setting +# from .admins.admin_settings import add_admin_first_step +# from .admins.admin_settings import admin_setting +# from .admins.admin_settings import attach_admins +# from .admins.callback_query import main_admin_panel +# from .admins.admin_settings import edit_admin -from .admins.channel_settings import channel_setting -from .admins.channel_settings import mandatory_membership -from .admins.channel_settings import add_channel -from .admins.channel_settings import remove_channel -from .admins.channel_settings import delete_channel +# from .admins.channel_settings import channel_setting +# from .admins.channel_settings import mandatory_membership +# from .admins.channel_settings import add_channel +# from .admins.channel_settings import remove_channel +# from .admins.channel_settings import delete_channel -from .admins.check_usr import check_usr -from .admins.check_usr import block_users -from .admins.check_usr import send_message +# from .admins.check_usr import check_usr +# from .admins.check_usr import block_users +# from .admins.check_usr import send_message -# from .admins.send_ads import send_ads -# from .admins.send_ads import stop_ads +# # from .admins.send_ads import send_ads +# # from .admins.send_ads import stop_ads -from .admins.statistika import staristika -from .admins.statistika import download_statistics +# from .admins.statistika import staristika +# from .admins.statistika import download_statistics -from .users import close +# from .users import close diff --git a/bot/handlers/errors/error_handler.py b/bot/handlers/errors/error_handler.py index 4933f82..c144b7f 100644 --- a/bot/handlers/errors/error_handler.py +++ b/bot/handlers/errors/error_handler.py @@ -9,7 +9,7 @@ TelegramUnauthorizedError, TelegramForbiddenError # (In aiogram v3.18, specific errors like "MessageNotModified" are categorized under TelegramBadRequest) ) -from loader import root_logger +from bot.loader import root_logger # from data.config import ADMINS # your admin IDs diff --git a/bot/handlers/users/start.py b/bot/handlers/users/start.py index 34aedf4..fd8c026 100755 --- a/bot/handlers/users/start.py +++ b/bot/handlers/users/start.py @@ -1,8 +1,8 @@ import logging from aiogram import types from aiogram.filters import CommandStart -from loader import dp, bot, translator -from keyboards.inline.user import send_url +from bot.loader import dp, bot, translator +from bot.keyboards.inline.user import send_url @dp.message(CommandStart()) diff --git a/bot/keyboards/inline/user.py b/bot/keyboards/inline/user.py index d6216b2..127dca8 100644 --- a/bot/keyboards/inline/user.py +++ b/bot/keyboards/inline/user.py @@ -1,20 +1,9 @@ import logging from aiogram.utils.keyboard import InlineKeyboardBuilder -from api.translator import translator +from bot.loader import translator def send_url(language_code, url): - """ - Creates an inline keyboard with a button to share a URL. - - Args: - url (str): The URL to be shared. - language_code (str): The language code for translation. - - Returns: - aiogram.types.InlineKeyboardMarkup: The markup for the inline keyboard with the share button, - or False if an error occurred. - """ try: btn = InlineKeyboardBuilder() btn.button( diff --git a/bot/loader.py b/bot/loader.py index 738a2fb..2e8a5f2 100755 --- a/bot/loader.py +++ b/bot/loader.py @@ -4,10 +4,10 @@ from redis import Redis from aiogram.fsm.storage.redis import RedisStorage from aiogram.client.bot import DefaultBotProperties # Yangi versiyadagi default sozlamalar uchun -from data.config import * # Konfiguratsiyalarni import qilamiz -from db.database import Database, MySQLHandler -from api.translator import Translator -from core.feature_manager import FeatureManager +from bot.data.config import * +from bot.db.database import Database +from bot.api.translator import Translator +from bot.core.feature_manager import FeatureManager # MySQL ma'lumotlar bazasi ulanishini yaratamiz diff --git a/bot/main.py b/bot/main.py index f4bc24b..42ce3cb 100755 --- a/bot/main.py +++ b/bot/main.py @@ -1,12 +1,12 @@ import os import sys import asyncio -import middlewares, handlers # Import middlewares and handlers modules -from utils.notify_admins import on_startup_notify # Import the function to notify admins on startup import logging -from utils.set_bot_commands import set_default_commands # Import the function to set default bot commands -from loader import * # Import all from loader module -from data.config import log_file_name, FEATURES # Import the log file name from config +from bot.utils.notify_admins import on_startup_notify # Import the function to notify admins on startup +from bot.utils.set_bot_commands import set_default_commands # Import the function to set default bot commands +from bot.loader import * # Import all from loader module +from bot.data.config import log_file_name +from bot.db.database import MySQLHandler async def main(): @@ -19,15 +19,15 @@ async def main(): try: # middlewares if FM.feature('middlewares'): - from middlewares.throttling import ThrottlingMiddleware + from bot.middlewares.throttling import ThrottlingMiddleware dp.update.middleware.register(ThrottlingMiddleware(db=db, bot=bot)) # Register the ThrottlingMiddleware # save_log if FM.feature('save_log'): mysql_handler = MySQLHandler(bot=bot, connection=db.connection) - log_format = '%(filename)s - %(funcName)s - %(lineno)d - %(name)s - %(levelname)s - %(message)s' - formatter = logging.Formatter(log_format) + # log_format = '%(filename)s - %(funcName)s - %(lineno)d - %(name)s - %(levelname)s - %(message)s' + # formatter = logging.Formatter(log_format) root_logger.addHandler(mysql_handler) mandatory_membership = db.select_setting('mandatory_membership') diff --git a/bot/middlewares/throttling.py b/bot/middlewares/throttling.py index f376445..01dc6ac 100755 --- a/bot/middlewares/throttling.py +++ b/bot/middlewares/throttling.py @@ -1,11 +1,11 @@ import time import logging -from data.config import ADMIN -from keyboards.inline.close_btn import close_btn +from bot.data.config import ADMIN +from bot.keyboards.inline.close_btn import close_btn from aiogram import BaseMiddleware, types from aiogram.utils.keyboard import InlineKeyboardBuilder -from keyboards.inline.button import MainCallback -from api.translator import translator +from bot.keyboards.inline.button import MainCallback +from bot.loader import translator class ThrottlingMiddleware(BaseMiddleware): diff --git a/bot/utils/notify_admins.py b/bot/utils/notify_admins.py index c6d406d..b0c00b2 100755 --- a/bot/utils/notify_admins.py +++ b/bot/utils/notify_admins.py @@ -1,7 +1,7 @@ import logging, os -from loader import bot -from data.config import ADMIN, log_file_name -from keyboards.inline.close_btn import close_btn +from bot.loader import bot +from bot.data.config import ADMIN, log_file_name +from bot.keyboards.inline.close_btn import close_btn from aiogram import types diff --git a/bot/utils/set_bot_commands.py b/bot/utils/set_bot_commands.py index 9a98d86..cf1a469 100755 --- a/bot/utils/set_bot_commands.py +++ b/bot/utils/set_bot_commands.py @@ -1,5 +1,5 @@ from aiogram import types -from loader import bot +from bot.loader import bot async def set_default_commands(): diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..0a8ae9e --- /dev/null +++ b/pytest.ini @@ -0,0 +1,7 @@ +[pytest] +python_files = + tests/*.py + tests/**/*.py + tests/**/**/*.py +asyncio_mode = auto +asyncio_default_fixture_loop_scope = function diff --git a/requirements.txt b/requirements.txt index 1a15a40..e6944f0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,4 +10,9 @@ pytest-docker pytest-mock aioresponses deep_translator -pandas \ No newline at end of file +pandas +pytest +pytest-asyncio +asynctest +aioresponses +aiogram_tests diff --git a/setup.py b/setup.py index 9713eb7..c742b21 100644 --- a/setup.py +++ b/setup.py @@ -100,12 +100,14 @@ def main_setup() -> None: print("🔧 Configuration complete.") - from loader import FM + from bot.loader import FM FEATURES = ['translator', 'middlewares', 'save_log'] for feature in FEATURES: - FM.feature(feature) + x = FM.feature(feature) + print(f"🔧 {feature}: {x}") + print("🔧 Features loaded.") diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index 6375e8b..0000000 --- a/tests/conftest.py +++ /dev/null @@ -1,43 +0,0 @@ -import os, time, contextlib -import pytest -import mysql.connector -from redis import Redis -from pytest_docker.plugin import Services - -MYSQL_URL = "mysql://root:root@localhost:3306/app_db" - -# ───────────── Docker servislar tayyor bo‘lguncha kutish ───────────── -def _wait_mysql_up(): - for _ in range(20): - try: - mysql.connector.connect( - host="localhost", user="root", password="root", database="app_db" - ).close() - return - except mysql.connector.Error: - time.sleep(1) - pytest.exit("MySQL konteyneri ishga tushmadi", returncode=1) - -def _wait_redis_up(): - for _ in range(20): - try: - Redis(host="localhost", port=6379).ping() - return - except Exception: - time.sleep(1) - pytest.exit("Redis konteyneri ishga tushmadi", returncode=1) - -# ───────────── Pytest hooks ───────────── -def pytest_configure(): - os.environ["DATABASE_URL"] = MYSQL_URL - os.environ["REDIS_HOST"] = "localhost" - -# ───────────── Docker services fixture ───────────── -@pytest.fixture(scope="session", autouse=True) -def _spin_up_docker_services(docker_services: Services): - """Redis va MySQL konteynerlarini test sessiyasi boshida ko‘taradi.""" - docker_services.start() # docker-compose.test.yml bo‘yicha - _wait_mysql_up() - _wait_redis_up() - yield - docker_services.stop() diff --git a/tests/handlers/users/test_start.py b/tests/handlers/users/test_start.py new file mode 100644 index 0000000..6d5f94c --- /dev/null +++ b/tests/handlers/users/test_start.py @@ -0,0 +1,15 @@ +# import pytest + +# from bot.handlers.users.start import start_handler + +# from aiogram_tests import MockedBot +# from aiogram_tests.handler import MessageHandler +# from aiogram_tests.types.dataset import MESSAGE + + +# @pytest.mark.asyncio +# async def test_echo(): +# request = MockedBot(MessageHandler(start_handler)) +# calls = await request.query(message=MESSAGE.as_object(text="Hello, Bot!")) +# answer_message = calls.send_messsage.fetchone() +# assert answer_message.text == "Hello, Bot!" \ No newline at end of file diff --git a/tests/moduls/test_translator.py b/tests/moduls/test_translator.py new file mode 100644 index 0000000..816c20b --- /dev/null +++ b/tests/moduls/test_translator.py @@ -0,0 +1,28 @@ +import pytest +from bot.api.translator import Translator +from bot.loader import db +from bot.function.function import to_hash + + +@pytest.mark.asyncio +async def test_translator_no_feature(monkeypatch): + class FM: + def __init__(self, defoult_return: bool = True): + self.defoult_return = defoult_return + def feature(self, *args,**kwargs) : + return self.defoult_return + + tr = Translator(db=db, FM=FM(False)) + result = tr.translate("Hello", dest="fr", src="en") + assert result == "Hello" + + tr = Translator(db=db, FM=FM(True)) + result = tr.translate("Hello", dest="fr", src="en") + assert result == "Bonjour" + + hash_value = to_hash("Hello") + hash_index = db.select_texts(hash_value) + assert hash_index is not None + + check = db.select_translations(hash_index, "fr") + assert check is not None \ No newline at end of file From 4e3436810f1603fb61750463bc99a83889022503 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 19:07:08 +0500 Subject: [PATCH 41/71] feat: Add main entry point and logging setup; refactor Makefile and update requirements --- Makefile | 2 +- bot/__init__.py | 1 + bot/__main__.py | 30 +++++++++ bot/loader.py | 2 +- bot/main.py | 26 +------- requirements.txt | 1 + tests/__init__.py | 0 tests/handlers/__init__.py | 0 tests/handlers/admin/__init__.py | 0 tests/handlers/users/__init__.py | 0 tests/handlers/users/test_start.py | 3 +- tests/moduls/__init__.py | 0 tests/unit/conftest.py | 98 ++++++++++++++++++++++++++++++ 13 files changed, 134 insertions(+), 29 deletions(-) create mode 100644 bot/__main__.py create mode 100644 tests/__init__.py create mode 100644 tests/handlers/__init__.py create mode 100644 tests/handlers/admin/__init__.py create mode 100644 tests/handlers/users/__init__.py create mode 100644 tests/moduls/__init__.py create mode 100644 tests/unit/conftest.py diff --git a/Makefile b/Makefile index d700efb..fc86dba 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,7 @@ endif main: setup @echo "🚀 Running main.py…" - $(VENV_PY) -m bot.main + $(VENV_PY) -m bot setup: requirements @echo "⚙️ Running setup.py…" diff --git a/bot/__init__.py b/bot/__init__.py index e69de29..deec4a8 100644 --- a/bot/__init__.py +++ b/bot/__init__.py @@ -0,0 +1 @@ +from . import main \ No newline at end of file diff --git a/bot/__main__.py b/bot/__main__.py new file mode 100644 index 0000000..bcf2da7 --- /dev/null +++ b/bot/__main__.py @@ -0,0 +1,30 @@ + +import os +import sys +import asyncio +import logging +from .main import main +from bot.data.config import log_file_name +from bot.loader import root_logger, log_file_name, formatter + + +if __name__ == "__main__": + + if not os.path.exists('logs'): + os.mkdir('logs') + + if not os.path.exists(log_file_name): + with open(log_file_name, 'w') as f: + pass + + file_handler = logging.FileHandler(log_file_name) + file_handler.setLevel(logging.INFO) + file_handler.setFormatter(formatter) + root_logger.addHandler(file_handler) + + stream_handler = logging.StreamHandler(sys.stdout) + stream_handler.setLevel(logging.INFO) + stream_handler.setFormatter(formatter) + root_logger.addHandler(stream_handler) + + asyncio.run(main()) diff --git a/bot/loader.py b/bot/loader.py index 2e8a5f2..7937640 100755 --- a/bot/loader.py +++ b/bot/loader.py @@ -24,7 +24,7 @@ FM = FeatureManager(db=db, root_logger=root_logger, redis_client=redis) - +print(f"({BOT_TOKEN})") # Botni token va default parametr orqali yaratamiz bot = Bot(token=BOT_TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML)) diff --git a/bot/main.py b/bot/main.py index 42ce3cb..d427cba 100755 --- a/bot/main.py +++ b/bot/main.py @@ -1,11 +1,7 @@ -import os -import sys -import asyncio import logging +from bot.loader import * from bot.utils.notify_admins import on_startup_notify # Import the function to notify admins on startup from bot.utils.set_bot_commands import set_default_commands # Import the function to set default bot commands -from bot.loader import * # Import all from loader module -from bot.data.config import log_file_name from bot.db.database import MySQLHandler @@ -44,26 +40,6 @@ async def main(): await bot.session.close() # Close the bot session -if __name__ == "__main__": - - if not os.path.exists('logs'): - os.mkdir('logs') - - if not os.path.exists(log_file_name): - with open(log_file_name, 'w') as f: - pass - - file_handler = logging.FileHandler(log_file_name) - file_handler.setLevel(logging.INFO) - file_handler.setFormatter(formatter) - root_logger.addHandler(file_handler) - - stream_handler = logging.StreamHandler(sys.stdout) - stream_handler.setLevel(logging.INFO) - stream_handler.setFormatter(formatter) - root_logger.addHandler(stream_handler) - - asyncio.run(main()) diff --git a/requirements.txt b/requirements.txt index e6944f0..06fb2ff 100644 --- a/requirements.txt +++ b/requirements.txt @@ -16,3 +16,4 @@ pytest-asyncio asynctest aioresponses aiogram_tests +redis \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/handlers/__init__.py b/tests/handlers/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/handlers/admin/__init__.py b/tests/handlers/admin/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/handlers/users/__init__.py b/tests/handlers/users/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/handlers/users/test_start.py b/tests/handlers/users/test_start.py index 6d5f94c..f026681 100644 --- a/tests/handlers/users/test_start.py +++ b/tests/handlers/users/test_start.py @@ -1,5 +1,4 @@ # import pytest - # from bot.handlers.users.start import start_handler # from aiogram_tests import MockedBot @@ -12,4 +11,4 @@ # request = MockedBot(MessageHandler(start_handler)) # calls = await request.query(message=MESSAGE.as_object(text="Hello, Bot!")) # answer_message = calls.send_messsage.fetchone() -# assert answer_message.text == "Hello, Bot!" \ No newline at end of file +# assert answer_message.text == "Hello, Bot!" diff --git a/tests/moduls/__init__.py b/tests/moduls/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py new file mode 100644 index 0000000..bbbafa5 --- /dev/null +++ b/tests/unit/conftest.py @@ -0,0 +1,98 @@ +# import asyncio +# import pytest +# from unittest.mock import AsyncMock, MagicMock +# from aiogram import Bot, Dispatcher +# from bot.data.config import BOT_TOKEN +# from tests.unit.fakebot import FakeBot, FakeDispatcher +# from aiogram.fsm.storage.memory import MemoryStorage + + +# @pytest.fixture +# def bot(): +# return Bot(token=BOT_TOKEN, parse_mode="HTML") + +# @pytest.fixture +# def dispatcher(bot): +# storage = MemoryStorage() +# return Dispatcher(bot=bot, storage=storage) + + + +# # @pytest.fixture(scope="session") +# # def event_loop(): +# # loop = asyncio.get_event_loop_policy().new_event_loop() +# # yield loop +# # loop.close() +# # @pytest.fixture(autouse=True) +# # def patch_bot_and_dp(fake_bot): +# # # bot.loader da asl bot va dp o‘rniga fake’larni o‘rnatamiz +# # bot.loader.bot = fake_bot +# # bot.loader.dp = FakeDispatcher(fake_bot) +# # yield + +# @pytest.fixture +# def fake_bot(): +# return FakeBot(username="test_bot") + +# @pytest.fixture +# def dp(fake_bot): +# # Bizning real `bot.loader.dp` o‘rniga FakeDispatcher ulanadi +# return FakeDispatcher(fake_bot) + +# @pytest.fixture +# def bot_token(monkeypatch): +# monkeypatch.setenv("BOT_TOKEN", BOT_TOKEN) +# return BOT_TOKEN + +# @pytest.fixture +# def bot(bot_token): +# return Bot(token=bot_token) + +# @pytest.fixture +# def dp(bot): +# """A fresh Dispatcher for each test (if you need it).""" +# return Dispatcher() + +# @pytest.fixture +# def bot_instance(): +# return Bot(token=BOT_TOKEN, parse_mode="HTML") + + + +# # @pytest.fixture +# # def fake_db(monkeypatch): +# # print("Creating fake DB") +# # # class DummyDB: +# # def __init__(self): +# # self.texts = {} +# # self.translations = {} + +# # def select_texts(self, hash_value): +# # return self.texts.get(hash_value) + +# # def insert_texts(self, hash_value, text): +# # idx = len(self.texts) + 1 +# # self.texts[hash_value] = idx +# # return idx + +# # def select_translations(self, text_id, dest_lang): +# # return self.translations.get((text_id, dest_lang)) + +# # def insert_translations(self, text_id, dest_lang, translated_content): +# # self.translations[(text_id, dest_lang)] = translated_content + +# # db = DummyDB() + +# # monkeypatch.setattr("bot.db.database.Database", lambda *args, **kw: db) +# # return db + +# # @pytest.fixture +# # def feature_manager(): +# # class DummyFM: +# # def feature(self, name): return True +# # return DummyFM() + +# # @pytest.fixture +# # def translator(fake_db, feature_manager): +# # from bot.api.translator import Translator +# # return Translator(db=fake_db, FM=feature_manager) From afceca5f67dd074ac0d0e6ff57d7c7264973ec92 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 19:07:36 +0500 Subject: [PATCH 42/71] refactor: Remove unused test fixtures and commented code from conftest.py --- tests/unit/conftest.py | 98 ------------------------------------------ 1 file changed, 98 deletions(-) diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index bbbafa5..e69de29 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -1,98 +0,0 @@ -# import asyncio -# import pytest -# from unittest.mock import AsyncMock, MagicMock -# from aiogram import Bot, Dispatcher -# from bot.data.config import BOT_TOKEN -# from tests.unit.fakebot import FakeBot, FakeDispatcher -# from aiogram.fsm.storage.memory import MemoryStorage - - -# @pytest.fixture -# def bot(): -# return Bot(token=BOT_TOKEN, parse_mode="HTML") - -# @pytest.fixture -# def dispatcher(bot): -# storage = MemoryStorage() -# return Dispatcher(bot=bot, storage=storage) - - - -# # @pytest.fixture(scope="session") -# # def event_loop(): -# # loop = asyncio.get_event_loop_policy().new_event_loop() -# # yield loop -# # loop.close() -# # @pytest.fixture(autouse=True) -# # def patch_bot_and_dp(fake_bot): -# # # bot.loader da asl bot va dp o‘rniga fake’larni o‘rnatamiz -# # bot.loader.bot = fake_bot -# # bot.loader.dp = FakeDispatcher(fake_bot) -# # yield - -# @pytest.fixture -# def fake_bot(): -# return FakeBot(username="test_bot") - -# @pytest.fixture -# def dp(fake_bot): -# # Bizning real `bot.loader.dp` o‘rniga FakeDispatcher ulanadi -# return FakeDispatcher(fake_bot) - -# @pytest.fixture -# def bot_token(monkeypatch): -# monkeypatch.setenv("BOT_TOKEN", BOT_TOKEN) -# return BOT_TOKEN - -# @pytest.fixture -# def bot(bot_token): -# return Bot(token=bot_token) - -# @pytest.fixture -# def dp(bot): -# """A fresh Dispatcher for each test (if you need it).""" -# return Dispatcher() - -# @pytest.fixture -# def bot_instance(): -# return Bot(token=BOT_TOKEN, parse_mode="HTML") - - - -# # @pytest.fixture -# # def fake_db(monkeypatch): -# # print("Creating fake DB") -# # # class DummyDB: -# # def __init__(self): -# # self.texts = {} -# # self.translations = {} - -# # def select_texts(self, hash_value): -# # return self.texts.get(hash_value) - -# # def insert_texts(self, hash_value, text): -# # idx = len(self.texts) + 1 -# # self.texts[hash_value] = idx -# # return idx - -# # def select_translations(self, text_id, dest_lang): -# # return self.translations.get((text_id, dest_lang)) - -# # def insert_translations(self, text_id, dest_lang, translated_content): -# # self.translations[(text_id, dest_lang)] = translated_content - -# # db = DummyDB() - -# # monkeypatch.setattr("bot.db.database.Database", lambda *args, **kw: db) -# # return db - -# # @pytest.fixture -# # def feature_manager(): -# # class DummyFM: -# # def feature(self, name): return True -# # return DummyFM() - -# # @pytest.fixture -# # def translator(fake_db, feature_manager): -# # from bot.api.translator import Translator -# # return Translator(db=fake_db, FM=feature_manager) From 7025e4096e654b64ec38dea9367e3bf143a5918a Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 19:10:08 +0500 Subject: [PATCH 43/71] feat: Add empty __init__.py files for admin and user handlers to initialize packages --- bot/handlers/admins/__init__.py | 0 bot/handlers/admins/admin_settings/__init__.py | 0 bot/handlers/admins/callback_query/__init__.py | 0 bot/handlers/admins/channel_settings/__init__.py | 0 bot/handlers/admins/check_usr/__init__.py | 0 bot/handlers/admins/send_ads/__init__.py | 0 bot/handlers/admins/statistika/__init__.py | 0 bot/handlers/users/__init__.py | 0 8 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 bot/handlers/admins/__init__.py create mode 100644 bot/handlers/admins/admin_settings/__init__.py create mode 100644 bot/handlers/admins/callback_query/__init__.py create mode 100644 bot/handlers/admins/channel_settings/__init__.py create mode 100644 bot/handlers/admins/check_usr/__init__.py create mode 100644 bot/handlers/admins/send_ads/__init__.py create mode 100644 bot/handlers/admins/statistika/__init__.py create mode 100644 bot/handlers/users/__init__.py diff --git a/bot/handlers/admins/__init__.py b/bot/handlers/admins/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bot/handlers/admins/admin_settings/__init__.py b/bot/handlers/admins/admin_settings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bot/handlers/admins/callback_query/__init__.py b/bot/handlers/admins/callback_query/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bot/handlers/admins/channel_settings/__init__.py b/bot/handlers/admins/channel_settings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bot/handlers/admins/check_usr/__init__.py b/bot/handlers/admins/check_usr/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bot/handlers/admins/send_ads/__init__.py b/bot/handlers/admins/send_ads/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bot/handlers/admins/statistika/__init__.py b/bot/handlers/admins/statistika/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/bot/handlers/users/__init__.py b/bot/handlers/users/__init__.py new file mode 100644 index 0000000..e69de29 From 8e564b0955d4636cc0f52dc3e302cd66b3cc7ee9 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 19:22:01 +0500 Subject: [PATCH 44/71] refactor: Clean up imports and enhance feature management in handlers and loader --- bot/handlers/__init__.py | 42 ++++------------------------------ bot/handlers/users/__init__.py | 5 ++++ bot/loader.py | 6 +++-- bot/main.py | 1 + setup.py | 2 +- 5 files changed, 15 insertions(+), 41 deletions(-) diff --git a/bot/handlers/__init__.py b/bot/handlers/__init__.py index 0ab3f0d..145b653 100755 --- a/bot/handlers/__init__.py +++ b/bot/handlers/__init__.py @@ -1,41 +1,7 @@ -from .errors import error_handler +from bot.loader import FM -from .users import start -# from .admins import main_panel +from . import users -# from .admins.admin_settings import add_admin -# from .admins.channel_settings import get_id -# from .admins.check_usr import attach_usr -# # from .admins.check_usr import send_ads_message -# # from .admins.send_ads import get_message -# from .admins import super_admin -# from .users import help +if FM.feature('error_handler'): + from .errors import error_handler -# # from .users import check_usr -# from .users import check_join - - -# from .admins.admin_settings import admin_setting -# from .admins.admin_settings import add_admin_first_step -# from .admins.admin_settings import admin_setting -# from .admins.admin_settings import attach_admins -# from .admins.callback_query import main_admin_panel -# from .admins.admin_settings import edit_admin - -# from .admins.channel_settings import channel_setting -# from .admins.channel_settings import mandatory_membership -# from .admins.channel_settings import add_channel -# from .admins.channel_settings import remove_channel -# from .admins.channel_settings import delete_channel - -# from .admins.check_usr import check_usr -# from .admins.check_usr import block_users -# from .admins.check_usr import send_message - -# # from .admins.send_ads import send_ads -# # from .admins.send_ads import stop_ads - -# from .admins.statistika import staristika -# from .admins.statistika import download_statistics - -# from .users import close diff --git a/bot/handlers/users/__init__.py b/bot/handlers/users/__init__.py index e69de29..fcf42b2 100644 --- a/bot/handlers/users/__init__.py +++ b/bot/handlers/users/__init__.py @@ -0,0 +1,5 @@ +from bot.loader import FM + + +if FM.feature('start'): + from . import start \ No newline at end of file diff --git a/bot/loader.py b/bot/loader.py index 7937640..448003d 100755 --- a/bot/loader.py +++ b/bot/loader.py @@ -2,6 +2,7 @@ from aiogram import Bot, Dispatcher, Router from aiogram.enums import ParseMode from redis import Redis +from redis.asyncio import Redis as AsyncRedis from aiogram.fsm.storage.redis import RedisStorage from aiogram.client.bot import DefaultBotProperties # Yangi versiyadagi default sozlamalar uchun from bot.data.config import * @@ -21,15 +22,16 @@ formatter = logging.Formatter(log_format) redis = Redis(host="localhost", port=6379, db=0, decode_responses=True) +async_redis = AsyncRedis(host="localhost", port=6379, db=1, decode_responses=True) FM = FeatureManager(db=db, root_logger=root_logger, redis_client=redis) -print(f"({BOT_TOKEN})") + # Botni token va default parametr orqali yaratamiz bot = Bot(token=BOT_TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML)) # Xotira asosidagi storage ni yaratamiz -storage = RedisStorage(redis=redis) +storage = RedisStorage(redis=async_redis) # Dispatcher obyektini yaratishda bot va storage ni uzatamiz dp = Dispatcher(bot=bot, storage=storage) diff --git a/bot/main.py b/bot/main.py index d427cba..b08ba64 100755 --- a/bot/main.py +++ b/bot/main.py @@ -1,3 +1,4 @@ +import bot.handlers import logging from bot.loader import * from bot.utils.notify_admins import on_startup_notify # Import the function to notify admins on startup diff --git a/setup.py b/setup.py index c742b21..8dd978c 100644 --- a/setup.py +++ b/setup.py @@ -103,7 +103,7 @@ def main_setup() -> None: from bot.loader import FM - FEATURES = ['translator', 'middlewares', 'save_log'] + FEATURES = ['translator', 'middlewares', 'save_log', 'admin_settings', 'error_handler', 'start'] for feature in FEATURES: x = FM.feature(feature) print(f"🔧 {feature}: {x}") From c03555730df8472e3951f95eabccbfb67d027781 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 19:49:45 +0500 Subject: [PATCH 45/71] Refactor admin filters and handlers; improve logging and feature management - Updated admin filters to use consistent import paths and removed unnecessary comments. - Enhanced logging throughout admin handlers for better error tracking. - Added new admin settings feature and integrated it into the admin panel. - Refactored add_admin and edit_admin handlers for clarity and efficiency. - Improved the structure of admin settings and permissions management. - Updated the setup script to include new features for admin panel functionality. --- bot/__main__.py | 2 + bot/filters/admin.py | 91 +------------------ bot/handlers/__init__.py | 5 + bot/handlers/admins/__init__.py | 9 ++ .../admins/admin_settings/__init__.py | 5 + .../admins/admin_settings/add_admin.py | 61 ++++--------- .../admin_settings/add_admin_first_step.py | 60 ++++-------- .../admins/admin_settings/admin_setting.py | 53 +++-------- .../admins/admin_settings/attach_admins.py | 72 +++++---------- .../admins/admin_settings/edit_admin.py | 70 +++++--------- bot/handlers/admins/main_panel.py | 34 ++----- bot/handlers/admins/super_admin.py | 47 ++-------- bot/handlers/users/__init__.py | 1 + bot/handlers/users/close.py | 13 --- bot/keyboards/inline/admin_btn.py | 32 +++---- setup.py | 9 +- 16 files changed, 160 insertions(+), 404 deletions(-) diff --git a/bot/__main__.py b/bot/__main__.py index bcf2da7..b190d85 100644 --- a/bot/__main__.py +++ b/bot/__main__.py @@ -27,4 +27,6 @@ stream_handler.setFormatter(formatter) root_logger.addHandler(stream_handler) + + asyncio.run(main()) diff --git a/bot/filters/admin.py b/bot/filters/admin.py index 5316aff..4297a32 100644 --- a/bot/filters/admin.py +++ b/bot/filters/admin.py @@ -1,30 +1,15 @@ from aiogram.filters import BaseFilter from aiogram.types import Message -from data.config import ADMIN -from loader import db +from bot.data.config import ADMIN +from bot.loader import db -class IsSuperAdmin(BaseFilter): - """ - Filter to check if the user is a super admin. - - Attributes: - ADMIN (int): The ID of the super admin. - """ +class IsSuperAdmin(BaseFilter): def __init__(self): self.ADMIN = ADMIN async def __call__(self, message: Message) -> bool: - """ - Checks if the message sender is the super admin. - - Args: - message (Message): The message object from the user. - - Returns: - bool: True if the user is the super admin, False otherwise. - """ user_id = message.from_user.id if user_id == self.ADMIN: return True @@ -33,26 +18,10 @@ async def __call__(self, message: Message) -> bool: class IsAdmin(BaseFilter): - """ - Filter to check if the user is an admin or the super admin. - - Attributes: - ADMIN (int): The ID of the super admin. - """ - def __init__(self): self.ADMIN = ADMIN async def __call__(self, message: Message) -> bool: - """ - Checks if the message sender is an admin or the super admin. - - Args: - message (Message): The message object from the user. - - Returns: - bool: True if the user is an admin or the super admin, False otherwise. - """ self.user_id = message.from_user.id self.dada = db.select_admin(user_id=self.user_id) if self.user_id == ADMIN: @@ -64,14 +33,6 @@ async def __call__(self, message: Message) -> bool: class SelectAdmin: - """ - Class to handle various admin-related actions. - - Attributes: - user_id (int): The user ID. - super_admin (int): The ID of the super admin. - dada (list): The admin details from the database. - """ def __init__(self, user_id): self.user_id = user_id @@ -79,12 +40,6 @@ def __init__(self, user_id): self.dada = db.select_admin(user_id=self.user_id) def send_message(self) -> bool: - """ - Checks if the user has permission to send messages. - - Returns: - bool: True if the user can send messages, False otherwise. - """ if self.user_id == self.super_admin: return True elif self.dada['send_message'] == 1: @@ -93,12 +48,6 @@ def send_message(self) -> bool: return False def view_statistika(self) -> bool: - """ - Checks if the user has permission to view statistics. - - Returns: - bool: True if the user can view statistics, False otherwise. - """ if self.user_id == self.super_admin: return True elif self.dada['statistika'] == 1: @@ -107,12 +56,6 @@ def view_statistika(self) -> bool: return False def download_statistika(self) -> bool: - """ - Checks if the user has permission to download statistics. - - Returns: - bool: True if the user can download statistics, False otherwise. - """ if self.user_id == self.super_admin: return True elif self.dada['download_statistika'] == 1: @@ -121,12 +64,6 @@ def download_statistika(self) -> bool: return False def block_user(self) -> bool: - """ - Checks if the user has permission to block other users. - - Returns: - bool: True if the user can block users, False otherwise. - """ if self.user_id == self.super_admin: return True elif self.dada['block_user'] == 1: @@ -135,12 +72,6 @@ def block_user(self) -> bool: return False def channel_settings(self) -> bool: - """ - Checks if the user has permission to change channel settings. - - Returns: - bool: True if the user can change channel settings, False otherwise. - """ if self.user_id == self.super_admin: return True elif self.dada['channel_settings'] == 1: @@ -149,12 +80,6 @@ def channel_settings(self) -> bool: return False def add_admin(self) -> bool: - """ - Checks if the user has permission to add new admins. - - Returns: - bool: True if the user can add new admins, False otherwise. - """ if self.user_id == self.super_admin: return True elif self.dada['add_admin'] == 1: @@ -164,11 +89,6 @@ def add_admin(self) -> bool: def set_data(self) -> bool: - """ - Checks if the user has permission to set data. - Returns: - bool: True if the user can set data, False otherwise. - """ if self.user_id == self.super_admin: return True elif self.dada['set_data'] == 1: @@ -178,11 +98,6 @@ def set_data(self) -> bool: def get_data(self) -> bool: - """ - Checks if the user has permission to get data. - Returns: - bool: True if the user can get data, False otherwise. - """ if self.user_id == self.super_admin: return True elif self.dada['get_data'] == 1: diff --git a/bot/handlers/__init__.py b/bot/handlers/__init__.py index 145b653..82a135e 100755 --- a/bot/handlers/__init__.py +++ b/bot/handlers/__init__.py @@ -2,6 +2,11 @@ from . import users +# error_handler if FM.feature('error_handler'): from .errors import error_handler +# admin_panel +if FM.feature('admin_panel'): + from . import admins + diff --git a/bot/handlers/admins/__init__.py b/bot/handlers/admins/__init__.py index e69de29..5c3617a 100644 --- a/bot/handlers/admins/__init__.py +++ b/bot/handlers/admins/__init__.py @@ -0,0 +1,9 @@ +from bot.loader import FM + + +from . import main_panel +from . import super_admin + +# admin_settings +if FM.feature('admin_settings'): + from . import admin_settings \ No newline at end of file diff --git a/bot/handlers/admins/admin_settings/__init__.py b/bot/handlers/admins/admin_settings/__init__.py index e69de29..5db025b 100644 --- a/bot/handlers/admins/admin_settings/__init__.py +++ b/bot/handlers/admins/admin_settings/__init__.py @@ -0,0 +1,5 @@ +from . import add_admin +from . import add_admin_first_step +from . import admin_setting +from . import attach_admins +from . import edit_admin \ No newline at end of file diff --git a/bot/handlers/admins/admin_settings/add_admin.py b/bot/handlers/admins/admin_settings/add_admin.py index 7de4131..4bbdc26 100755 --- a/bot/handlers/admins/admin_settings/add_admin.py +++ b/bot/handlers/admins/admin_settings/add_admin.py @@ -1,57 +1,34 @@ import logging from aiogram import types from aiogram.fsm.context import FSMContext -from filters.admin import IsAdmin, SelectAdmin -from api.translator import translator -from keyboards.inline.admin_btn import admin_setting -from keyboards.inline.close_btn import close_btn -from loader import dp, bot, db -from states.admin_state import AdminState -from data.config import yil_oy_kun, soat_minut_sekund +from bot.filters.admin import IsAdmin, SelectAdmin +from bot.keyboards.inline.admin_btn import admin_setting +from bot.keyboards.inline.close_btn import close_btn +from bot.loader import dp, bot, db, translator +from bot.states.admin_state import AdminState @dp.message(AdminState.add_admin, IsAdmin()) async def add_admin(msg: types.Message, state: FSMContext): - """ - Handles the addition of a new admin to the system. - Parameters: - - msg (types.Message): The message object containing the admin ID to be added. - - state (FSMContext): The FSM context to manage the bot's state during the conversation. - - Functionality: - - Retrieves the admin's user ID (`user_id`), the message ID (`mid`), and the language code (`lang`) from the message. - - Checks if the sender has the required permissions to add an admin. - - Tries to add the new admin using the provided user ID: - - If the admin is successfully added, sends a confirmation message to both the current admin and the newly added admin. - - If the admin was previously added, sends an appropriate message with existing details. - - Updates the message with a response based on the success or failure of the operation. - - Returns: - - This function is asynchronous and does not return a value. It interacts with the Telegram API to update messages and manage the state. - - Error Handling: - - Catches and logs any exceptions that occur during the addition of the new admin or message editing. - """ try: - user_id = msg.from_user.id # The ID of the admin who is performing the action - mid = msg.message_id # The ID of the message to be updated - language_code = msg.from_user.language_code # The language code for translation - data = SelectAdmin(user_id=user_id) # Retrieves admin settings for the current user - add_admin_db = data.add_admin() # Check if the user has the right to add an admin - target_user_id = int(msg.text) # The ID of the user to be added as an admin + user_id = msg.from_user.id + mid = msg.message_id + language_code = msg.from_user.language_code + data = SelectAdmin(user_id=user_id) + add_admin_db = data.add_admin() + target_user_id = int(msg.text) if add_admin_db: - data_state = await state.get_data() # Get current state data - btn = await admin_setting(user_id=user_id, language_code=language_code) # Prepare admin settings buttons - text = "🔴 Admin failed because admin was not found!\n" + data_state = await state.get_data() + btn = await admin_setting(user_id=user_id, language_code=language_code) + text = "🔴 Failed because admin was not found!\n" try: - user = await bot.get_chat(chat_id=target_user_id) # Get user information - check = db.select_admin(user_id=target_user_id) # Check if the user is already an admin + user = await bot.get_chat(chat_id=target_user_id) + check = db.select_admin(user_id=target_user_id) if check is None: - # Add the new admin to the database db.insert_admin(user_id=target_user_id, initiator_user_id=user_id) text = translator(text="✅ Admin has been successfully added\n\nName: ", @@ -62,7 +39,7 @@ async def add_admin(msg: types.Message, state: FSMContext): text=f'😊Hi @{user.username}, you have been made an admin\n' f'To open the panel, use /admin ', reply_markup=close_btn()) - btn = await admin_setting(user_id=user_id, language_code=language_code) # Prepare admin settings buttons + btn = await admin_setting(user_id=user_id, language_code=language_code) else: text = translator(text="✅ Admin was added before\n\nName: ", dest=language_code) @@ -74,7 +51,7 @@ async def add_admin(msg: types.Message, state: FSMContext): text += translator(text="Added by", dest=language_code) except Exception as err: - logging.error(err) # Log any errors that occur + logging.error(err) text = translator(text="🔴 Admin failed because admin was not found!\n" "The bot may not have found the admin..", dest=language_code) @@ -97,5 +74,5 @@ async def add_admin(msg: types.Message, state: FSMContext): "message_id": mid }) except Exception as err: - logging.error(err) # Log any errors that occur + logging.error(err) diff --git a/bot/handlers/admins/admin_settings/add_admin_first_step.py b/bot/handlers/admins/admin_settings/add_admin_first_step.py index 9123a1e..a56047f 100755 --- a/bot/handlers/admins/admin_settings/add_admin_first_step.py +++ b/bot/handlers/admins/admin_settings/add_admin_first_step.py @@ -1,61 +1,35 @@ -import logging from aiogram import types, F from aiogram.fsm.context import FSMContext -from filters.admin import IsAdmin, SelectAdmin -from api.translator import translator -from keyboards.inline.admin_btn import admin_setting -from keyboards.inline.button import AdminCallback -from keyboards.inline.close_btn import close_btn -from loader import dp, bot -from states.admin_state import AdminState -@dp.callback_query(AdminCallback.filter(F.action == "add_admin"), IsAdmin()) -async def add_admin_first(call: types.CallbackQuery, state: FSMContext): - """ - Handles the initial request to add a new admin. - - Parameters: - - call (types.CallbackQuery): The callback query object from the admin's interaction. - - state (FSMContext): The FSM context to manage the bot's state during the conversation. +from bot.filters.admin import IsAdmin, SelectAdmin +from bot.keyboards.inline.admin_btn import admin_setting +from bot.keyboards.inline.button import AdminCallback +from bot.keyboards.inline.close_btn import close_btn +from bot.loader import dp, bot, root_logger, translator +from bot.states.admin_state import AdminState - Functionality: - - Retrieves the ID of the admin who initiated the request (`user_id`), the message ID (`mid`), and the language code (`lang`). - - Checks if the requesting admin has the rights to add a new admin. - - If the requesting admin has the necessary permissions, prompts them to send the ID of the new admin to be added. - - Sets the state to `AdminState.add_admin` to handle the next step of the process. - - If the requesting admin does not have the necessary permissions, sends a message indicating lack of rights. - - Updates the original message with the appropriate response and buttons based on the outcome. - Returns: - - This function is asynchronous and does not return a value. It interacts with the Telegram API to update messages and manage the state. - - Error Handling: - - Catches and logs any exceptions that occur during the process of handling the callback query or updating the message. - """ +@dp.callback_query(AdminCallback.filter(F.action == "add_admin"), IsAdmin()) +async def add_admin_first(call: types.CallbackQuery, state: FSMContext): try: - user_id = call.from_user.id # ID of the admin initiating the request - mid = call.message.message_id # ID of the message to be updated - language_code = call.from_user.language_code # Language code for translation - data = SelectAdmin(user_id=user_id) # Retrieves admin settings for the current user - add_admin = data.add_admin() # Checks if the user has the right to add an admin + user_id = call.from_user.id + mid = call.message.message_id + language_code = call.from_user.language_code + admin = SelectAdmin(user_id=user_id) - if add_admin: - # Prompt the user to provide the ID of the new admin + if admin.add_admin() : text = translator(text="🔰 Please send the admin ID number you want to add...", dest=language_code) - btn = await admin_setting(user_id=user_id, language_code=language_code) # Prepare admin settings buttons - await state.set_state(AdminState.add_admin) # Set the FSM state for adding an admin + btn = await admin_setting(user_id=user_id, language_code=language_code) + await state.set_state(AdminState.add_admin) else: - # Inform the user that they do not have the necessary permissions text = translator(text="❌ Unfortunately, you do not have this right!", dest=language_code) - btn = close_btn() # Prepare close button + btn = close_btn() - # Update the message with the appropriate response and buttons await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f'{text}', reply_markup=btn) - # Update the state data with the current message ID await state.update_data({"message_id": call.message.message_id}) except Exception as err: - logging.error(err) # Log any errors that occur + root_logger.error(err) diff --git a/bot/handlers/admins/admin_settings/admin_setting.py b/bot/handlers/admins/admin_settings/admin_setting.py index d034d9c..706bf14 100755 --- a/bot/handlers/admins/admin_settings/admin_setting.py +++ b/bot/handlers/admins/admin_settings/admin_setting.py @@ -1,58 +1,35 @@ import logging from aiogram import types, F from aiogram.fsm.context import FSMContext -from filters.admin import IsAdmin, SelectAdmin -from api.translator import translator -from keyboards.inline.admin_btn import admin_setting -from keyboards.inline.button import AdminCallback -from keyboards.inline.close_btn import close_btn -from loader import dp, bot -@dp.callback_query(AdminCallback.filter(F.action == "admin_settings"), IsAdmin()) -async def admin_settings(call: types.CallbackQuery, state: FSMContext): - """ - Handles the callback query for accessing the Admin settings. - - Parameters: - - call (types.CallbackQuery): The callback query object from the admin's interaction. - - state (FSMContext): The FSM context to manage the bot's state during the conversation. +from bot.filters.admin import IsAdmin, SelectAdmin +from bot.keyboards.inline.admin_btn import admin_setting +from bot.keyboards.inline.button import AdminCallback +from bot.keyboards.inline.close_btn import close_btn +from bot.loader import dp, bot, translator - Functionality: - - Retrieves the ID of the admin (`user_id`), the message ID (`mid`), and the language code (`lang`). - - Checks if the admin has the permissions to access the Admin settings. - - If permissions are granted, presents the admin with the settings options. - - If permissions are denied, informs the admin that they lack the necessary rights. - - Updates the original message with the appropriate response and buttons. - Returns: - - This function is asynchronous and does not return a value. It interacts with the Telegram API to update messages. - Error Handling: - - Catches and logs any exceptions that occur during the process of handling the callback query or updating the message. - """ +@dp.callback_query(AdminCallback.filter(F.action == "admin_settings"), IsAdmin()) +async def admin_settings(call: types.CallbackQuery, state: FSMContext): try: - user_id = call.from_user.id # ID of the admin initiating the request - mid = call.message.message_id # ID of the message to be updated - language_code = call.from_user.language_code # Language code for translation - data = SelectAdmin(user_id=user_id) # Retrieves admin settings for the current user - add_admin = data.add_admin() # Checks if the user has the right to access admin settings + user_id = call.from_user.id + mid = call.message.message_id + language_code = call.from_user.language_code + admin = SelectAdmin(user_id=user_id) - if add_admin: - # The admin has the right to access settings + if admin.add_admin(): text = translator(text="❗ You are in the Admin settings section!", dest=language_code) - btn = await admin_setting(user_id=user_id, language_code=language_code) # Prepare admin settings buttons + btn = await admin_setting(user_id=user_id, language_code=language_code) else: - # The admin does not have the necessary rights text = translator(text="❌ Unfortunately, you do not have this right!", dest=language_code) - btn = close_btn() # Prepare close button + btn = close_btn() - # Update the message with the appropriate response and buttons await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f'{text}', reply_markup=btn) - # Update the state data with the current message ID await state.update_data({"message_id": mid}) except Exception as err: - logging.error(err) # Log any errors that occur + logging.error(err) diff --git a/bot/handlers/admins/admin_settings/attach_admins.py b/bot/handlers/admins/admin_settings/attach_admins.py index 563c43a..3f79de6 100755 --- a/bot/handlers/admins/admin_settings/attach_admins.py +++ b/bot/handlers/admins/admin_settings/attach_admins.py @@ -1,59 +1,36 @@ -import logging from aiogram import types, F from aiogram.fsm.context import FSMContext -from data.config import ADMIN -from filters.admin import IsAdmin, SelectAdmin -from function.function import x_or_y -from api.translator import translator -from keyboards.inline.admin_btn import attach_admin_btn -from keyboards.inline.button import AdminSetting -from keyboards.inline.close_btn import close_btn -from loader import dp, bot, db -from states.admin_state import AdminState +from bot.data.config import ADMIN +from bot.filters.admin import IsAdmin, SelectAdmin +from bot.function.function import x_or_y +from bot.keyboards.inline.admin_btn import attach_admin_btn +from bot.keyboards.inline.button import AdminSetting +from bot.keyboards.inline.close_btn import close_btn +from bot.loader import dp, bot, db, root_logger, translator +from bot.states.admin_state import AdminState -@dp.callback_query(AdminSetting.filter(F.action == "attach_admin"), IsAdmin()) -async def attach_admins(call: types.CallbackQuery, callback_data: AdminSetting, state: FSMContext): - """ - Handles the callback query for attaching admin rights to a user. - - Parameters: - - call (types.CallbackQuery): The callback query object triggered by the admin's action. - - callback_data (AdminSetting): Data extracted from the callback query, including the admin ID. - - state (FSMContext): The FSM context for managing the bot's conversation state. - Functionality: - - Extracts the admin's ID (`user_id`), message ID (`mid`), language_codeuage code (`language_code`), and the target admin ID (`admin_user_id`). - - Checks if the current admin has the right to modify admin settings. - - If permitted, fetches the target admin's data and checks the permissions of the current admin. - - Constructs a response message detailing the target admin's rights. - - Updates the message with the constructed text and appropriate buttons. - - Sets the FSM state to `AdminState.add_admin`. - Returns: - - This function is asynchronous and interacts with the Telegram API to update messages. +@dp.callback_query(AdminSetting.filter(F.action == "attach_admin"), IsAdmin()) +async def attach_admins(call: types.CallbackQuery, callback_data: AdminSetting, state: FSMContext): - Error Handling: - - Catches and logs any exceptions that occur during the execution of the function. - """ try: - user_id = call.from_user.id # Current admin's ID - mid = call.message.message_id # Message ID to be updated - language_code = call.from_user.language_code # Admin's language_codeuage preference - admin_user_id = callback_data.user_id # ID of the admin to be modified - data = SelectAdmin(user_id=user_id) # Fetches the current admin's data - btn = close_btn() # Default button to close the operation + user_id = call.from_user.id + mid = call.message.message_id + language_code = call.from_user.language_code + admin_user_id = callback_data.user_id + data = SelectAdmin(user_id=user_id) + btn = close_btn() - # Check if the admin has rights to add another admin if data.add_admin(): - admin_data = db.select_admin(user_id=admin_user_id) # Fetch data for the target admin + admin_data = db.select_admin(user_id=admin_user_id) if admin_data['initiator_user_id'] == user_id or user_id == ADMIN: - # If the current admin added the target admin or is the primary admin btn = attach_admin_btn(user_id=admin_user_id, - language_code=language_code) # Buttons for setting admin rights - is_admin = SelectAdmin(user_id=admin_user_id) # Check target admin's permissions + language_code=language_code) + is_admin = SelectAdmin(user_id=admin_user_id) + - # Format the text showing current permissions of the target admin send_message_tx = x_or_y(is_admin.send_message()) view_statistika_tx = x_or_y(is_admin.view_statistika()) download_statistika_tx = x_or_y(is_admin.download_statistika()) @@ -70,15 +47,12 @@ async def attach_admins(call: types.CallbackQuery, callback_data: AdminSetting, f'Add admin: {add_admin_tx}\n' \ f'Date added: ' else: - # If the current admin does not have the right to modify the target admin text = translator(text='😪You can only change the admin rights you added!', dest=language_code) else: - # If the current admin does not have the necessary rights text = translator(text='❌ Unfortunately, you do not have this right!', dest=language_code) - # Update the message with the admin rights information or error message await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f'{text}', reply_markup=btn) - await state.set_state(AdminState.add_admin) # Set the state to add admin - await state.update_data({"message_id": call.message.message_id}) # Update the state data with the message ID + await state.set_state(AdminState.add_admin) + await state.update_data({"message_id": call.message.message_id}) except Exception as err: - logging.error(err) # Log any errors that occur + root_logger.error(err) diff --git a/bot/handlers/admins/admin_settings/edit_admin.py b/bot/handlers/admins/admin_settings/edit_admin.py index c1a38e5..a0161c5 100755 --- a/bot/handlers/admins/admin_settings/edit_admin.py +++ b/bot/handlers/admins/admin_settings/edit_admin.py @@ -1,67 +1,40 @@ -import logging from aiogram import types, F from aiogram.fsm.context import FSMContext -from data.config import ADMIN -from filters.admin import IsAdmin, SelectAdmin -from function.function import x_or_y -from api.translator import translator -from keyboards.inline.close_btn import close_btn -from loader import dp, bot, db -from states.admin_state import AdminState -from keyboards.inline.button import EditAdminSetting -from keyboards.inline.admin_btn import attach_admin_btn + +from bot.data.config import ADMIN +from bot.filters.admin import IsAdmin, SelectAdmin +from bot.function.function import x_or_y +from bot.keyboards.inline.close_btn import close_btn +from bot.loader import dp, bot, db, root_logger, translator +from bot.states.admin_state import AdminState +from bot.keyboards.inline.button import EditAdminSetting +from bot.keyboards.inline.admin_btn import attach_admin_btn @dp.callback_query(EditAdminSetting.filter(F.action == "edit"), IsAdmin()) async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, state: FSMContext): - """ - Handles the callback query for editing admin settings. - - Parameters: - - call (types.CallbackQuery): The callback query object triggered by the admin's action. - - callback_data (EditAdminSetting): Data extracted from the callback query, including the admin ID and the edit key. - - state (FSMContext): The FSM context for managing the bot's conversation state. - - Functionality: - - Extracts the current admin's ID (`user_id`), message ID (`mid`), language code (`lang`), target admin ID (`admin_user_id`), and the key to be edited (`edit_key`). - - Checks if the current admin has the right to modify admin settings. - - If permitted, fetches the target admin's data. - - Depending on the edit key, either deletes the target admin or updates a specific admin permission. - - Constructs a response message detailing the updated admin rights. - - Updates the message with the constructed text and appropriate buttons. - - Sets the FSM state to `AdminState.add_admin`. - - Returns: - - This function is asynchronous and interacts with the Telegram API to update messages. - - Error Handling: - - Catches and logs any exceptions that occur during the execution of the function. - """ try: - user_id = call.from_user.id # Current admin's ID - mid = call.message.message_id # Message ID to be updated - language_code = call.from_user.language_code # Admin's language preference - admin_user_id = callback_data.user_id # ID of the target admin to be modified - edit_key = callback_data.data # The key indicating what action to perform - data = SelectAdmin(user_id=user_id) # Fetches the current admin's data - add_admin = data.add_admin() # Checks if the current admin can add admins - btn = close_btn() # Default button to close the operation + user_id = call.from_user.id + mid = call.message.message_id + language_code = call.from_user.language_code + admin_user_id = callback_data.user_id + edit_key = callback_data.data + data = SelectAdmin(user_id=user_id) + add_admin = data.add_admin() + btn = close_btn() - # Check if the admin has rights to add another admin if add_admin: - admin_data = db.select_admin(user_id=admin_user_id) # Fetch data for the target admin + admin_data = db.select_admin(user_id=admin_user_id) if admin_data is None: text = f'⛔{admin_user_id} {translator(text="😪 Not available in admin list!", dest=language_code)}' else: if admin_data['initiator_user_id'] == user_id or user_id == ADMIN: if edit_key == "delete_admin": - # If the edit action is to delete the admin db.delete_admin(user_id=admin_user_id) admin_info = await bot.get_chat(chat_id=admin_user_id) text = f'🔪 @{admin_info.username} {translator(text="✅ Removed from admin!", dest=language_code)}' await bot.send_message(chat_id=admin_user_id, text='😪 Your admin rights have been revoked!') else: - # Update the specific admin permission select_column = db.select_admin_column(user_id=admin_user_id, column=edit_key) new_value = 0 if select_column['result'] == 1 else 1 db.update_admin_data(user_id=admin_user_id, column=edit_key, value=new_value, updater_user_id=user_id) @@ -90,10 +63,9 @@ async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, else: text = translator(text='❌ Unfortunately, you do not have this right!', dest=language_code) - # Update the message with the admin rights information or error message await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f"{text}", reply_markup=btn) - await state.set_state(AdminState.add_admin) # Set the state to add admin - await state.update_data({"message_id": call.message.message_id}) # Update the state data with the message ID + await state.set_state(AdminState.add_admin) + await state.update_data({"message_id": call.message.message_id}) except Exception as err: - logging.error(err) # Log any errors that occur + root_logger.error(err) diff --git a/bot/handlers/admins/main_panel.py b/bot/handlers/admins/main_panel.py index 6ac331b..6e40f02 100755 --- a/bot/handlers/admins/main_panel.py +++ b/bot/handlers/admins/main_panel.py @@ -1,58 +1,38 @@ -import logging -from loader import dp, bot +from bot.loader import dp, bot, translator, root_logger +from bot.keyboards.inline.admin_btn import main_admin_panel_btn +from bot.filters.admin import IsAdmin + from aiogram.filters import Command from aiogram import types -from keyboards.inline.admin_btn import main_admin_panel_btn -from filters.admin import IsAdmin + from aiogram.fsm.context import FSMContext -from api.translator import translator @dp.message(Command(commands='admin'), IsAdmin()) async def main_panel(msg: types.Message, state: FSMContext): - """ - Handles the '/admin' command for admin users. Sends a welcome message with an admin panel inline keyboard. - - - Retrieves the user ID and message ID from the incoming message. - - Translates and sends a welcome message to the user with an inline keyboard. - - Deletes any previous message stored in the state to avoid clutter. - - Updates the state with the new message ID. - - Deletes the original command message to keep the chat clean. - - Args: - msg (types.Message): The incoming message object. - state (FSMContext): The finite state machine context to manage state data. - - Raises: - Exception: Logs any errors encountered during the process. - """ try: user_id = msg.from_user.id message_id = msg.message_id language_code = msg.from_user.language_code - # Translate and send the welcome message with admin panel buttons welcome_text = translator(text=f'👩‍💻Hello, dear admin, welcome to the main panel!', dest=language_code) response_msg = await msg.answer(text=f'{welcome_text}', reply_markup=main_admin_panel_btn(user_id=user_id, language_code=language_code)) - # Manage previous message state_data = await state.get_data() try: if 'message_id' in state_data and state_data['message_id'] > 1: await bot.delete_message(chat_id=user_id, message_id=state_data['message_id']) except Exception as err: - logging.error(f"Error deleting previous message: {err}") + root_logger.error(f"Error deleting previous message: {err}") - # Update the state with the new message ID await state.update_data({ "message_id": response_msg.message_id }) - # Delete the original command message await bot.delete_message(chat_id=user_id, message_id=message_id) except Exception as err: - logging.error(f"Unhandled error: {err}") + root_logger.error(f"Unhandled error: {err}") diff --git a/bot/handlers/admins/super_admin.py b/bot/handlers/admins/super_admin.py index 11ca596..21f9338 100755 --- a/bot/handlers/admins/super_admin.py +++ b/bot/handlers/admins/super_admin.py @@ -1,42 +1,18 @@ -import logging -import pandas as pd import os +import pandas as pd from aiogram import types from aiogram.filters import Command -from data.config import log_file_name -from filters.admin import IsSuperAdmin -from loader import dp, bot, db from aiogram.types import FSInputFile +from bot.data.config import log_file_name +from bot.filters.admin import IsSuperAdmin +from bot.loader import dp, bot, db, root_logger + @dp.message(IsSuperAdmin(), Command(commands='stat')) async def super_admin(msg: types.Message): - """ - Handles the '/stat' command from super admins to generate and send a report - of banned users and system logs. - - This function performs the following steps: - 1. Logs the initiation of the stats report generation process. - 2. Retrieves the user ID and message ID from the incoming message. - 3. Fetches all banned users' data from the database. - 4. Constructs a DataFrame with the banned users' details including their IDs, - chat IDs, admin chat IDs, dates of ban, and usernames. - 5. Saves the DataFrame to an Excel file and sends it to the super admin. - 6. Deletes the Excel file from the filesystem after sending. - 7. Checks if the log file exists and is not empty, then sends it to the super admin. - 8. Deletes the original message from the chat. - - Args: - msg (types.Message): The incoming message object containing details of the command. - - Raises: - Exception: Logs any exceptions that occur during the process. - - Returns: - None - """ try: - logging.info('Generating stats report') + root_logger.info('Generating stats report') user_id = msg.from_user.id mid = msg.message_id data = db.select_all_users_ban() @@ -49,7 +25,6 @@ async def super_admin(msg: types.Message): try: if data: - # Collecting data for the DataFrame for x in data: id_list.append(x['id']) user_id_list.append(x['user_id']) @@ -60,7 +35,6 @@ async def super_admin(msg: types.Message): chat = await bot.get_chat(chat_id=x['user_id']) username_list.append(f'@{chat.username}') - # Creating and saving DataFrame to Excel x_data = { "id": id_list, "user_id": user_id_list, @@ -72,7 +46,6 @@ async def super_admin(msg: types.Message): excel_path = 'data/ban.xlsx' df.to_excel(excel_path, index=False) - # Sending the generated Excel file using FSInputFile document = FSInputFile(excel_path) await bot.send_document( chat_id=user_id, @@ -82,10 +55,9 @@ async def super_admin(msg: types.Message): os.remove(excel_path) except Exception as err: - logging.error(f"Error processing ban data: {err}") + root_logger.error(f"Error processing ban data: {err}") try: - # Sending the log file if it exists if os.path.exists(log_file_name) and os.path.getsize(log_file_name) > 0: document2 = FSInputFile(log_file_name) await bot.send_document( @@ -94,10 +66,9 @@ async def super_admin(msg: types.Message): caption='Update log' ) except Exception as err: - logging.error(f"Error sending log file: {err}") + root_logger.error(f"Error sending log file: {err}") - # Deleting the original message await bot.delete_message(chat_id=user_id, message_id=mid) except Exception as err: - logging.error(f"Unhandled error: {err}") \ No newline at end of file + root_logger.error(f"Unhandled error: {err}") \ No newline at end of file diff --git a/bot/handlers/users/__init__.py b/bot/handlers/users/__init__.py index fcf42b2..6fff65d 100644 --- a/bot/handlers/users/__init__.py +++ b/bot/handlers/users/__init__.py @@ -1,5 +1,6 @@ from bot.loader import FM +from . import close if FM.feature('start'): from . import start \ No newline at end of file diff --git a/bot/handlers/users/close.py b/bot/handlers/users/close.py index 85f0a76..8b791f9 100755 --- a/bot/handlers/users/close.py +++ b/bot/handlers/users/close.py @@ -7,22 +7,9 @@ @dp.callback_query(MainCallback.filter(F.action == "close")) async def close(call: types.CallbackQuery, state: FSMContext): - """ - Handles the close callback action. - Clears the FSM context and deletes the message that triggered the callback query. - - Args: - call (types.CallbackQuery): The callback query. - state (FSMContext): The FSM context. - - Returns: - None - """ try: - # Clear the FSM context await state.clear() - # Delete the message that triggered the callback query await bot.delete_message(chat_id=call.from_user.id, message_id=call.message.message_id) except Exception as err: diff --git a/bot/keyboards/inline/admin_btn.py b/bot/keyboards/inline/admin_btn.py index 08f1b12..71cf4b2 100644 --- a/bot/keyboards/inline/admin_btn.py +++ b/bot/keyboards/inline/admin_btn.py @@ -1,12 +1,12 @@ -import logging from aiogram.utils.keyboard import InlineKeyboardBuilder + from .button import AdminCallback, EditAdminSetting, AdminSetting, BlockUser from .close_btn import close_btn -from api.translator import translator -from filters.admin import SelectAdmin -from data.config import ADMIN -from loader import db, bot -from function.function import x_or_y + +from bot.data.config import ADMIN +from bot.loader import db, bot, translator, FM, root_logger +from bot.function.function import x_or_y +from bot.filters.admin import SelectAdmin def main_btn(): @@ -16,7 +16,7 @@ def main_btn(): callback_data=AdminCallback(action="main_adm_panel", data="").pack()) return btn.as_markup() except Exception as err: - logging.error(err) + root_logger.error(err) return False @@ -26,7 +26,7 @@ def main_admin_panel_btn(user_id, language_code): btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) is_admin = SelectAdmin(user_id=user_id) - if is_admin.add_admin(): + if is_admin.add_admin() and FM.feature('admin_settings'): btn.button(text=translator(text=f"👮‍♂️ Admins settings!", dest=language_code), callback_data=AdminCallback(action="admin_settings", data="").pack()) @@ -50,7 +50,7 @@ def main_admin_panel_btn(user_id, language_code): btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) return btn.as_markup() except Exception as err: - logging.error(err) + root_logger.error(err) return False @@ -74,7 +74,7 @@ async def admin_setting(user_id, language_code): btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) return btn.as_markup() except Exception as err: - logging.error(err) + root_logger.error(err) return False @@ -117,7 +117,7 @@ def attach_admin(user_id, language_code): btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) return btn.as_markup() except Exception as err: - logging.error(err) + root_logger.error(err) return False @@ -160,7 +160,7 @@ def attach_admin_btn(user_id, language_code): btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) return btn.as_markup() except Exception as err: - logging.error(err) + root_logger.error(err) return False @@ -188,7 +188,7 @@ def channel_settings(language_code): btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) return btn.as_markup() except Exception as err: - logging.error(err) + root_logger.error(err) return False @@ -213,7 +213,7 @@ def block_user(attention_user_id, language_code, user_id): btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) return btn.as_markup() except Exception as err: - logging.error(err) + root_logger.error(err) return False @@ -230,7 +230,7 @@ def download_statistika(user_id, language_code): btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) return btn.as_markup() except Exception as err: - logging.error(err) + root_logger.error(err) return False @@ -250,7 +250,7 @@ def stop_advertisement(): except Exception as err: # Log any exceptions that occur during the button creation process - logging.error(f"Error in stop_ads function: {err}") + root_logger.error(f"Error in stop_ads function: {err}") # Return False to indicate the failure of the operation return False diff --git a/setup.py b/setup.py index 8dd978c..54883bd 100644 --- a/setup.py +++ b/setup.py @@ -103,7 +103,14 @@ def main_setup() -> None: from bot.loader import FM - FEATURES = ['translator', 'middlewares', 'save_log', 'admin_settings', 'error_handler', 'start'] + FEATURES = ['translator', + 'middlewares', + 'save_log', + 'start', + 'error_handler', + 'admin_panel', + 'admin_settings', + ] for feature in FEATURES: x = FM.feature(feature) print(f"🔧 {feature}: {x}") From 53bbf437e60ed8ec2d75ce737ee5ec8ba1d10043 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 20:03:23 +0500 Subject: [PATCH 46/71] refactor: Organize imports and enhance main admin panel handler functionality --- bot/handlers/admins/__init__.py | 2 + .../admins/callback_query/main_admin_panel.py | 45 +++++-------------- 2 files changed, 13 insertions(+), 34 deletions(-) diff --git a/bot/handlers/admins/__init__.py b/bot/handlers/admins/__init__.py index 5c3617a..de103aa 100644 --- a/bot/handlers/admins/__init__.py +++ b/bot/handlers/admins/__init__.py @@ -3,6 +3,8 @@ from . import main_panel from . import super_admin +from .callback_query import main_admin_panel + # admin_settings if FM.feature('admin_settings'): diff --git a/bot/handlers/admins/callback_query/main_admin_panel.py b/bot/handlers/admins/callback_query/main_admin_panel.py index 031d615..a430e17 100755 --- a/bot/handlers/admins/callback_query/main_admin_panel.py +++ b/bot/handlers/admins/callback_query/main_admin_panel.py @@ -1,51 +1,28 @@ -import logging -from loader import dp, bot from aiogram import types, F -from keyboards.inline.button import AdminCallback -from keyboards.inline.admin_btn import main_admin_panel_btn -from filters.admin import IsAdmin from aiogram.fsm.context import FSMContext -from api.translator import translator + +from bot.loader import dp, bot, translator, root_logger +from bot.keyboards.inline.button import AdminCallback +from bot.keyboards.inline.admin_btn import main_admin_panel_btn +from bot.filters.admin import IsAdmin @dp.callback_query(AdminCallback.filter(F.action == "main_adm_panel"), IsAdmin()) async def main_panel(call: types.CallbackQuery, state: FSMContext): - """ - Handles the callback query for navigating to the main admin panel. - - Parameters: - - call (types.CallbackQuery): The callback query object containing information about the user's action. - - state (FSMContext): The FSM context to manage the bot's state during the conversation. - - Functionality: - - Retrieves the admin's user ID (`user_id`), the message ID (`mid`), and the language code (`lang`) from the callback query. - - Translates a greeting message to the admin in their preferred language. - - Edits the original message in the chat to display the translated greeting and the main admin panel buttons. - - Updates the FSM state with the current message ID. - - Returns: - - This function is asynchronous and does not return a value. It interacts with the Telegram API to update messages and manage the state. - - Error Handling: - - Catches and logs any exceptions that occur during the execution, ensuring that errors are recorded for debugging. - """ try: - user_id = call.from_user.id # The ID of the admin who initiated the action - mid = call.message.message_id # The ID of the message to be updated - language_code = call.from_user.language_code # The language code for translation + user_id = call.from_user.id + mid = call.message.message_id + language_code = call.from_user.language_code - # Translate the greeting message - text = translator(text="👩‍💻Hello, dear admin, welcome to the main panel!", dest=language_code) + text = translator(text="👩‍💻Hello, dear admin, welcome to the main panel!", + dest=language_code) - # Edit the message with the translated text and update it with the main admin panel buttons await bot.edit_message_text(chat_id=user_id, message_id=mid, text=f'{text}', reply_markup=main_admin_panel_btn(user_id=user_id, language_code=language_code)) - # Update FSM state with the current message ID await state.update_data({"message_id": call.message.message_id}) except Exception as err: - # Log any errors that occur during execution - logging.error(err) + root_logger.error(err) From 96d0728942036eed6cdb5b2422f9461b202d4540 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 20:05:00 +0500 Subject: [PATCH 47/71] refactor: Update logging mechanism in close handler and reorganize imports --- bot/handlers/users/close.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bot/handlers/users/close.py b/bot/handlers/users/close.py index 8b791f9..0084737 100755 --- a/bot/handlers/users/close.py +++ b/bot/handlers/users/close.py @@ -1,8 +1,8 @@ -import logging -from loader import bot, dp -from aiogram.fsm.context import FSMContext -from keyboards.inline.button import MainCallback from aiogram import types, F +from aiogram.fsm.context import FSMContext + +from bot.loader import bot, dp, root_logger +from bot.keyboards.inline.button import MainCallback @dp.callback_query(MainCallback.filter(F.action == "close")) @@ -13,5 +13,5 @@ async def close(call: types.CallbackQuery, state: FSMContext): await bot.delete_message(chat_id=call.from_user.id, message_id=call.message.message_id) except Exception as err: - logging.error(f"Error in close handler: {err}") + root_logger.error(f"Error in close handler: {err}") From a068769dc3ed8a5be6ad41b4a196a215ef701147 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 20:52:32 +0500 Subject: [PATCH 48/71] refactor: Enhance Database class with improved logging and SettingsManager integration --- bot/core/settings_manager.py | 62 ++++++++ bot/db/database.py | 208 ++++++++++++-------------- bot/loader.py | 15 +- bot/main.py | 24 ++- bot/middlewares/throttling.py | 70 ++++----- tests/moduls/test_settings_manager.py | 39 +++++ 6 files changed, 242 insertions(+), 176 deletions(-) create mode 100644 bot/core/settings_manager.py create mode 100644 tests/moduls/test_settings_manager.py diff --git a/bot/core/settings_manager.py b/bot/core/settings_manager.py new file mode 100644 index 0000000..6cba876 --- /dev/null +++ b/bot/core/settings_manager.py @@ -0,0 +1,62 @@ +import logging +from typing import Optional, Any + +from redis import Redis, RedisError +from bot.db.database import Database + + +class SettingsManager: + _REDIS_HASH = "settings" + + def __init__( + self, + db: Database, + redis_client: Redis, + root_logger: logging.Logger, + ): + self.db: Database = db + self.redis: Redis = redis_client + self.log: logging.Logger = root_logger + + def get(self, key: str) -> Optional[str]: + try: + cached = self._get_from_redis(key) + if cached is not None: + return cached + + db_val = self.db.select_setting(key) + if db_val is None: + return None + + self.redis.hset(self._REDIS_HASH, key, db_val) + return db_val + + except (RedisError, Exception) as exc: + self.log.error(f"Error in SettingsManager.get('{key}'): {exc}") + return None + + def update(self, key: str, value: Any, updater_user_id: int = -1) -> None: + try: + check = self.db.select_setting(key) + if check is None: + self.db.insert_settings( + initiator_user_id=updater_user_id, + key=key, + value=str(value), + ) + else: + self.db.update_settings_key( + updater_user_id=updater_user_id, + key=key, + value=str(value), + ) + self.redis.hset(self._REDIS_HASH, key, str(value)) + self.log.info(f"Setting '{key}' updated → {value}") + + except (RedisError, Exception) as exc: + self.log.error(f"Error in SettingsManager.update('{key}', '{value}'): {exc}") + raise + + def _get_from_redis(self, key: str) -> Optional[str]: + val = self.redis.hget(self._REDIS_HASH, key) + return val if val is not None else None diff --git a/bot/db/database.py b/bot/db/database.py index 2bda13a..504e11c 100755 --- a/bot/db/database.py +++ b/bot/db/database.py @@ -1,11 +1,10 @@ import logging import mysql.connector from aiogram import Bot -from bot.function.function import to_hash class Database: - def __init__(self, host, user, password, database): + def __init__(self, host, user, password, database, root_logger: logging.Logger): """ Initialize the Database object with connection parameters. """ @@ -13,19 +12,17 @@ def __init__(self, host, user, password, database): self.user = user self.password = password self.database = database + self.root_logger = root_logger self.reconnect() - self.create_table_admins() # Create the admins table - self.create_table_users() # Create the users table - self.create_table_channel() # Create the channel table - self.create_table_settings() # Create the settings table - self.create_table_texts() # Create the texts table - self.create_table_translations() # Create the translations table - self.create_table_features() # Create the features table + self.create_table_admins() + self.create_table_users() + self.create_table_channel() + self.create_table_settings() + self.create_table_texts() + self.create_table_translations() + self.create_table_features() def reconnect(self): - """ - Reconnect to the MySQL database. - """ try: self.connection = mysql.connector.connect( host=self.host, @@ -37,7 +34,7 @@ def reconnect(self): ) self.cursor = self.connection.cursor(dictionary=True, buffered=True) except mysql.connector.Error as err: - logging.error(f"Database connection error: {err}") + self.root_logger.error(f"Database connection error: {err}") raise def __del__(self): @@ -48,9 +45,9 @@ def __del__(self): if hasattr(self, 'connection') and self.connection.is_connected(): self.connection.close() except mysql.connector.Error as err: - logging.error(f"MySQL Error in __del__: {err}") + self.root_logger.error(f"MySQL Error in __del__: {err}") except Exception as err: - logging.error(f"General Error in __del__: {err}") + self.root_logger.error(f"General Error in __del__: {err}") ## --------------------- Create table ------------------## @@ -76,10 +73,10 @@ def create_table_users(self): self.cursor.execute(sql) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def create_table_channel(self): """ @@ -99,10 +96,10 @@ def create_table_channel(self): self.cursor.execute(sql) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def create_table_admins(self): """ @@ -128,10 +125,10 @@ def create_table_admins(self): self.cursor.execute(sql) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def create_table_settings(self): """ @@ -152,10 +149,10 @@ def create_table_settings(self): self.cursor.execute(sql) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def create_table_texts(self): try: @@ -173,10 +170,10 @@ def create_table_texts(self): self.cursor.execute(sql) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def create_table_translations(self): try: @@ -195,10 +192,10 @@ def create_table_translations(self): self.cursor.execute(sql) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def create_table_features(self): try: @@ -215,10 +212,10 @@ def create_table_features(self): self.cursor.execute(sql) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) ## ---------------- Scheduler --------------------- def ban_user_for_one_hour(self, user_id, comment=None): @@ -248,10 +245,10 @@ def ban_user_for_one_hour(self, user_id, comment=None): _ = self.cursor.fetchall() # Natijani o‘qish orqali tozalaymiz self.connection.commit() except mysql.connector.Error as err: - logging.error(f"MySQL error: {err}") + self.root_logger.error(f"MySQL error: {err}") self.reconnect() except Exception as err: - logging.error(f"General error: {err}") + self.root_logger.error(f"General error: {err}") ## ------------------ Insert data ------------------ ## @@ -262,10 +259,10 @@ def insert_feature(self, name: str, enabled: bool): self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def insert_texts(self, hash_value: str, raw_text: str): """ @@ -278,10 +275,10 @@ def insert_texts(self, hash_value: str, raw_text: str): self.connection.commit() return self.cursor.lastrowid except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def insert_translations(self, text_id: int, dest_lang: str, translated_content: str): try: @@ -290,10 +287,10 @@ def insert_translations(self, text_id: int, dest_lang: str, translated_content: self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def insert_settings(self, initiator_user_id, key, value): """ @@ -305,10 +302,10 @@ def insert_settings(self, initiator_user_id, key, value): self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def insert_user(self, user_id, language_code): """ @@ -322,10 +319,10 @@ def insert_user(self, user_id, language_code): self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def insert_channel(self, channel_id, initiator_user_id): """ @@ -339,10 +336,10 @@ def insert_channel(self, channel_id, initiator_user_id): self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def insert_admin(self, user_id, initiator_user_id): """ @@ -356,10 +353,10 @@ def insert_admin(self, user_id, initiator_user_id): self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) ## ------------------ Update ------------------ ## def update_feature(self, name: str, enabled: bool): @@ -372,17 +369,13 @@ def update_feature(self, name: str, enabled: bool): self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def update_settings_key(self, updater_user_id, key, value): - """ - Update a setting in the 'settings' table. - """ try: - # Removed the extra comma before WHERE clause sql = """ UPDATE settings SET `value` = %s, `updater_user_id` = %s WHERE `key` = %s """ @@ -390,10 +383,10 @@ def update_settings_key(self, updater_user_id, key, value): self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def update_admin_data(self, user_id, column, value, updater_user_id): """ @@ -402,7 +395,7 @@ def update_admin_data(self, user_id, column, value, updater_user_id): """ allowed_columns = {'send_message', 'statistika', 'download_statistika', 'block_user', 'channel_settings', 'add_admin'} if column not in allowed_columns: - logging.error(f"Invalid column '{column}' specified for update_admin_data") + self.root_logger.error(f"Invalid column '{column}' specified for update_admin_data") return try: sql = f"UPDATE admins SET {column} = %s, updater_user_id = %s WHERE user_id = %s" @@ -410,10 +403,10 @@ def update_admin_data(self, user_id, column, value, updater_user_id): self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def update_user_status(self, user_id, status, updater_user_id): """ @@ -425,10 +418,10 @@ def update_user_status(self, user_id, status, updater_user_id): self.cursor.execute(sql, values) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) ## ------------------ Select ------------------ ## def select_feature(self, name: str): @@ -442,10 +435,10 @@ def select_feature(self, name: str): result = self.cursor.fetchone() return None if result is None else result['enabled'] except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def select_texts(self, hash_value: str): try: @@ -455,10 +448,10 @@ def select_texts(self, hash_value: str): result = self.cursor.fetchone() return None if result is None else result['id'] except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def select_translations(self, text_id: int, dest_lang: str): try: @@ -468,15 +461,12 @@ def select_translations(self, text_id: int, dest_lang: str): result = self.cursor.fetchone() return None if result is None else result['translated_content'] except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def select_setting(self, key: str): - """ - Select a setting from the 'settings' table. - """ try: sql = "SELECT `value` FROM `settings` WHERE `key` = %s" values = (key,) @@ -484,10 +474,10 @@ def select_setting(self, key: str): result = self.cursor.fetchone() return None if result is None else result['value'] except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def select_all_users_ban(self): """ @@ -499,10 +489,10 @@ def select_all_users_ban(self): result = self.cursor.fetchall() return result except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def stat_ban(self): """ @@ -514,10 +504,10 @@ def stat_ban(self): result = self.cursor.fetchone() return result['user_count'] except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def check_user_ban(self, user_id): """ @@ -529,10 +519,10 @@ def check_user_ban(self, user_id): result = self.cursor.fetchone() return result except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def delete_user_ban(self, user_id): """ @@ -543,10 +533,10 @@ def delete_user_ban(self, user_id): self.cursor.execute(sql, (user_id,)) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def select_all_users(self): """ @@ -558,10 +548,10 @@ def select_all_users(self): result = self.cursor.fetchall() return result except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def select_users_by_id(self, start_id: int, end_id: int) -> list: """ @@ -574,10 +564,10 @@ def select_users_by_id(self, start_id: int, end_id: int) -> list: result = self.cursor.fetchall() return result except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def select_admins_by_id(self, start_id: int, end_id: int) -> list: """ @@ -590,10 +580,10 @@ def select_admins_by_id(self, start_id: int, end_id: int) -> list: result = self.cursor.fetchall() return result except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def stat(self): """ @@ -605,10 +595,10 @@ def stat(self): result = self.cursor.fetchone() return result['total_users'] except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def check_user(self, user_id): """ @@ -620,10 +610,10 @@ def check_user(self, user_id): result = self.cursor.fetchone() return result except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def select_admin_column(self, user_id, column): """ @@ -635,10 +625,10 @@ def select_admin_column(self, user_id, column): result = self.cursor.fetchone() return result except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def select_admin(self, user_id): """ @@ -650,10 +640,10 @@ def select_admin(self, user_id): result = self.cursor.fetchone() return result except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def select_add_admin(self, user_id): """ @@ -665,10 +655,10 @@ def select_add_admin(self, user_id): result = self.cursor.fetchall() return result except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def select_all_admins(self): """ @@ -680,10 +670,10 @@ def select_all_admins(self): result = self.cursor.fetchall() return result except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def stat_admins(self): """ @@ -695,10 +685,10 @@ def stat_admins(self): result = self.cursor.fetchone() return result[list(result.keys())[0]] except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def delete_admin(self, user_id): """ @@ -709,10 +699,10 @@ def delete_admin(self, user_id): self.cursor.execute(sql, (user_id,)) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def select_channels(self): """ @@ -724,10 +714,10 @@ def select_channels(self): results = self.cursor.fetchall() return results except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def select_channels_initiator_user_id(self, initiator_user_id): """ @@ -739,10 +729,10 @@ def select_channels_initiator_user_id(self, initiator_user_id): result = self.cursor.fetchall() return result except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def check_channel(self, channel_id): """ @@ -754,10 +744,10 @@ def check_channel(self, channel_id): result = self.cursor.fetchone() return result except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def select_all_channel(self): """ @@ -769,10 +759,10 @@ def select_all_channel(self): result = self.cursor.fetchall() return result except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) def delete_channel(self, channel_id): """ @@ -783,10 +773,10 @@ def delete_channel(self, channel_id): self.cursor.execute(sql, (channel_id,)) self.connection.commit() except mysql.connector.Error as err: - logging.error(err) + self.root_logger.error(err) self.reconnect() except Exception as err: - logging.error(err) + self.root_logger.error(err) diff --git a/bot/loader.py b/bot/loader.py index 448003d..0273620 100755 --- a/bot/loader.py +++ b/bot/loader.py @@ -4,20 +4,23 @@ from redis import Redis from redis.asyncio import Redis as AsyncRedis from aiogram.fsm.storage.redis import RedisStorage -from aiogram.client.bot import DefaultBotProperties # Yangi versiyadagi default sozlamalar uchun +from aiogram.client.bot import DefaultBotProperties from bot.data.config import * from bot.db.database import Database from bot.api.translator import Translator from bot.core.feature_manager import FeatureManager +from bot.core.settings_manager import SettingsManager -# MySQL ma'lumotlar bazasi ulanishini yaratamiz -db = Database(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE) root_logger = logging.getLogger() root_logger.setLevel(logging.INFO) + +db = Database(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE, root_logger=root_logger) + + log_format = '%(filename)s - %(funcName)s - %(lineno)d - %(name)s - %(levelname)s - %(message)s' formatter = logging.Formatter(log_format) @@ -26,19 +29,15 @@ FM = FeatureManager(db=db, root_logger=root_logger, redis_client=redis) - -# Botni token va default parametr orqali yaratamiz bot = Bot(token=BOT_TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML)) -# Xotira asosidagi storage ni yaratamiz storage = RedisStorage(redis=async_redis) -# Dispatcher obyektini yaratishda bot va storage ni uzatamiz dp = Dispatcher(bot=bot, storage=storage) -# Router obyektini yaratamiz router = Router() +SM = SettingsManager(db=db, redis_client=redis, root_logger=root_logger) translator = Translator(db=db, FM=FM) diff --git a/bot/main.py b/bot/main.py index b08ba64..c0c0938 100755 --- a/bot/main.py +++ b/bot/main.py @@ -1,44 +1,38 @@ import bot.handlers import logging from bot.loader import * -from bot.utils.notify_admins import on_startup_notify # Import the function to notify admins on startup -from bot.utils.set_bot_commands import set_default_commands # Import the function to set default bot commands +from bot.utils.notify_admins import on_startup_notify +from bot.utils.set_bot_commands import set_default_commands from bot.db.database import MySQLHandler async def main(): - """ - The main asynchronous function to start the bot and perform initial setup. - """ await on_startup_notify() - await set_default_commands() # Set the default commands for the bot + await set_default_commands() try: # middlewares + SM.update(key='test', value='test') + print(db.select_setting('test')) if FM.feature('middlewares'): from bot.middlewares.throttling import ThrottlingMiddleware - dp.update.middleware.register(ThrottlingMiddleware(db=db, bot=bot)) # Register the ThrottlingMiddleware + dp.update.middleware.register(ThrottlingMiddleware(db=db, bot=bot)) - # save_log if FM.feature('save_log'): mysql_handler = MySQLHandler(bot=bot, connection=db.connection) - # log_format = '%(filename)s - %(funcName)s - %(lineno)d - %(name)s - %(levelname)s - %(message)s' - # formatter = logging.Formatter(log_format) root_logger.addHandler(mysql_handler) mandatory_membership = db.select_setting('mandatory_membership') if mandatory_membership is None: db.insert_settings(initiator_user_id=1, key='mandatory_membership', value='False') - # Delete any existing webhook and start polling await bot.delete_webhook(drop_pending_updates=True) await dp.start_polling(bot) finally: - # Log the database statistics and close the bot session - res = db.stat() # Get database statistics - logging.info(res) # Log the database statistics - await bot.session.close() # Close the bot session + res = db.stat() + logging.info(res) + await bot.session.close() diff --git a/bot/middlewares/throttling.py b/bot/middlewares/throttling.py index 01dc6ac..39806ca 100755 --- a/bot/middlewares/throttling.py +++ b/bot/middlewares/throttling.py @@ -1,43 +1,31 @@ import time -import logging -from bot.data.config import ADMIN -from bot.keyboards.inline.close_btn import close_btn from aiogram import BaseMiddleware, types from aiogram.utils.keyboard import InlineKeyboardBuilder +from aiogram import Bot + +from bot.data.config import ADMIN +from bot.keyboards.inline.close_btn import close_btn from bot.keyboards.inline.button import MainCallback -from bot.loader import translator +from bot.loader import translator, root_logger, FM +from bot.db.database import Database class ThrottlingMiddleware(BaseMiddleware): - """ - Middleware class to manage throttling of requests to prevent overloading. - This middleware limits the rate of incoming requests from users. - If a user exceeds the allowed request rate, they will receive a message indicating that they are making too many requests. - If a user receives the throttling warning 3 times within 1 minute, they are banned for 1 hour. - """ - - def __init__(self, bot, db, default_rate: float = 0.5) -> None: - """ - Initializes the ThrottlingMiddleware instance. - - Parameters: - - default_rate (float): The minimal interval between allowed requests (in seconds), default is 0.5 seconds. - """ - self.limiters = {} # Dictionary to store per-user throttling data. + def __init__(self, + bot: Bot, + db: Database, + default_rate: float = 0.5) -> None: + + self.limiters = {} self.default_rate = default_rate self.bot = bot self.db = db - async def __call__(self, handler, event: types.Message, data): - """ - Processes incoming messages and enforces throttling rules. - If a user triggers throttling 3 times in 1 minute, they will be banned for 1 hour. - """ + async def __call__(self, handler, event: types, data): real_handler = data["handler"] skip_pass = True - # Determine user id and language code. if event.message: user_id = event.message.from_user.id language_code = event.message.from_user.language_code @@ -57,7 +45,8 @@ async def __call__(self, handler, event: types.Message, data): is_ban = await self.check_ban(user_data) if is_ban: return - is_member = await self.check_member(user_id=user_id, language_code=language_code) + is_member = await self.check_member(user_id=user_id, + language_code=language_code) if is_member: return @@ -65,28 +54,22 @@ async def __call__(self, handler, event: types.Message, data): skip_pass = real_handler.flags.get("skip_pass") now = time.time() - # For each user we track: - # "last": timestamp of the last request, - # "count": number of throttled events in the current window, - # "first": start timestamp of the current 1-minute window. + user_data = self.limiters.get(user_id, {"last": now, "count": 0, "first": now}) if skip_pass: - # If enough time has passed since the last request, reset the throttling counter. if now - user_data["last"] >= self.default_rate: user_data["last"] = now - user_data["count"] = 0 # Reset counter. + user_data["count"] = 0 user_data["first"] = now self.limiters[user_id] = user_data return await handler(event, data) else: - # Update the throttling counter. If the current window is over 60 seconds, reset it. if now - user_data["first"] > 60: user_data["count"] = 0 user_data["first"] = now user_data["count"] += 1 - # Agar throttling hisobi 3 yoki undan ko'p bo'lsa, foydalanuvchini ban qilamiz. if user_data["count"] >= 3: try: self.db.ban_user_for_one_hour(user_id, comment="1 hour due to too many requests.") @@ -96,8 +79,7 @@ async def __call__(self, handler, event: types.Message, data): ) await self.bot.send_message(chat_id=user_id, text=tx) except Exception as err: - logging.error(f"Error banning user {user_id}: {err}") - # Reset the counter to oldindan qayta-ban qilishdan saqlanish uchun. + root_logger.error(f"Error banning user {user_id}: {err}") user_data["count"] = 0 else: try: @@ -111,7 +93,7 @@ async def __call__(self, handler, event: types.Message, data): reply_markup=close_btn() ) except Exception as err: - logging.error(err) + root_logger.error(err) user_data["last"] = now self.limiters[user_id] = user_data @@ -161,7 +143,9 @@ async def check_member(self, user_id, language_code): try: is_mandatory = self.db.select_setting('mandatory_membership') if is_mandatory is None: - self.db.update_settings_key(updater_user_id=1, key='mandatory_membership', value=False) + self.db.update_settings_key(updater_user_id=1, + key='mandatory_membership', + value=False) return False elif is_mandatory == 'False': return False @@ -169,7 +153,7 @@ async def check_member(self, user_id, language_code): try: channels = self.db.select_channels() except Exception as err: - logging.error(f"Error selecting channels: {err}") + root_logger.error(f"Error selecting channels: {err}") return False for channel in channels: @@ -190,10 +174,9 @@ async def check_member(self, user_id, language_code): try: chat_member_status = await self.bot.get_chat_member(chat_id=channel_id, user_id=user_id) except Exception as e: - logging.error(f"Error getting chat member status: {e}") + root_logger.error(f"Error getting chat member status: {e}") continue - # Check if the user is a member of the channel if chat_member_status.status not in ('member', 'administrator', 'creator'): count += 1 message_text += f"\n{count}. ⭕ {channel.full_name} @{channel.username} ❓\n" @@ -211,12 +194,11 @@ async def check_member(self, user_id, language_code): reply_markup=keyboard.as_markup()) return True except Exception as err: - logging.error(f"Error checking membership for channel {channel.get('channel_id')}: {err}") + root_logger.error(f"Error checking membership for channel {channel.get('channel_id')}: {err}") continue - # If all channels checked and no problems found, return False. return False except Exception as err: - logging.error(err) + root_logger.error(err) return False \ No newline at end of file diff --git a/tests/moduls/test_settings_manager.py b/tests/moduls/test_settings_manager.py new file mode 100644 index 0000000..3fd879c --- /dev/null +++ b/tests/moduls/test_settings_manager.py @@ -0,0 +1,39 @@ +import pytest +from bot.loader import SM, db, redis + +TEST_KEY = "test_setting_key" +INITIAL_VALUE = "initial_test_value" +UPDATED_VALUE = "updated_test_value" + +@pytest.fixture(autouse=True) +def setup_teardown(): + redis.hdel(SM._REDIS_HASH, TEST_KEY) + db.cursor.execute("DELETE FROM settings WHERE `key`=%s", (TEST_KEY,)) + db.connection.commit() + yield + redis.hdel(SM._REDIS_HASH, TEST_KEY) + db.cursor.execute("DELETE FROM settings WHERE `key`=%s", (TEST_KEY,)) + db.connection.commit() + +def test_settings_manager_get_and_update(): + assert SM.get(TEST_KEY) is None + + SM.update(TEST_KEY, INITIAL_VALUE, updater_user_id=12345) + + redis_val = redis.hget(SM._REDIS_HASH, TEST_KEY) + assert redis_val == INITIAL_VALUE + + db_val = db.select_setting(TEST_KEY) + assert db_val == INITIAL_VALUE + + assert SM.get(TEST_KEY) == INITIAL_VALUE + + SM.update(TEST_KEY, UPDATED_VALUE, updater_user_id=54321) + + redis_updated_val = redis.hget(SM._REDIS_HASH, TEST_KEY) + assert redis_updated_val == UPDATED_VALUE + + db_updated_val = db.select_setting(TEST_KEY) + assert db_updated_val == UPDATED_VALUE + + assert SM.get(TEST_KEY) == UPDATED_VALUE From d10fbc3c256311099dfc21eb24609429f94e5fb5 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 20:56:47 +0500 Subject: [PATCH 49/71] Add tests for feature manager functionality --- bot/main.py | 5 ---- tests/moduls/test_feature_manager.py | 40 ++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 tests/moduls/test_feature_manager.py diff --git a/bot/main.py b/bot/main.py index c0c0938..0feec94 100755 --- a/bot/main.py +++ b/bot/main.py @@ -12,8 +12,6 @@ async def main(): try: # middlewares - SM.update(key='test', value='test') - print(db.select_setting('test')) if FM.feature('middlewares'): from bot.middlewares.throttling import ThrottlingMiddleware dp.update.middleware.register(ThrottlingMiddleware(db=db, bot=bot)) @@ -23,9 +21,6 @@ async def main(): mysql_handler = MySQLHandler(bot=bot, connection=db.connection) root_logger.addHandler(mysql_handler) - mandatory_membership = db.select_setting('mandatory_membership') - if mandatory_membership is None: - db.insert_settings(initiator_user_id=1, key='mandatory_membership', value='False') await bot.delete_webhook(drop_pending_updates=True) await dp.start_polling(bot) diff --git a/tests/moduls/test_feature_manager.py b/tests/moduls/test_feature_manager.py new file mode 100644 index 0000000..649d76b --- /dev/null +++ b/tests/moduls/test_feature_manager.py @@ -0,0 +1,40 @@ +import pytest +from unittest.mock import patch +from bot.loader import FM, db, redis + +TEST_FEATURE_NAME = "test_feature" +INITIAL_STATE = True +UPDATED_STATE = False + +@pytest.fixture(autouse=True) +def setup_teardown(): + redis.hdel(FM._REDIS_HASH, TEST_FEATURE_NAME) + db.cursor.execute("DELETE FROM features WHERE name=%s", (TEST_FEATURE_NAME,)) + db.connection.commit() + yield + redis.hdel(FM._REDIS_HASH, TEST_FEATURE_NAME) + db.cursor.execute("DELETE FROM features WHERE name=%s", (TEST_FEATURE_NAME,)) + db.connection.commit() + +def test_feature_manager(): + assert redis.hget(FM._REDIS_HASH, TEST_FEATURE_NAME) is None + assert db.select_feature(TEST_FEATURE_NAME) is None + + with patch('builtins.input', return_value='y' if INITIAL_STATE else 'n'): + assert FM.feature(TEST_FEATURE_NAME) == INITIAL_STATE + + redis_val = redis.hget(FM._REDIS_HASH, TEST_FEATURE_NAME) + assert bool(int(redis_val)) == INITIAL_STATE + + db_val = db.select_feature(TEST_FEATURE_NAME) + assert bool(db_val) == INITIAL_STATE + + FM.update_feature(TEST_FEATURE_NAME, UPDATED_STATE) + + redis_updated_val = redis.hget(FM._REDIS_HASH, TEST_FEATURE_NAME) + assert bool(int(redis_updated_val)) == UPDATED_STATE + + db_updated_val = db.select_feature(TEST_FEATURE_NAME) + assert bool(db_updated_val) == UPDATED_STATE + + assert FM.feature(TEST_FEATURE_NAME) == UPDATED_STATE From 4fd40330ac0cb2d5496a2f649d82672d0d17d385 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 21:21:24 +0500 Subject: [PATCH 50/71] refactor: Remove unused methods from SelectAdmin class and streamline logic --- bot/filters/admin.py | 18 ----- tests/filters/test_admin_filter.py | 117 +++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 18 deletions(-) create mode 100644 tests/filters/test_admin_filter.py diff --git a/bot/filters/admin.py b/bot/filters/admin.py index 4297a32..4517fb2 100644 --- a/bot/filters/admin.py +++ b/bot/filters/admin.py @@ -84,23 +84,5 @@ def add_admin(self) -> bool: return True elif self.dada['add_admin'] == 1: return True - else: - return False - - - def set_data(self) -> bool: - if self.user_id == self.super_admin: - return True - elif self.dada['set_data'] == 1: - return True - else: - return False - - - def get_data(self) -> bool: - if self.user_id == self.super_admin: - return True - elif self.dada['get_data'] == 1: - return True else: return False \ No newline at end of file diff --git a/tests/filters/test_admin_filter.py b/tests/filters/test_admin_filter.py new file mode 100644 index 0000000..d683834 --- /dev/null +++ b/tests/filters/test_admin_filter.py @@ -0,0 +1,117 @@ +import random +import pytest + +from bot.loader import db # real Database instance +from bot.data.config import ADMIN +from bot.filters.admin import SelectAdmin + +# Helper functions +def _random_user_id() -> int: + """Generate a pseudo-random Telegram-style user id.""" + return random.randint(2_000_000_000, 3_000_000_000) + + +def _ensure_admin_row(user_id: int): + sql_check = "SELECT 1 FROM admins WHERE user_id = %s LIMIT 1" + db.cursor.execute(sql_check, (user_id,)) + if not db.cursor.fetchone(): + db.insert_admin(user_id=user_id, initiator_user_id=ADMIN) + +@pytest.fixture(autouse=True) +def isolation(): + # Start a transaction and roll back after each test + db.cursor.execute("START TRANSACTION") + yield + db.cursor.execute("ROLLBACK") + +@pytest.fixture() +def new_admin_id(): + # Create a fresh admin with all permissions = 0 + user_id = _random_user_id() + _ensure_admin_row(user_id) + for col in ["send_message", "statistika", "download_statistika", "block_user", "channel_settings", "add_admin"]: + db.update_admin_data(user_id=user_id, column=col, value=0, updater_user_id=ADMIN) + return user_id + +# Tests for send_message + +def test_send_message_true_for_flag(new_admin_id): + db.update_admin_data(user_id=new_admin_id, column="send_message", value=1, updater_user_id=ADMIN) + selector = SelectAdmin(user_id=new_admin_id) + assert selector.send_message() is True + + +def test_send_message_false_for_flag(new_admin_id): + selector = SelectAdmin(user_id=new_admin_id) + assert selector.send_message() is False + +# Tests for view_statistika + +def test_view_statistika_true_for_flag(new_admin_id): + db.update_admin_data(user_id=new_admin_id, column="statistika", value=1, updater_user_id=ADMIN) + selector = SelectAdmin(user_id=new_admin_id) + assert selector.view_statistika() is True + + +def test_view_statistika_false_for_flag(new_admin_id): + selector = SelectAdmin(user_id=new_admin_id) + assert selector.view_statistika() is False + +# Tests for download_statistika + +def test_download_statistika_true_for_flag(new_admin_id): + db.update_admin_data(user_id=new_admin_id, column="download_statistika", value=1, updater_user_id=ADMIN) + selector = SelectAdmin(user_id=new_admin_id) + assert selector.download_statistika() is True + + +def test_download_statistika_false_for_flag(new_admin_id): + selector = SelectAdmin(user_id=new_admin_id) + assert selector.download_statistika() is False + +# Tests for block_user + +def test_block_user_true_for_flag(new_admin_id): + db.update_admin_data(user_id=new_admin_id, column="block_user", value=1, updater_user_id=ADMIN) + selector = SelectAdmin(user_id=new_admin_id) + assert selector.block_user() is True + + +def test_block_user_false_for_flag(new_admin_id): + selector = SelectAdmin(user_id=new_admin_id) + assert selector.block_user() is False + +# Tests for channel_settings + +def test_channel_settings_true_for_flag(new_admin_id): + db.update_admin_data(user_id=new_admin_id, column="channel_settings", value=1, updater_user_id=ADMIN) + selector = SelectAdmin(user_id=new_admin_id) + assert selector.channel_settings() is True + + +def test_channel_settings_false_for_flag(new_admin_id): + selector = SelectAdmin(user_id=new_admin_id) + assert selector.channel_settings() is False + +# Tests for add_admin + +def test_add_admin_true_for_flag(new_admin_id): + db.update_admin_data(user_id=new_admin_id, column="add_admin", value=1, updater_user_id=ADMIN) + selector = SelectAdmin(user_id=new_admin_id) + assert selector.add_admin() is True + + +def test_add_admin_false_for_flag(new_admin_id): + selector = SelectAdmin(user_id=new_admin_id) + assert selector.add_admin() is False + +# Tests for super admin shortcuts + +def test_super_admin_methods_always_true(): + selector = SelectAdmin(user_id=ADMIN) + assert selector.send_message() is True + assert selector.view_statistika() is True + assert selector.download_statistika() is True + assert selector.block_user() is True + assert selector.channel_settings() is True + assert selector.add_admin() is True From f48f832aec372b61bd91e03061965eb8efdee399 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 21:30:15 +0500 Subject: [PATCH 51/71] refactor: Replace SelectAdmin with AdminFilter in admin-related handlers and tests --- bot/filters/admin.py | 10 +- .../admins/admin_settings/add_admin.py | 4 +- .../admin_settings/add_admin_first_step.py | 4 +- .../admins/admin_settings/admin_setting.py | 4 +- .../admins/admin_settings/attach_admins.py | 6 +- .../admins/admin_settings/edit_admin.py | 6 +- bot/keyboards/inline/admin_btn.py | 12 +- tests/filters/test_admin_filter.py | 161 +++++++++--------- 8 files changed, 109 insertions(+), 98 deletions(-) diff --git a/bot/filters/admin.py b/bot/filters/admin.py index 4517fb2..f87f9b7 100644 --- a/bot/filters/admin.py +++ b/bot/filters/admin.py @@ -2,7 +2,7 @@ from aiogram.types import Message from bot.data.config import ADMIN -from bot.loader import db +from bot.loader import db, radis class IsSuperAdmin(BaseFilter): @@ -32,13 +32,19 @@ async def __call__(self, message: Message) -> bool: return False -class SelectAdmin: +class AdminFilter: def __init__(self, user_id): self.user_id = user_id self.super_admin = ADMIN self.dada = db.select_admin(user_id=self.user_id) + def __call__(self): + if self.dada is not None: + return True + else: + return False + def send_message(self) -> bool: if self.user_id == self.super_admin: return True diff --git a/bot/handlers/admins/admin_settings/add_admin.py b/bot/handlers/admins/admin_settings/add_admin.py index 4bbdc26..26b5853 100755 --- a/bot/handlers/admins/admin_settings/add_admin.py +++ b/bot/handlers/admins/admin_settings/add_admin.py @@ -1,7 +1,7 @@ import logging from aiogram import types from aiogram.fsm.context import FSMContext -from bot.filters.admin import IsAdmin, SelectAdmin +from bot.filters.admin import IsAdmin, AdminFilter from bot.keyboards.inline.admin_btn import admin_setting from bot.keyboards.inline.close_btn import close_btn from bot.loader import dp, bot, db, translator @@ -15,7 +15,7 @@ async def add_admin(msg: types.Message, state: FSMContext): user_id = msg.from_user.id mid = msg.message_id language_code = msg.from_user.language_code - data = SelectAdmin(user_id=user_id) + data = AdminFilter(user_id=user_id) add_admin_db = data.add_admin() target_user_id = int(msg.text) diff --git a/bot/handlers/admins/admin_settings/add_admin_first_step.py b/bot/handlers/admins/admin_settings/add_admin_first_step.py index a56047f..f20f886 100755 --- a/bot/handlers/admins/admin_settings/add_admin_first_step.py +++ b/bot/handlers/admins/admin_settings/add_admin_first_step.py @@ -1,7 +1,7 @@ from aiogram import types, F from aiogram.fsm.context import FSMContext -from bot.filters.admin import IsAdmin, SelectAdmin +from bot.filters.admin import IsAdmin, AdminFilter from bot.keyboards.inline.admin_btn import admin_setting from bot.keyboards.inline.button import AdminCallback from bot.keyboards.inline.close_btn import close_btn @@ -15,7 +15,7 @@ async def add_admin_first(call: types.CallbackQuery, state: FSMContext): user_id = call.from_user.id mid = call.message.message_id language_code = call.from_user.language_code - admin = SelectAdmin(user_id=user_id) + admin = AdminFilter(user_id=user_id) if admin.add_admin() : text = translator(text="🔰 Please send the admin ID number you want to add...", dest=language_code) diff --git a/bot/handlers/admins/admin_settings/admin_setting.py b/bot/handlers/admins/admin_settings/admin_setting.py index 706bf14..fc455fb 100755 --- a/bot/handlers/admins/admin_settings/admin_setting.py +++ b/bot/handlers/admins/admin_settings/admin_setting.py @@ -2,7 +2,7 @@ from aiogram import types, F from aiogram.fsm.context import FSMContext -from bot.filters.admin import IsAdmin, SelectAdmin +from bot.filters.admin import IsAdmin, AdminFilter from bot.keyboards.inline.admin_btn import admin_setting from bot.keyboards.inline.button import AdminCallback from bot.keyboards.inline.close_btn import close_btn @@ -16,7 +16,7 @@ async def admin_settings(call: types.CallbackQuery, state: FSMContext): user_id = call.from_user.id mid = call.message.message_id language_code = call.from_user.language_code - admin = SelectAdmin(user_id=user_id) + admin = AdminFilter(user_id=user_id) if admin.add_admin(): text = translator(text="❗ You are in the Admin settings section!", dest=language_code) diff --git a/bot/handlers/admins/admin_settings/attach_admins.py b/bot/handlers/admins/admin_settings/attach_admins.py index 3f79de6..ec1a0cf 100755 --- a/bot/handlers/admins/admin_settings/attach_admins.py +++ b/bot/handlers/admins/admin_settings/attach_admins.py @@ -2,7 +2,7 @@ from aiogram.fsm.context import FSMContext from bot.data.config import ADMIN -from bot.filters.admin import IsAdmin, SelectAdmin +from bot.filters.admin import IsAdmin, AdminFilter from bot.function.function import x_or_y from bot.keyboards.inline.admin_btn import attach_admin_btn from bot.keyboards.inline.button import AdminSetting @@ -20,7 +20,7 @@ async def attach_admins(call: types.CallbackQuery, callback_data: AdminSetting, mid = call.message.message_id language_code = call.from_user.language_code admin_user_id = callback_data.user_id - data = SelectAdmin(user_id=user_id) + data = AdminFilter(user_id=user_id) btn = close_btn() if data.add_admin(): @@ -28,7 +28,7 @@ async def attach_admins(call: types.CallbackQuery, callback_data: AdminSetting, if admin_data['initiator_user_id'] == user_id or user_id == ADMIN: btn = attach_admin_btn(user_id=admin_user_id, language_code=language_code) - is_admin = SelectAdmin(user_id=admin_user_id) + is_admin = AdminFilter(user_id=admin_user_id) send_message_tx = x_or_y(is_admin.send_message()) diff --git a/bot/handlers/admins/admin_settings/edit_admin.py b/bot/handlers/admins/admin_settings/edit_admin.py index a0161c5..4addf14 100755 --- a/bot/handlers/admins/admin_settings/edit_admin.py +++ b/bot/handlers/admins/admin_settings/edit_admin.py @@ -2,7 +2,7 @@ from aiogram.fsm.context import FSMContext from bot.data.config import ADMIN -from bot.filters.admin import IsAdmin, SelectAdmin +from bot.filters.admin import IsAdmin, AdminFilter from bot.function.function import x_or_y from bot.keyboards.inline.close_btn import close_btn from bot.loader import dp, bot, db, root_logger, translator @@ -19,7 +19,7 @@ async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, language_code = call.from_user.language_code admin_user_id = callback_data.user_id edit_key = callback_data.data - data = SelectAdmin(user_id=user_id) + data = AdminFilter(user_id=user_id) add_admin = data.add_admin() btn = close_btn() @@ -39,7 +39,7 @@ async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, new_value = 0 if select_column['result'] == 1 else 1 db.update_admin_data(user_id=admin_user_id, column=edit_key, value=new_value, updater_user_id=user_id) btn = attach_admin_btn(user_id=admin_user_id, language_code=language_code) - is_admin = SelectAdmin(user_id=admin_user_id) + is_admin = AdminFilter(user_id=admin_user_id) send_message_tx = x_or_y(is_admin.send_message()) view_statistika_tx = x_or_y(is_admin.view_statistika()) download_statistika_tx = x_or_y(is_admin.download_statistika()) diff --git a/bot/keyboards/inline/admin_btn.py b/bot/keyboards/inline/admin_btn.py index 71cf4b2..1c91af2 100644 --- a/bot/keyboards/inline/admin_btn.py +++ b/bot/keyboards/inline/admin_btn.py @@ -6,7 +6,7 @@ from bot.data.config import ADMIN from bot.loader import db, bot, translator, FM, root_logger from bot.function.function import x_or_y -from bot.filters.admin import SelectAdmin +from bot.filters.admin import AdminFilter def main_btn(): @@ -25,7 +25,7 @@ def main_admin_panel_btn(user_id, language_code): btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = SelectAdmin(user_id=user_id) + is_admin = AdminFilter(user_id=user_id) if is_admin.add_admin() and FM.feature('admin_settings'): btn.button(text=translator(text=f"👮‍♂️ Admins settings!", dest=language_code), @@ -82,7 +82,7 @@ def attach_admin(user_id, language_code): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = SelectAdmin(user_id=user_id) + is_admin = AdminFilter(user_id=user_id) send_message_tx = x_or_y(is_admin.send_message()) wiew_statistika_tx = x_or_y(is_admin.view_statistika()) download_statistika_tx = x_or_y(is_admin.download_statistika()) @@ -125,7 +125,7 @@ def attach_admin_btn(user_id, language_code): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = SelectAdmin(user_id=user_id) + is_admin = AdminFilter(user_id=user_id) send_message_tx = x_or_y(is_admin.send_message()) wiew_statistika_tx = x_or_y(is_admin.view_statistika()) download_statistika_tx = x_or_y(is_admin.download_statistika()) @@ -197,7 +197,7 @@ def block_user(attention_user_id, language_code, user_id): btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = SelectAdmin(user_id=user_id) + is_admin = AdminFilter(user_id=user_id) if is_admin.block_user(): data = db.check_user_ban(user_id=attention_user_id) if data is None: @@ -221,7 +221,7 @@ def download_statistika(user_id, language_code): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = SelectAdmin(user_id=user_id) + is_admin = AdminFilter(user_id=user_id) if is_admin.download_statistika(): btn.button(text=translator(text=f"📜 Dowload statistika!", dest=language_code), diff --git a/tests/filters/test_admin_filter.py b/tests/filters/test_admin_filter.py index d683834..d66a962 100644 --- a/tests/filters/test_admin_filter.py +++ b/tests/filters/test_admin_filter.py @@ -1,117 +1,122 @@ import random import pytest -from bot.loader import db # real Database instance +from bot.loader import db from bot.data.config import ADMIN -from bot.filters.admin import SelectAdmin +from bot.filters.admin import AdminFilter # Helper functions def _random_user_id() -> int: - """Generate a pseudo-random Telegram-style user id.""" return random.randint(2_000_000_000, 3_000_000_000) -def _ensure_admin_row(user_id: int): + +def test_admin_filter(): + user_id = _random_user_id() sql_check = "SELECT 1 FROM admins WHERE user_id = %s LIMIT 1" db.cursor.execute(sql_check, (user_id,)) if not db.cursor.fetchone(): - db.insert_admin(user_id=user_id, initiator_user_id=ADMIN) - -@pytest.fixture(autouse=True) -def isolation(): - # Start a transaction and roll back after each test - db.cursor.execute("START TRANSACTION") - yield - db.cursor.execute("ROLLBACK") - -@pytest.fixture() -def new_admin_id(): - # Create a fresh admin with all permissions = 0 - user_id = _random_user_id() - _ensure_admin_row(user_id) - for col in ["send_message", "statistika", "download_statistika", "block_user", "channel_settings", "add_admin"]: - db.update_admin_data(user_id=user_id, column=col, value=0, updater_user_id=ADMIN) - return user_id + db.insert_admin(user_id=user_id, + initiator_user_id=ADMIN) + + # Is admin + selector = AdminFilter(user_id=user_id) + assert selector(user_id=user_id) is True + + # db.update_admin_data(user_id=new_admin_id, column="send_message", value=1, updater_user_id=ADMIN) + # selector = SelectAdmin(user_id=new_admin_id) + # assert selector.send_message() is True + + + + -# Tests for send_message +# @pytest.fixture() +# def new_admin_id(): +# # Create a fresh admin with all permissions = 0 +# user_id = _random_user_id() +# _ensure_admin_row(user_id) +# for col in ["send_message", "statistika", "download_statistika", "block_user", "channel_settings", "add_admin"]: +# db.update_admin_data(user_id=user_id, column=col, value=0, updater_user_id=ADMIN) +# return user_id -def test_send_message_true_for_flag(new_admin_id): - db.update_admin_data(user_id=new_admin_id, column="send_message", value=1, updater_user_id=ADMIN) - selector = SelectAdmin(user_id=new_admin_id) - assert selector.send_message() is True +# # Tests for send_message +# def test_send_message_true_for_flag(new_admin_id): +# db.update_admin_data(user_id=new_admin_id, column="send_message", value=1, updater_user_id=ADMIN) +# selector = SelectAdmin(user_id=new_admin_id) +# assert selector.send_message() is True -def test_send_message_false_for_flag(new_admin_id): - selector = SelectAdmin(user_id=new_admin_id) - assert selector.send_message() is False +# selector = SelectAdmin(user_id=new_admin_id) +# assert selector.send_message() is False -# Tests for view_statistika +# # Tests for view_statistika -def test_view_statistika_true_for_flag(new_admin_id): - db.update_admin_data(user_id=new_admin_id, column="statistika", value=1, updater_user_id=ADMIN) - selector = SelectAdmin(user_id=new_admin_id) - assert selector.view_statistika() is True +# def test_view_statistika_true_for_flag(new_admin_id): +# db.update_admin_data(user_id=new_admin_id, column="statistika", value=1, updater_user_id=ADMIN) +# selector = SelectAdmin(user_id=new_admin_id) +# assert selector.view_statistika() is True -def test_view_statistika_false_for_flag(new_admin_id): - selector = SelectAdmin(user_id=new_admin_id) - assert selector.view_statistika() is False +# def test_view_statistika_false_for_flag(new_admin_id): +# selector = SelectAdmin(user_id=new_admin_id) +# assert selector.view_statistika() is False -# Tests for download_statistika +# # Tests for download_statistika -def test_download_statistika_true_for_flag(new_admin_id): - db.update_admin_data(user_id=new_admin_id, column="download_statistika", value=1, updater_user_id=ADMIN) - selector = SelectAdmin(user_id=new_admin_id) - assert selector.download_statistika() is True +# def test_download_statistika_true_for_flag(new_admin_id): +# db.update_admin_data(user_id=new_admin_id, column="download_statistika", value=1, updater_user_id=ADMIN) +# selector = SelectAdmin(user_id=new_admin_id) +# assert selector.download_statistika() is True -def test_download_statistika_false_for_flag(new_admin_id): - selector = SelectAdmin(user_id=new_admin_id) - assert selector.download_statistika() is False +# def test_download_statistika_false_for_flag(new_admin_id): +# selector = SelectAdmin(user_id=new_admin_id) +# assert selector.download_statistika() is False -# Tests for block_user +# # Tests for block_user -def test_block_user_true_for_flag(new_admin_id): - db.update_admin_data(user_id=new_admin_id, column="block_user", value=1, updater_user_id=ADMIN) - selector = SelectAdmin(user_id=new_admin_id) - assert selector.block_user() is True +# def test_block_user_true_for_flag(new_admin_id): +# db.update_admin_data(user_id=new_admin_id, column="block_user", value=1, updater_user_id=ADMIN) +# selector = SelectAdmin(user_id=new_admin_id) +# assert selector.block_user() is True -def test_block_user_false_for_flag(new_admin_id): - selector = SelectAdmin(user_id=new_admin_id) - assert selector.block_user() is False +# def test_block_user_false_for_flag(new_admin_id): +# selector = SelectAdmin(user_id=new_admin_id) +# assert selector.block_user() is False -# Tests for channel_settings +# # Tests for channel_settings -def test_channel_settings_true_for_flag(new_admin_id): - db.update_admin_data(user_id=new_admin_id, column="channel_settings", value=1, updater_user_id=ADMIN) - selector = SelectAdmin(user_id=new_admin_id) - assert selector.channel_settings() is True +# def test_channel_settings_true_for_flag(new_admin_id): +# db.update_admin_data(user_id=new_admin_id, column="channel_settings", value=1, updater_user_id=ADMIN) +# selector = SelectAdmin(user_id=new_admin_id) +# assert selector.channel_settings() is True -def test_channel_settings_false_for_flag(new_admin_id): - selector = SelectAdmin(user_id=new_admin_id) - assert selector.channel_settings() is False +# def test_channel_settings_false_for_flag(new_admin_id): +# selector = SelectAdmin(user_id=new_admin_id) +# assert selector.channel_settings() is False -# Tests for add_admin +# # Tests for add_admin -def test_add_admin_true_for_flag(new_admin_id): - db.update_admin_data(user_id=new_admin_id, column="add_admin", value=1, updater_user_id=ADMIN) - selector = SelectAdmin(user_id=new_admin_id) - assert selector.add_admin() is True +# def test_add_admin_true_for_flag(new_admin_id): +# db.update_admin_data(user_id=new_admin_id, column="add_admin", value=1, updater_user_id=ADMIN) +# selector = SelectAdmin(user_id=new_admin_id) +# assert selector.add_admin() is True -def test_add_admin_false_for_flag(new_admin_id): - selector = SelectAdmin(user_id=new_admin_id) - assert selector.add_admin() is False +# def test_add_admin_false_for_flag(new_admin_id): +# selector = SelectAdmin(user_id=new_admin_id) +# assert selector.add_admin() is False -# Tests for super admin shortcuts +# # Tests for super admin shortcuts -def test_super_admin_methods_always_true(): - selector = SelectAdmin(user_id=ADMIN) - assert selector.send_message() is True - assert selector.view_statistika() is True - assert selector.download_statistika() is True - assert selector.block_user() is True - assert selector.channel_settings() is True - assert selector.add_admin() is True +# def test_super_admin_methods_always_true(): +# selector = SelectAdmin(user_id=ADMIN) +# assert selector.send_message() is True +# assert selector.view_statistika() is True +# assert selector.download_statistika() is True +# assert selector.block_user() is True +# assert selector.channel_settings() is True +# assert selector.add_admin() is True From 5dc2c8d2f14b62c42e224c3708d825de9550dd55 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 22:46:00 +0500 Subject: [PATCH 52/71] refactor: Remove unused admin-related methods and streamline database logic; add AdminsManager for managing admin rights --- bot/core/admin_rights_manager.py | 145 +++++++++ bot/db/database.py | 280 +----------------- bot/filters/admin.py | 3 +- bot/loader.py | 9 +- pytest.ini | 2 + tests/filters/test_admin_filter.py | 36 +-- .../test_admin_rights_manager_integration.py | 66 +++++ 7 files changed, 250 insertions(+), 291 deletions(-) create mode 100644 bot/core/admin_rights_manager.py create mode 100644 tests/moduls/test_admin_rights_manager_integration.py diff --git a/bot/core/admin_rights_manager.py b/bot/core/admin_rights_manager.py new file mode 100644 index 0000000..5d09da1 --- /dev/null +++ b/bot/core/admin_rights_manager.py @@ -0,0 +1,145 @@ +# bot/core/admin_rights_manager.py +import logging +from typing import Optional + +import mysql.connector +from redis import Redis + +from bot.db.database import Database + + +class AdminsManager: + def __init__( + self, + db: Database, + redis_client: Redis, + root_logger: logging.Logger, + redis_namespace: str = "admin_setting", + ) -> None: + self.db = db + self.redis = redis_client + self.ns = redis_namespace + self.log = root_logger.getChild(self.__class__.__name__) + self.create_table_admins() + self.create_table_admin_rights() + + def get(self, user_id: int, feature: str) -> Optional[bool]: + key = self._redis_key(user_id, feature) + + if (cached := self.redis.get(key)) is not None: + return cached == "1" + + try: + sql = """ + SELECT `value` + FROM `admin_rights` AS ar + INNER JOIN `admins` AS a + ON ar.admin_id=a.id + WHERE a.user_id = %s + AND `name` = %s + AND ar.`is_active` = TRUE + LIMIT 1 + """ + self.db.cursor.execute(sql, (user_id, feature)) + row = self.db.cursor.fetchone() + if row: + value = bool(row["value"]) + self.redis.set(key, "1" if value else "0") + return value + return None + except mysql.connector.Error as err: + self.log.error(f"MySQL (get) xatosi: {err}") + self.db.reconnect() + return None + + def update(self, user_id: int, feature: str, value: bool, is_active: bool = True) -> None: + try: + sql = """ + INSERT INTO admin_rights (admin_id, name, value, is_active) + VALUES ( + (SELECT id FROM admins WHERE user_id = %s), + %s, -- feature + %s, -- value + %s -- is_active + ) + ON DUPLICATE KEY UPDATE + value = VALUES(value), + is_active = VALUES(is_active), + updated_at = CURRENT_TIMESTAMP; + """ + self.db.cursor.execute(sql, (user_id, feature, int(value), is_active)) + self.db.connection.commit() + except mysql.connector.Error as err: + self.log.error(f"MySQL (update) xatosi: {err}") + self.db.reconnect() + return + + # Redis keshini yangilash + key = self._redis_key(user_id, feature) + self.redis.set(key, "1" if value else "0") + + def add(self, user_id: int) -> None: + try: + self.db.cursor.execute( + "INSERT INTO `admins` (`user_id`) VALUES (%s);", + (user_id,), + ) + self.db.connection.commit() + except mysql.connector.Error as err: + self.log.error(f"MySQL (add) xatosi: {err}") + self.db.reconnect() + + def _redis_key(self, admin_id: int, feature: str) -> str: + return f"{self.ns}:{admin_id}:{feature}" + + def create_table_admins(self): + try: + sql = """ + CREATE TABLE IF NOT EXISTS `admins` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `user_id` BIGINT NOT NULL UNIQUE, + `initiator_user_id` BIGINT, + `updater_user_id` BIGINT, + `role` ENUM('admin', 'moderator') DEFAULT 'admin', + `is_active` BOOLEAN DEFAULT TRUE, + `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP NULL DEFAULT NULL + ); + """ + self.db.cursor.execute(sql) + self.db.connection.commit() + except mysql.connector.Error as err: + self.log.error(err) + self.db.reconnect() + except Exception as err: + self.log.error(err) + + def create_table_admin_rights(self): + try: + sql = """ + CREATE TABLE IF NOT EXISTS `admin_rights` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `admin_id` INT NOT NULL, + `name` VARCHAR(255) NOT NULL, + `value` BOOLEAN NOT NULL, + `is_active` BOOLEAN DEFAULT TRUE, + `description` TEXT, + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP NULL, + UNIQUE KEY `uq_admin_feature` (`admin_id`,`name`), + CONSTRAINT `fk_rights_admin` + FOREIGN KEY (`admin_id`) REFERENCES `admins`(`id`) + ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """ + self.db.cursor.execute(sql) + self.db.connection.commit() + except mysql.connector.Error as err: + self.log.error(err) + self.db.reconnect() + except Exception as err: + self.log.error(err) + self.db.reconnect() + diff --git a/bot/db/database.py b/bot/db/database.py index 504e11c..979455c 100755 --- a/bot/db/database.py +++ b/bot/db/database.py @@ -14,7 +14,6 @@ def __init__(self, host, user, password, database, root_logger: logging.Logger): self.database = database self.root_logger = root_logger self.reconnect() - self.create_table_admins() self.create_table_users() self.create_table_channel() self.create_table_settings() @@ -65,8 +64,9 @@ def create_table_users(self): `updater_user_id` BIGINT, `comment` TEXT, `ban_time` TIMESTAMP NULL DEFAULT NULL, - `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP NULL DEFAULT NULL, `language_code` VARCHAR(5) ) """ @@ -89,8 +89,9 @@ def create_table_channel(self): `channel_id` BIGINT, `initiator_user_id` BIGINT, `updater_user_id` BIGINT, - `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP + `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP NULL DEFAULT NULL ); """ self.cursor.execute(sql) @@ -100,36 +101,7 @@ def create_table_channel(self): self.reconnect() except Exception as err: self.root_logger.error(err) - - def create_table_admins(self): - """ - Create the 'admins' table if it does not already exist. - """ - try: - sql = """ - CREATE TABLE IF NOT EXISTS `admins` ( - `id` INT AUTO_INCREMENT PRIMARY KEY, - `user_id` BIGINT NOT NULL UNIQUE, - `initiator_user_id` BIGINT, - `updater_user_id` BIGINT, - `send_message` TINYINT(1) DEFAULT 0, - `statistika` TINYINT(1) DEFAULT 0, - `download_statistika` TINYINT(1) DEFAULT 0, - `block_user` TINYINT(1) DEFAULT 0, - `channel_settings` TINYINT(1) DEFAULT 0, - `add_admin` TINYINT(1) DEFAULT 0, - `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP - ); - """ - self.cursor.execute(sql) - self.connection.commit() - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - + def create_table_settings(self): """ Create the 'settings' table if it does not already exist. @@ -143,7 +115,8 @@ def create_table_settings(self): `key` VARCHAR(255) NOT NULL, `value` VARCHAR(255) NOT NULL, `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP NULL ) """ self.cursor.execute(sql) @@ -341,23 +314,6 @@ def insert_channel(self, channel_id, initiator_user_id): except Exception as err: self.root_logger.error(err) - def insert_admin(self, user_id, initiator_user_id): - """ - Add an admin to the 'admins' table. - """ - try: - sql = """ - INSERT INTO admins (user_id, initiator_user_id) VALUES (%s, %s) - """ - values = (user_id, initiator_user_id) - self.cursor.execute(sql, values) - self.connection.commit() - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - ## ------------------ Update ------------------ ## def update_feature(self, name: str, enabled: bool): """ @@ -388,26 +344,6 @@ def update_settings_key(self, updater_user_id, key, value): except Exception as err: self.root_logger.error(err) - def update_admin_data(self, user_id, column, value, updater_user_id): - """ - Update an admin's data in the 'admins' table. - Only allowed columns may be updated. - """ - allowed_columns = {'send_message', 'statistika', 'download_statistika', 'block_user', 'channel_settings', 'add_admin'} - if column not in allowed_columns: - self.root_logger.error(f"Invalid column '{column}' specified for update_admin_data") - return - try: - sql = f"UPDATE admins SET {column} = %s, updater_user_id = %s WHERE user_id = %s" - values = (value, updater_user_id, user_id) - self.cursor.execute(sql, values) - self.connection.commit() - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - def update_user_status(self, user_id, status, updater_user_id): """ Update a user's status in the 'users' table. @@ -553,39 +489,6 @@ def select_all_users(self): except Exception as err: self.root_logger.error(err) - def select_users_by_id(self, start_id: int, end_id: int) -> list: - """ - Select users from the 'users' table within a specific ID range. - """ - try: - sql = "SELECT * FROM `users` WHERE `id` >= %s AND `id` < %s;" - values = (start_id, end_id) - self.cursor.execute(sql, values) - result = self.cursor.fetchall() - return result - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - def select_admins_by_id(self, start_id: int, end_id: int) -> list: - """ - Select admins from the 'admins' table within a specific ID range. - """ - try: - sql = "SELECT * FROM `admins` WHERE `id` >= %s AND `id` < %s;" - values = (start_id, end_id) - self.cursor.execute(sql, values) - result = self.cursor.fetchall() - return result - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - def stat(self): """ Get the total number of users. """ @@ -615,171 +518,6 @@ def check_user(self, user_id): except Exception as err: self.root_logger.error(err) - def select_admin_column(self, user_id, column): - """ - Select a specific column for an admin from the 'admins' table. - """ - try: - sql = f"SELECT {column} AS result FROM admins WHERE user_id = %s" - self.cursor.execute(sql, (user_id,)) - result = self.cursor.fetchone() - return result - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - def select_admin(self, user_id): - """ - Select an admin from the 'admins' table. - """ - try: - sql = "SELECT * FROM admins WHERE user_id = %s LIMIT 1" - self.cursor.execute(sql, (user_id,)) - result = self.cursor.fetchone() - return result - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - def select_add_admin(self, user_id): - """ - Select all admins added by a specific admin. - """ - try: - sql = "SELECT * FROM admins WHERE initiator_user_id = %s" - self.cursor.execute(sql, (user_id,)) - result = self.cursor.fetchall() - return result - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - def select_all_admins(self): - """ - Select all admins from the 'admins' table. - """ - try: - sql = "SELECT * FROM admins" - self.cursor.execute(sql) - result = self.cursor.fetchall() - return result - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - def stat_admins(self): - """ - Get the total number of admins. - """ - try: - sql = "SELECT COUNT(*) FROM admins" - self.cursor.execute(sql) - result = self.cursor.fetchone() - return result[list(result.keys())[0]] - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - def delete_admin(self, user_id): - """ - Delete an admin from the 'admins' table. - """ - try: - sql = "DELETE FROM admins WHERE user_id = %s" - self.cursor.execute(sql, (user_id,)) - self.connection.commit() - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - def select_channels(self): - """ - Select all channels from the 'channels' table. - """ - try: - sql = "SELECT * FROM channels" - self.cursor.execute(sql) - results = self.cursor.fetchall() - return results - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - def select_channels_initiator_user_id(self, initiator_user_id): - """ - Select all channels added by a specific admin. - """ - try: - sql = "SELECT * FROM channels WHERE initiator_user_id = %s" - self.cursor.execute(sql, (initiator_user_id,)) - result = self.cursor.fetchall() - return result - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - def check_channel(self, channel_id): - """ - Check if a channel exists in the 'channels' table. - """ - try: - sql = "SELECT * FROM channels WHERE channel_id = %s" - self.cursor.execute(sql, (channel_id,)) - result = self.cursor.fetchone() - return result - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - def select_all_channel(self): - """ - Select all channels from the 'channels' table. - """ - try: - sql = "SELECT * FROM channels" - self.cursor.execute(sql) - result = self.cursor.fetchall() - return result - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - def delete_channel(self, channel_id): - """ - Delete a channel from the 'channels' table. - """ - try: - sql = "DELETE FROM channels WHERE channel_id = %s" - self.cursor.execute(sql, (channel_id,)) - self.connection.commit() - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - - diff --git a/bot/filters/admin.py b/bot/filters/admin.py index f87f9b7..99d44e1 100644 --- a/bot/filters/admin.py +++ b/bot/filters/admin.py @@ -1,8 +1,9 @@ from aiogram.filters import BaseFilter from aiogram.types import Message +from typing import Optional, Any from bot.data.config import ADMIN -from bot.loader import db, radis +from bot.loader import db, redis class IsSuperAdmin(BaseFilter): diff --git a/bot/loader.py b/bot/loader.py index 0273620..a62acf9 100755 --- a/bot/loader.py +++ b/bot/loader.py @@ -10,6 +10,7 @@ from bot.api.translator import Translator from bot.core.feature_manager import FeatureManager from bot.core.settings_manager import SettingsManager +from bot.core.admin_rights_manager import AdminsManager @@ -21,13 +22,16 @@ db = Database(host=HOST, user=MYSQL_USER, password=MYSQL_PASSWORD, database=MYSQL_DATABASE, root_logger=root_logger) + + + log_format = '%(filename)s - %(funcName)s - %(lineno)d - %(name)s - %(levelname)s - %(message)s' formatter = logging.Formatter(log_format) redis = Redis(host="localhost", port=6379, db=0, decode_responses=True) async_redis = AsyncRedis(host="localhost", port=6379, db=1, decode_responses=True) -FM = FeatureManager(db=db, root_logger=root_logger, redis_client=redis) + bot = Bot(token=BOT_TOKEN, default=DefaultBotProperties(parse_mode=ParseMode.HTML)) @@ -37,6 +41,9 @@ router = Router() + +FM = FeatureManager(db=db, root_logger=root_logger, redis_client=redis) +AM = AdminsManager(db=db, redis_client=redis, root_logger=root_logger) SM = SettingsManager(db=db, redis_client=redis, root_logger=root_logger) translator = Translator(db=db, FM=FM) diff --git a/pytest.ini b/pytest.ini index 0a8ae9e..2df4b30 100644 --- a/pytest.ini +++ b/pytest.ini @@ -5,3 +5,5 @@ python_files = tests/**/**/*.py asyncio_mode = auto asyncio_default_fixture_loop_scope = function +markers = + integration: slow tests that hit real MySQL + Redis diff --git a/tests/filters/test_admin_filter.py b/tests/filters/test_admin_filter.py index d66a962..53aea79 100644 --- a/tests/filters/test_admin_filter.py +++ b/tests/filters/test_admin_filter.py @@ -1,27 +1,27 @@ -import random -import pytest +# import random +# import pytest -from bot.loader import db -from bot.data.config import ADMIN -from bot.filters.admin import AdminFilter +# from bot.loader import db +# from bot.data.config import ADMIN +# from bot.filters.admin import AdminFilter -# Helper functions -def _random_user_id() -> int: - return random.randint(2_000_000_000, 3_000_000_000) +# # Helper functions +# def _random_user_id() -> int: +# return random.randint(2_000_000_000, 3_000_000_000) -def test_admin_filter(): - user_id = _random_user_id() - sql_check = "SELECT 1 FROM admins WHERE user_id = %s LIMIT 1" - db.cursor.execute(sql_check, (user_id,)) - if not db.cursor.fetchone(): - db.insert_admin(user_id=user_id, - initiator_user_id=ADMIN) +# def test_admin_filter(): +# user_id = _random_user_id() +# sql_check = "SELECT 1 FROM admins WHERE user_id = %s LIMIT 1" +# db.cursor.execute(sql_check, (user_id,)) +# if not db.cursor.fetchone(): +# db.insert_admin(user_id=user_id, +# initiator_user_id=ADMIN) - # Is admin - selector = AdminFilter(user_id=user_id) - assert selector(user_id=user_id) is True +# # Is admin +# selector = AdminFilter(user_id=user_id) +# assert selector(user_id=user_id) is True # db.update_admin_data(user_id=new_admin_id, column="send_message", value=1, updater_user_id=ADMIN) # selector = SelectAdmin(user_id=new_admin_id) diff --git a/tests/moduls/test_admin_rights_manager_integration.py b/tests/moduls/test_admin_rights_manager_integration.py new file mode 100644 index 0000000..ae8e1f7 --- /dev/null +++ b/tests/moduls/test_admin_rights_manager_integration.py @@ -0,0 +1,66 @@ +# tests/test_admins_manager_int.py +import random +import pytest +import mysql.connector + +from bot.loader import db, redis, AM + + +@pytest.mark.integration +def test_admins_manager_full_cycle(): + + + user_id = random.randint(10**10, 10**11 - 1) + features = ["can_ban_users", "can_post", "is_super_admin"] + + db.cursor.execute("DELETE FROM admin_rights WHERE admin_id IN (SELECT id FROM admins WHERE user_id = %s)", (user_id,)) + db.cursor.execute("DELETE FROM admins WHERE user_id = %s", (user_id,)) + db.connection.commit() + for f in features: + redis.delete(AM._redis_key(user_id, f)) + + AM.add(user_id) + AM.add(user_id) + + db.cursor.execute("SELECT id FROM admins WHERE user_id=%s", (user_id,)) + admin_row = db.cursor.fetchone() + assert admin_row, "Admin qo'shilmadi" + admin_pk = admin_row["id"] + + for feat in features: + + assert AM.get(user_id, feat) is None + + AM.update(user_id, feat, True) + + db.cursor.execute( + "SELECT value, is_active FROM admin_rights WHERE admin_id=%s AND name=%s", + (admin_pk, feat), + ) + row = db.cursor.fetchone() + assert row and row["value"] == 1 and row["is_active"] == 1 + + assert redis.get(AM._redis_key(user_id, feat)) == "1" + + assert AM.get(user_id, feat) is True + + AM.update(user_id, feat, False) + + db.cursor.execute( + "SELECT value FROM admin_rights WHERE admin_id=%s AND name=%s", + (admin_pk, feat), + ) + assert db.cursor.fetchone()["value"] == 0 + assert redis.get(AM._redis_key(user_id, feat)) == "0" + assert AM.get(user_id, feat) is False + + AM.update(user_id, feat, False, is_active=False) + + redis.delete(AM._redis_key(user_id, feat)) + assert AM.get(user_id, feat) is None + + db.cursor.execute("DELETE FROM admin_rights WHERE admin_id=%s", (admin_pk,)) + db.cursor.execute("DELETE FROM admins WHERE id=%s", (admin_pk,)) + db.connection.commit() + for f in features: + redis.delete(AM._redis_key(user_id, f)) From c6225bd54c8e352e55db273194fd01447b2b964c Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 22:46:12 +0500 Subject: [PATCH 53/71] refactor: Remove unused mysql.connector import from admin rights manager integration test --- tests/moduls/test_admin_rights_manager_integration.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/moduls/test_admin_rights_manager_integration.py b/tests/moduls/test_admin_rights_manager_integration.py index ae8e1f7..5b97651 100644 --- a/tests/moduls/test_admin_rights_manager_integration.py +++ b/tests/moduls/test_admin_rights_manager_integration.py @@ -1,7 +1,6 @@ # tests/test_admins_manager_int.py import random import pytest -import mysql.connector from bot.loader import db, redis, AM From 83e4f8c6fe1f2ad3fc995ca5c9c350669a3e2f11 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 22:51:32 +0500 Subject: [PATCH 54/71] refactor: Move feature-related database methods to FeatureManager and update tests accordingly --- bot/core/feature_manager.py | 56 +++++++++++++++++++++++++--- bot/db/database.py | 47 ----------------------- tests/moduls/test_feature_manager.py | 6 +-- 3 files changed, 54 insertions(+), 55 deletions(-) diff --git a/bot/core/feature_manager.py b/bot/core/feature_manager.py index 2ebd2c6..c887fe1 100644 --- a/bot/core/feature_manager.py +++ b/bot/core/feature_manager.py @@ -2,7 +2,7 @@ from typing import Optional from bot.db.database import Database from redis import Redis, RedisError - +import mysql.connector class FeatureManager: _REDIS_HASH = "features" @@ -16,6 +16,7 @@ def __init__( self.db = db self.redis = redis_client self.log = root_logger + self.create_table_features() def feature(self, name: str) -> bool: try: @@ -23,7 +24,7 @@ def feature(self, name: str) -> bool: if cached is not None: return cached - db_value = self.db.select_feature(name) + db_value = self.select_feature(name) if db_value is None: enabled = self._ask_user(name) self._persist(name, enabled) @@ -39,8 +40,8 @@ def feature(self, name: str) -> bool: def update_feature(self, name: str, enabled: bool) -> None: try: rows = self.db.update_feature(name=name, enabled=enabled) - if rows == 0: # feature yo‘q edi - self.db.insert_feature(name=name, enabled=enabled) + if rows == 0: + self.insert_feature(name=name, enabled=enabled) self.redis.hset(self._REDIS_HASH, name, int(enabled)) @@ -61,5 +62,50 @@ def _ask_user(self, name: str) -> bool: return access.strip().lower() == "y" def _persist(self, name: str, enabled: bool) -> None: - self.db.insert_feature(name=name, enabled=enabled) + self.insert_feature(name=name, enabled=enabled) self.redis.hset(self._REDIS_HASH, name, int(enabled)) + + def create_table_features(self): + try: + sql = """ + CREATE TABLE IF NOT EXISTS `features` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(255) NOT NULL UNIQUE, + `enabled` TINYINT(1) DEFAULT 0, + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP NULL DEFAULT NULL, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP + ) + """ + self.db.cursor.execute(sql) + self.db.connection.commit() + except mysql.connector.Error as err: + self.log.error(err) + self.db.reconnect() + except Exception as err: + self.log.error(err) + + def insert_feature(self, name: str, enabled: bool): + try: + sql = "INSERT INTO `features` (`name`, `enabled`) VALUES (%s, %s)" + values = (name, int(enabled)) + self.db.cursor.execute(sql, values) + self.db.connection.commit() + except mysql.connector.Error as err: + self.log.error(err) + self.db.reconnect() + except Exception as err: + self.db.root_logger.error(err) + + def select_feature(self, name: str): + try: + sql = "SELECT * FROM `features` WHERE `name` = %s" + values = (name,) + self.db.cursor.execute(sql, values) + result = self.db.cursor.fetchone() + return None if result is None else result['enabled'] + except mysql.connector.Error as err: + self.log.error(err) + self.db.reconnect() + except Exception as err: + self.log.error(err) diff --git a/bot/db/database.py b/bot/db/database.py index 979455c..640b862 100755 --- a/bot/db/database.py +++ b/bot/db/database.py @@ -19,7 +19,6 @@ def __init__(self, host, user, password, database, root_logger: logging.Logger): self.create_table_settings() self.create_table_texts() self.create_table_translations() - self.create_table_features() def reconnect(self): try: @@ -170,25 +169,6 @@ def create_table_translations(self): except Exception as err: self.root_logger.error(err) - def create_table_features(self): - try: - sql = """ - CREATE TABLE IF NOT EXISTS `features` ( - `id` INT AUTO_INCREMENT PRIMARY KEY, - `name` VARCHAR(255) NOT NULL UNIQUE, - `enabled` TINYINT(1) DEFAULT 0, - `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `deleted_at` TIMESTAMP NULL DEFAULT NULL, - `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP - ) - """ - self.cursor.execute(sql) - self.connection.commit() - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) ## ---------------- Scheduler --------------------- def ban_user_for_one_hour(self, user_id, comment=None): @@ -225,18 +205,6 @@ def ban_user_for_one_hour(self, user_id, comment=None): ## ------------------ Insert data ------------------ ## - def insert_feature(self, name: str, enabled: bool): - try: - sql = "INSERT INTO `features` (`name`, `enabled`) VALUES (%s, %s)" - values = (name, int(enabled)) - self.cursor.execute(sql, values) - self.connection.commit() - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - def insert_texts(self, hash_value: str, raw_text: str): """ Insert a new text into the 'texts' table. @@ -360,21 +328,6 @@ def update_user_status(self, user_id, status, updater_user_id): self.root_logger.error(err) ## ------------------ Select ------------------ ## - def select_feature(self, name: str): - """ - Select a feature from the 'features' table. - """ - try: - sql = "SELECT * FROM `features` WHERE `name` = %s" - values = (name,) - self.cursor.execute(sql, values) - result = self.cursor.fetchone() - return None if result is None else result['enabled'] - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) def select_texts(self, hash_value: str): try: diff --git a/tests/moduls/test_feature_manager.py b/tests/moduls/test_feature_manager.py index 649d76b..3f6a1cf 100644 --- a/tests/moduls/test_feature_manager.py +++ b/tests/moduls/test_feature_manager.py @@ -18,7 +18,7 @@ def setup_teardown(): def test_feature_manager(): assert redis.hget(FM._REDIS_HASH, TEST_FEATURE_NAME) is None - assert db.select_feature(TEST_FEATURE_NAME) is None + assert FM.select_feature(TEST_FEATURE_NAME) is None with patch('builtins.input', return_value='y' if INITIAL_STATE else 'n'): assert FM.feature(TEST_FEATURE_NAME) == INITIAL_STATE @@ -26,7 +26,7 @@ def test_feature_manager(): redis_val = redis.hget(FM._REDIS_HASH, TEST_FEATURE_NAME) assert bool(int(redis_val)) == INITIAL_STATE - db_val = db.select_feature(TEST_FEATURE_NAME) + db_val = FM.select_feature(TEST_FEATURE_NAME) assert bool(db_val) == INITIAL_STATE FM.update_feature(TEST_FEATURE_NAME, UPDATED_STATE) @@ -34,7 +34,7 @@ def test_feature_manager(): redis_updated_val = redis.hget(FM._REDIS_HASH, TEST_FEATURE_NAME) assert bool(int(redis_updated_val)) == UPDATED_STATE - db_updated_val = db.select_feature(TEST_FEATURE_NAME) + db_updated_val = FM.select_feature(TEST_FEATURE_NAME) assert bool(db_updated_val) == UPDATED_STATE assert FM.feature(TEST_FEATURE_NAME) == UPDATED_STATE From 80de546c00ecafb2ba38f8828875a2450071df87 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 22:52:29 +0500 Subject: [PATCH 55/71] refactor: Add __call__ method to AdminsManager for improved usability --- bot/core/admin_rights_manager.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bot/core/admin_rights_manager.py b/bot/core/admin_rights_manager.py index 5d09da1..1f343db 100644 --- a/bot/core/admin_rights_manager.py +++ b/bot/core/admin_rights_manager.py @@ -23,6 +23,9 @@ def __init__( self.create_table_admins() self.create_table_admin_rights() + def __call__(self, user_id: int, feature: str) -> Optional[bool]: + return self.get(user_id, feature) + def get(self, user_id: int, feature: str) -> Optional[bool]: key = self._redis_key(user_id, feature) From f51193dfdb52f763d577a77d154a40433905477c Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 23:06:42 +0500 Subject: [PATCH 56/71] refactor: Simplify feature management by consolidating update logic and enhancing test coverage --- bot/core/feature_manager.py | 107 ++++++++++++--------------- bot/db/database.py | 15 ---- tests/moduls/test_feature_manager.py | 14 ++-- 3 files changed, 53 insertions(+), 83 deletions(-) diff --git a/bot/core/feature_manager.py b/bot/core/feature_manager.py index c887fe1..0b1b001 100644 --- a/bot/core/feature_manager.py +++ b/bot/core/feature_manager.py @@ -7,48 +7,54 @@ class FeatureManager: _REDIS_HASH = "features" - def __init__( - self, - db: Database, - redis_client: Redis, - root_logger: logging.Logger, - ): + def __init__(self, db: Database, redis_client: Redis, root_logger: logging.Logger): self.db = db self.redis = redis_client self.log = root_logger - self.create_table_features() + self._create_table_features() def feature(self, name: str) -> bool: + """Kesh → DB → (birinchi marta bo‘lsa) foydalanuvchidan so‘rash.""" try: cached = self._get_from_redis(name) if cached is not None: return cached - db_value = self.select_feature(name) - if db_value is None: - enabled = self._ask_user(name) - self._persist(name, enabled) - return enabled + db_val = self._select_enabled(name) + if db_val is not None: + self.redis.hset(self._REDIS_HASH, name, int(db_val)) + return bool(db_val) - self.redis.hset(self._REDIS_HASH, name, int(db_value)) - return bool(db_value) + enabled = self._ask_user(name) + self.upsert_feature(name, enabled) + return enabled except (RedisError, Exception) as exc: self.log.error(f"Error in feature('{name}'): {exc}") return False - def update_feature(self, name: str, enabled: bool) -> None: + def upsert_feature(self, name: str, enabled: bool) -> None: try: - rows = self.db.update_feature(name=name, enabled=enabled) - if rows == 0: - self.insert_feature(name=name, enabled=enabled) + sql = """ + INSERT INTO features (name, enabled) + VALUES (%s, %s) + ON DUPLICATE KEY UPDATE + enabled = VALUES(enabled), + updated_at = CURRENT_TIMESTAMP, + deleted_at = NULL + """ + self.db.cursor.execute(sql, (name, int(enabled))) + self.db.connection.commit() - self.redis.hset(self._REDIS_HASH, name, int(enabled)) - self.log.info(f"Feature '{name}' updated → {enabled}") + self.redis.hset(self._REDIS_HASH, name, int(enabled)) + self.log.info("Feature '%s' upserted → %s", name, enabled) - except (RedisError, Exception) as exc: - self.log.error(f"Error in update_feature('{name}'): {exc}") + except mysql.connector.Error as err: + self.log.error(err) + self.db.reconnect() + except Exception as err: + self.log.error(err) raise def _get_from_redis(self, name: str) -> Optional[bool]: @@ -56,54 +62,35 @@ def _get_from_redis(self, name: str) -> Optional[bool]: return bool(int(val)) if val is not None else None def _ask_user(self, name: str) -> bool: - access = input( - f"Feature '{name}' not found, do you want to enable it? (y/n): " - ) - return access.strip().lower() == "y" - - def _persist(self, name: str, enabled: bool) -> None: - self.insert_feature(name=name, enabled=enabled) - self.redis.hset(self._REDIS_HASH, name, int(enabled)) + return input(f"Feature '{name}' not found, enable it? (y/n): ").strip().lower() == "y" - def create_table_features(self): + def _select_enabled(self, name: str) -> Optional[bool]: try: - sql = """ - CREATE TABLE IF NOT EXISTS `features` ( - `id` INT AUTO_INCREMENT PRIMARY KEY, - `name` VARCHAR(255) NOT NULL UNIQUE, - `enabled` TINYINT(1) DEFAULT 0, - `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `deleted_at` TIMESTAMP NULL DEFAULT NULL, - `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP - ) - """ - self.db.cursor.execute(sql) - self.db.connection.commit() + self.db.cursor.execute("SELECT `enabled` FROM `features` WHERE `name` = %s LIMIT 1", (name,)) + row = self.db.cursor.fetchone() + return None if row is None else bool(row["enabled"]) except mysql.connector.Error as err: self.log.error(err) self.db.reconnect() except Exception as err: self.log.error(err) - def insert_feature(self, name: str, enabled: bool): - try: - sql = "INSERT INTO `features` (`name`, `enabled`) VALUES (%s, %s)" - values = (name, int(enabled)) - self.db.cursor.execute(sql, values) - self.db.connection.commit() - except mysql.connector.Error as err: - self.log.error(err) - self.db.reconnect() - except Exception as err: - self.db.root_logger.error(err) - def select_feature(self, name: str): + def _create_table_features(self): try: - sql = "SELECT * FROM `features` WHERE `name` = %s" - values = (name,) - self.db.cursor.execute(sql, values) - result = self.db.cursor.fetchone() - return None if result is None else result['enabled'] + self.db.cursor.execute( + """ + CREATE TABLE IF NOT EXISTS features ( + id INT AUTO_INCREMENT PRIMARY KEY, + name VARCHAR(255) NOT NULL UNIQUE, + enabled TINYINT(1) NOT NULL DEFAULT 0, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + deleted_at TIMESTAMP DEFAULT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP + ) + """ + ) + self.db.connection.commit() except mysql.connector.Error as err: self.log.error(err) self.db.reconnect() diff --git a/bot/db/database.py b/bot/db/database.py index 640b862..f06f26a 100755 --- a/bot/db/database.py +++ b/bot/db/database.py @@ -283,21 +283,6 @@ def insert_channel(self, channel_id, initiator_user_id): self.root_logger.error(err) ## ------------------ Update ------------------ ## - def update_feature(self, name: str, enabled: bool): - """ - Update a feature in the 'features' table. - """ - try: - sql = "UPDATE `features` SET `enabled` = %s WHERE `name` = %s" - values = (int(enabled), name) - self.cursor.execute(sql, values) - self.connection.commit() - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - def update_settings_key(self, updater_user_id, key, value): try: sql = """ diff --git a/tests/moduls/test_feature_manager.py b/tests/moduls/test_feature_manager.py index 3f6a1cf..b950cff 100644 --- a/tests/moduls/test_feature_manager.py +++ b/tests/moduls/test_feature_manager.py @@ -9,16 +9,16 @@ @pytest.fixture(autouse=True) def setup_teardown(): redis.hdel(FM._REDIS_HASH, TEST_FEATURE_NAME) - db.cursor.execute("DELETE FROM features WHERE name=%s", (TEST_FEATURE_NAME,)) + db.cursor.execute("DELETE FROM `features` WHERE `name`=%s", (TEST_FEATURE_NAME,)) db.connection.commit() yield redis.hdel(FM._REDIS_HASH, TEST_FEATURE_NAME) - db.cursor.execute("DELETE FROM features WHERE name=%s", (TEST_FEATURE_NAME,)) + db.cursor.execute("DELETE FROM `features` WHERE `name`=%s", (TEST_FEATURE_NAME,)) db.connection.commit() + def test_feature_manager(): assert redis.hget(FM._REDIS_HASH, TEST_FEATURE_NAME) is None - assert FM.select_feature(TEST_FEATURE_NAME) is None with patch('builtins.input', return_value='y' if INITIAL_STATE else 'n'): assert FM.feature(TEST_FEATURE_NAME) == INITIAL_STATE @@ -26,15 +26,13 @@ def test_feature_manager(): redis_val = redis.hget(FM._REDIS_HASH, TEST_FEATURE_NAME) assert bool(int(redis_val)) == INITIAL_STATE - db_val = FM.select_feature(TEST_FEATURE_NAME) - assert bool(db_val) == INITIAL_STATE + assert FM.feature(TEST_FEATURE_NAME) == INITIAL_STATE - FM.update_feature(TEST_FEATURE_NAME, UPDATED_STATE) + FM.upsert_feature(TEST_FEATURE_NAME, UPDATED_STATE) redis_updated_val = redis.hget(FM._REDIS_HASH, TEST_FEATURE_NAME) assert bool(int(redis_updated_val)) == UPDATED_STATE - db_updated_val = FM.select_feature(TEST_FEATURE_NAME) - assert bool(db_updated_val) == UPDATED_STATE + assert FM.feature(TEST_FEATURE_NAME) == UPDATED_STATE assert FM.feature(TEST_FEATURE_NAME) == UPDATED_STATE From d076ab0d60a5755ec761e1fff5eebb439a03d016 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 23:15:19 +0500 Subject: [PATCH 57/71] refactor: Consolidate settings management logic and enhance test coverage --- bot/core/settings_manager.py | 90 ++++++++++++++++++--------- bot/db/database.py | 69 +------------------- tests/moduls/test_settings_manager.py | 9 +-- 3 files changed, 65 insertions(+), 103 deletions(-) diff --git a/bot/core/settings_manager.py b/bot/core/settings_manager.py index 6cba876..b870192 100644 --- a/bot/core/settings_manager.py +++ b/bot/core/settings_manager.py @@ -1,6 +1,6 @@ import logging from typing import Optional, Any - +import mysql.connector from redis import Redis, RedisError from bot.db.database import Database @@ -17,46 +17,80 @@ def __init__( self.db: Database = db self.redis: Redis = redis_client self.log: logging.Logger = root_logger + self._ensure_table() def get(self, key: str) -> Optional[str]: + """Kesh → DB tartibida o‘qish.""" try: - cached = self._get_from_redis(key) + cached = self.redis.hget(self._REDIS_HASH, key) if cached is not None: return cached - db_val = self.db.select_setting(key) - if db_val is None: + sql = "SELECT `value` FROM `settings` WHERE `key` = %s" + self.db.cursor.execute(sql, (key,)) + row = self.db.cursor.fetchone() + if row is None: return None - self.redis.hset(self._REDIS_HASH, key, db_val) - return db_val + self.redis.hset(self._REDIS_HASH, key, row["value"]) + return row["value"] - except (RedisError, Exception) as exc: - self.log.error(f"Error in SettingsManager.get('{key}'): {exc}") + except (RedisError, mysql.connector.Error, Exception) as exc: + self.log.error(f"SettingsManager.get('{key}') → {exc}") + if isinstance(exc, mysql.connector.Error): + self.db.reconnect() return None - def update(self, key: str, value: Any, updater_user_id: int = -1) -> None: + def upsert(self, key: str, value: Any, user_id: int = -1) -> None: try: - check = self.db.select_setting(key) - if check is None: - self.db.insert_settings( - initiator_user_id=updater_user_id, - key=key, - value=str(value), - ) - else: - self.db.update_settings_key( - updater_user_id=updater_user_id, - key=key, - value=str(value), - ) + sql = """ + INSERT INTO `settings` + (`key`, `value`, `initiator_user_id`, `updater_user_id`) + VALUES + (%s, %s, %s, %s) + ON DUPLICATE KEY UPDATE + `value` = VALUES(`value`), + `updater_user_id` = VALUES(`updater_user_id`), + `updated_at` = CURRENT_TIMESTAMP + """ + vals = (key, str(value), user_id, user_id) + self.db.cursor.execute(sql, vals) + self.db.connection.commit() + self.redis.hset(self._REDIS_HASH, key, str(value)) - self.log.info(f"Setting '{key}' updated → {value}") + self.log.info(f"Setting '{key}' → {value}") + + except RedisError as exc: + self.log.error(f"Redis error upserting '{key}': {exc}") - except (RedisError, Exception) as exc: - self.log.error(f"Error in SettingsManager.update('{key}', '{value}'): {exc}") + except mysql.connector.Error as err: + self.log.error(f"MySQL error upserting '{key}': {err}") + self.db.reconnect() raise - def _get_from_redis(self, key: str) -> Optional[str]: - val = self.redis.hget(self._REDIS_HASH, key) - return val if val is not None else None + except Exception as exc: + self.log.error(f"Unknown error upserting '{key}': {exc}") + raise + + def _ensure_table(self) -> None: + try: + self.db.cursor.execute( + """ + CREATE TABLE IF NOT EXISTS `settings` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `key` VARCHAR(255) NOT NULL UNIQUE, + `value` VARCHAR(255) NOT NULL, + `initiator_user_id` BIGINT, + `updater_user_id` BIGINT, + `updated_at` TIMESTAMP + DEFAULT CURRENT_TIMESTAMP + ON UPDATE CURRENT_TIMESTAMP, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP NULL + ) + """ + ) + self.db.connection.commit() + except mysql.connector.Error as err: + self.log.error(f"Error creating settings table: {err}") + self.db.reconnect() diff --git a/bot/db/database.py b/bot/db/database.py index f06f26a..32c5005 100755 --- a/bot/db/database.py +++ b/bot/db/database.py @@ -16,7 +16,6 @@ def __init__(self, host, user, password, database, root_logger: logging.Logger): self.reconnect() self.create_table_users() self.create_table_channel() - self.create_table_settings() self.create_table_texts() self.create_table_translations() @@ -100,32 +99,7 @@ def create_table_channel(self): self.reconnect() except Exception as err: self.root_logger.error(err) - - def create_table_settings(self): - """ - Create the 'settings' table if it does not already exist. - """ - try: - sql = """ - CREATE TABLE IF NOT EXISTS `settings` ( - `id` INT AUTO_INCREMENT PRIMARY KEY, - `updater_user_id` BIGINT, - `initiator_user_id` BIGINT, - `key` VARCHAR(255) NOT NULL, - `value` VARCHAR(255) NOT NULL, - `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - `deleted_at` TIMESTAMP NULL - ) - """ - self.cursor.execute(sql) - self.connection.commit() - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - + def create_table_texts(self): try: sql = """ @@ -233,21 +207,6 @@ def insert_translations(self, text_id: int, dest_lang: str, translated_content: except Exception as err: self.root_logger.error(err) - def insert_settings(self, initiator_user_id, key, value): - """ - Add a setting to the 'settings' table. - """ - try: - sql = "INSERT INTO `settings` (`updater_user_id`, `initiator_user_id`, `key`, `value`) VALUES (%s, %s, %s, %s)" - values = (initiator_user_id, initiator_user_id, key, value) - self.cursor.execute(sql, values) - self.connection.commit() - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - def insert_user(self, user_id, language_code): """ Add a user to the 'users' table. @@ -283,19 +242,6 @@ def insert_channel(self, channel_id, initiator_user_id): self.root_logger.error(err) ## ------------------ Update ------------------ ## - def update_settings_key(self, updater_user_id, key, value): - try: - sql = """ - UPDATE settings SET `value` = %s, `updater_user_id` = %s WHERE `key` = %s - """ - values = (value, updater_user_id, key) - self.cursor.execute(sql, values) - self.connection.commit() - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) def update_user_status(self, user_id, status, updater_user_id): """ @@ -340,19 +286,6 @@ def select_translations(self, text_id: int, dest_lang: str): except Exception as err: self.root_logger.error(err) - def select_setting(self, key: str): - try: - sql = "SELECT `value` FROM `settings` WHERE `key` = %s" - values = (key,) - self.cursor.execute(sql, values) - result = self.cursor.fetchone() - return None if result is None else result['value'] - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - def select_all_users_ban(self): """ Select all banned users from the 'users' table. diff --git a/tests/moduls/test_settings_manager.py b/tests/moduls/test_settings_manager.py index 3fd879c..0f951d3 100644 --- a/tests/moduls/test_settings_manager.py +++ b/tests/moduls/test_settings_manager.py @@ -18,22 +18,17 @@ def setup_teardown(): def test_settings_manager_get_and_update(): assert SM.get(TEST_KEY) is None - SM.update(TEST_KEY, INITIAL_VALUE, updater_user_id=12345) + SM.upsert(TEST_KEY, INITIAL_VALUE, user_id=12345) redis_val = redis.hget(SM._REDIS_HASH, TEST_KEY) assert redis_val == INITIAL_VALUE - db_val = db.select_setting(TEST_KEY) - assert db_val == INITIAL_VALUE - assert SM.get(TEST_KEY) == INITIAL_VALUE - SM.update(TEST_KEY, UPDATED_VALUE, updater_user_id=54321) + SM.upsert(TEST_KEY, UPDATED_VALUE, user_id=54321) redis_updated_val = redis.hget(SM._REDIS_HASH, TEST_KEY) assert redis_updated_val == UPDATED_VALUE - db_updated_val = db.select_setting(TEST_KEY) - assert db_updated_val == UPDATED_VALUE assert SM.get(TEST_KEY) == UPDATED_VALUE From 41fc6f7be45dfcebfd8ba9208f8048d2f66a472c Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 23:34:25 +0500 Subject: [PATCH 58/71] refactor: Enhance Translator class with logging and database methods, streamline feature checks --- bot/api/translator.py | 132 +++++++++++++++--- bot/db/database.py | 98 ------------- bot/loader.py | 2 +- .../test_admin_rights_manager_integration.py | 1 - tests/moduls/test_translator.py | 40 +++--- 5 files changed, 128 insertions(+), 145 deletions(-) diff --git a/bot/api/translator.py b/bot/api/translator.py index 46294e1..413753e 100644 --- a/bot/api/translator.py +++ b/bot/api/translator.py @@ -1,5 +1,7 @@ +import logging from typing import Optional from deep_translator import GoogleTranslator + from bot.db.database import Database from bot.function.function import to_hash from bot.core.feature_manager import FeatureManager @@ -7,13 +9,17 @@ class Translator: def __init__(self, db: Database, - FM: FeatureManager = None, + FM: FeatureManager, + root_logger: logging.Logger, default_dest: str = "en", default_src: str = "en"): - self.db = db + self.db: Database = db + self.root_logger = root_logger self.default_dest = default_dest self.default_src = default_src - self.FM = FM + self.FM: FeatureManager = FM + self.create_table_translations() + self.create_table_texts() def __call__( self, @@ -23,31 +29,115 @@ def __call__( ) -> str: return self.translate(text, dest=dest, src=src) + def translate(self, text: str, dest: Optional[str] = 'en', src: Optional[str] = 'en') -> str: - if self.FM.feature('translator'): - if dest == src or not text: - return text - dest = dest or self.default_dest - src = src or self.default_src + try: + if self.FM.feature('translator'): + if dest == src or not text: + return text + dest = dest or self.default_dest + src = src or self.default_src - hash_value = to_hash(text) - hash_index = self.db.select_texts(hash_value) - if hash_index: - check = self.db.select_translations(hash_index, dest) - if check: - return check + hash_value = to_hash(text) + hash_index = self.select_texts(hash_value) + if hash_index: + check = self.select_translations(hash_index, dest) + if check: + return check + else: + translated = GoogleTranslator(source=src, target=dest).translate(text) + self.insert_translations(text_id=hash_index, dest_lang=dest, translated_content=translated) + return translated else: + hash_index = self.insert_texts(hash_value=hash_value, raw_text=text) translated = GoogleTranslator(source=src, target=dest).translate(text) - self.db.insert_translations(text_id=hash_index, dest_lang=dest, translated_content=translated) + self.insert_translations(text_id=hash_index, dest_lang=dest, translated_content=translated) return translated else: - hash_index = self.db.insert_texts(hash_value=hash_value, raw_text=text) - translated = GoogleTranslator(source=src, target=dest).translate(text) - self.db.insert_translations(text_id=hash_index, dest_lang=dest, translated_content=translated) - return translated - else: - return text \ No newline at end of file + return text + except Exception as e: + self.root_logger.info(f"Error in translator.py: {e}") + return text + + + + + def create_table_texts(self): + try: + sql = """ + CREATE TABLE IF NOT EXISTS texts ( + id INT AUTO_INCREMENT PRIMARY KEY, + hash_value BIGINT UNSIGNED, + raw_text TEXT NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + deleted_at TIMESTAMP NULL DEFAULT NULL, + INDEX(hash_value) + ) + """ + self.db.cursor.execute(sql) + self.db.connection.commit() + except Exception as err: + self.root_logger.error(err) + + def create_table_translations(self): + try: + sql = """ + CREATE TABLE IF NOT EXISTS `translations` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `text_id` INT NOT NULL, + `dest_lang` CHAR(5) NOT NULL, + `translated_content` TEXT NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + deleted_at TIMESTAMP NULL DEFAULT NULL, + FOREIGN KEY (text_id) REFERENCES texts(id) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """ + self.db.cursor.execute(sql) + self.db.connection.commit() + except Exception as err: + self.root_logger.error(err) + + def insert_texts(self, hash_value: str, raw_text: str): + try: + sql = "INSERT INTO `texts` (`hash_value`, `raw_text`) VALUES (%s, %s)" + values = (hash_value, raw_text) + self.db.cursor.execute(sql, values) + self.db.connection.commit() + return self.db.cursor.lastrowid + except Exception as err: + self.root_logger.error(err) + + def insert_translations(self, text_id: int, dest_lang: str, translated_content: str): + try: + sql = "INSERT INTO `translations` (`text_id`, `dest_lang`, `translated_content`) VALUES (%s, %s, %s)" + values = (text_id, dest_lang, translated_content) + self.db.cursor.execute(sql, values) + self.db.connection.commit() + except Exception as err: + self.root_logger.error(err) + + def select_texts(self, hash_value: str): + try: + sql = "SELECT * FROM `texts` WHERE `hash_value` = %s LIMIT 1" + values = (hash_value,) + self.db.cursor.execute(sql, values) + result = self.db.cursor.fetchone() + return None if result is None else result['id'] + except Exception as err: + self.root_logger.error(err) + + def select_translations(self, text_id: int, dest_lang: str): + try: + sql = "SELECT * FROM `translations` WHERE `text_id` = %s AND `dest_lang` = %s LIMIT 1" + values = (text_id, dest_lang) + self.db.cursor.execute(sql, values) + result = self.db.cursor.fetchone() + return None if result is None else result['translated_content'] + except Exception as err: + self.root_logger.error(err) diff --git a/bot/db/database.py b/bot/db/database.py index 32c5005..c5b904b 100755 --- a/bot/db/database.py +++ b/bot/db/database.py @@ -16,8 +16,6 @@ def __init__(self, host, user, password, database, root_logger: logging.Logger): self.reconnect() self.create_table_users() self.create_table_channel() - self.create_table_texts() - self.create_table_translations() def reconnect(self): try: @@ -100,50 +98,6 @@ def create_table_channel(self): except Exception as err: self.root_logger.error(err) - def create_table_texts(self): - try: - sql = """ - CREATE TABLE IF NOT EXISTS texts ( - id INT AUTO_INCREMENT PRIMARY KEY, - hash_value BIGINT UNSIGNED, - raw_text TEXT NOT NULL, - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, - deleted_at TIMESTAMP NULL DEFAULT NULL, - INDEX(hash_value) - ) - """ - self.cursor.execute(sql) - self.connection.commit() - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - def create_table_translations(self): - try: - sql = """ - CREATE TABLE IF NOT EXISTS `translations` ( - `id` INT AUTO_INCREMENT PRIMARY KEY, - `text_id` INT NOT NULL, - `dest_lang` CHAR(5) NOT NULL, - `translated_content` TEXT NOT NULL, - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, - deleted_at TIMESTAMP NULL DEFAULT NULL, - FOREIGN KEY (text_id) REFERENCES texts(id) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - """ - self.cursor.execute(sql) - self.connection.commit() - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - ## ---------------- Scheduler --------------------- def ban_user_for_one_hour(self, user_id, comment=None): """ @@ -179,33 +133,6 @@ def ban_user_for_one_hour(self, user_id, comment=None): ## ------------------ Insert data ------------------ ## - def insert_texts(self, hash_value: str, raw_text: str): - """ - Insert a new text into the 'texts' table. - """ - try: - sql = "INSERT INTO `texts` (`hash_value`, `raw_text`) VALUES (%s, %s)" - values = (hash_value, raw_text) - self.cursor.execute(sql, values) - self.connection.commit() - return self.cursor.lastrowid - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - def insert_translations(self, text_id: int, dest_lang: str, translated_content: str): - try: - sql = "INSERT INTO `translations` (`text_id`, `dest_lang`, `translated_content`) VALUES (%s, %s, %s)" - values = (text_id, dest_lang, translated_content) - self.cursor.execute(sql, values) - self.connection.commit() - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) def insert_user(self, user_id, language_code): """ @@ -260,31 +187,6 @@ def update_user_status(self, user_id, status, updater_user_id): ## ------------------ Select ------------------ ## - def select_texts(self, hash_value: str): - try: - sql = "SELECT * FROM `texts` WHERE `hash_value` = %s LIMIT 1" - values = (hash_value,) - self.cursor.execute(sql, values) - result = self.cursor.fetchone() - return None if result is None else result['id'] - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) - - def select_translations(self, text_id: int, dest_lang: str): - try: - sql = "SELECT * FROM `translations` WHERE `text_id` = %s AND `dest_lang` = %s LIMIT 1" - values = (text_id, dest_lang) - self.cursor.execute(sql, values) - result = self.cursor.fetchone() - return None if result is None else result['translated_content'] - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) def select_all_users_ban(self): """ diff --git a/bot/loader.py b/bot/loader.py index a62acf9..1aa2208 100755 --- a/bot/loader.py +++ b/bot/loader.py @@ -46,7 +46,7 @@ AM = AdminsManager(db=db, redis_client=redis, root_logger=root_logger) SM = SettingsManager(db=db, redis_client=redis, root_logger=root_logger) -translator = Translator(db=db, FM=FM) +translator = Translator(db=db, FM=FM, root_logger=root_logger) diff --git a/tests/moduls/test_admin_rights_manager_integration.py b/tests/moduls/test_admin_rights_manager_integration.py index 5b97651..1bef747 100644 --- a/tests/moduls/test_admin_rights_manager_integration.py +++ b/tests/moduls/test_admin_rights_manager_integration.py @@ -1,4 +1,3 @@ -# tests/test_admins_manager_int.py import random import pytest diff --git a/tests/moduls/test_translator.py b/tests/moduls/test_translator.py index 816c20b..3d0dd77 100644 --- a/tests/moduls/test_translator.py +++ b/tests/moduls/test_translator.py @@ -1,28 +1,20 @@ -import pytest -from bot.api.translator import Translator -from bot.loader import db -from bot.function.function import to_hash - - -@pytest.mark.asyncio -async def test_translator_no_feature(monkeypatch): - class FM: - def __init__(self, defoult_return: bool = True): - self.defoult_return = defoult_return - def feature(self, *args,**kwargs) : - return self.defoult_return - - tr = Translator(db=db, FM=FM(False)) - result = tr.translate("Hello", dest="fr", src="en") +from bot.loader import translator, FM + + + +async def test_translator_no_feature(): + + feature = FM.feature('translator') + + FM.upsert_feature('translator', False) + + result = translator("Hello", dest="fr", src="en") assert result == "Hello" - tr = Translator(db=db, FM=FM(True)) - result = tr.translate("Hello", dest="fr", src="en") - assert result == "Bonjour" + FM.upsert_feature('translator', True) + assert FM.feature('translator') == True - hash_value = to_hash("Hello") - hash_index = db.select_texts(hash_value) - assert hash_index is not None + result = translator.translate("Hello", dest="fr", src="en") + assert result == "Bonjour" - check = db.select_translations(hash_index, "fr") - assert check is not None \ No newline at end of file + FM.upsert_feature('translator', feature) From 0899644cbdd4d56673beac497913ee75a51baf2b Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Thu, 22 May 2025 23:40:14 +0500 Subject: [PATCH 59/71] refactor: Add __call__ method to Translator, FeatureManager, and SettingsManager for improved usability --- bot/api/translator.py | 4 ---- bot/core/feature_manager.py | 3 +++ bot/core/settings_manager.py | 3 +++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bot/api/translator.py b/bot/api/translator.py index 413753e..2bbae57 100644 --- a/bot/api/translator.py +++ b/bot/api/translator.py @@ -29,7 +29,6 @@ def __call__( ) -> str: return self.translate(text, dest=dest, src=src) - def translate(self, text: str, dest: Optional[str] = 'en', @@ -63,9 +62,6 @@ def translate(self, self.root_logger.info(f"Error in translator.py: {e}") return text - - - def create_table_texts(self): try: sql = """ diff --git a/bot/core/feature_manager.py b/bot/core/feature_manager.py index 0b1b001..dd29dc8 100644 --- a/bot/core/feature_manager.py +++ b/bot/core/feature_manager.py @@ -13,6 +13,9 @@ def __init__(self, db: Database, redis_client: Redis, root_logger: logging.Logge self.log = root_logger self._create_table_features() + def __call__(self, name: str) -> bool: + return self.feature(name) + def feature(self, name: str) -> bool: """Kesh → DB → (birinchi marta bo‘lsa) foydalanuvchidan so‘rash.""" try: diff --git a/bot/core/settings_manager.py b/bot/core/settings_manager.py index b870192..4aeccac 100644 --- a/bot/core/settings_manager.py +++ b/bot/core/settings_manager.py @@ -19,6 +19,9 @@ def __init__( self.log: logging.Logger = root_logger self._ensure_table() + def __call__(self, key: str) -> Optional[str]: + return self.get(key) + def get(self, key: str) -> Optional[str]: """Kesh → DB tartibida o‘qish.""" try: From 946f848404e81d77b95eb3001dc5d4c89577ec8f Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Fri, 23 May 2025 23:06:06 +0500 Subject: [PATCH 60/71] refactor: Update Translator initialization to include Redis client and adjust Redis database index --- bot/api/translator.py | 228 +++++++++++++++++++++++------------------- bot/loader.py | 7 +- 2 files changed, 128 insertions(+), 107 deletions(-) diff --git a/bot/api/translator.py b/bot/api/translator.py index 2bbae57..f06a2b8 100644 --- a/bot/api/translator.py +++ b/bot/api/translator.py @@ -1,5 +1,7 @@ import logging from typing import Optional + +from redis import Redis, RedisError from deep_translator import GoogleTranslator from bot.db.database import Database @@ -8,18 +10,34 @@ class Translator: - def __init__(self, db: Database, - FM: FeatureManager, - root_logger: logging.Logger, - default_dest: str = "en", - default_src: str = "en"): + """ + Tarjima servisi: Redis → MySQL → GoogleTranslator + * Redis: texts, translations (hash) + * MySQL: texts, translations (tablalar) + """ + + _REDIS_HASH_TEXTS = "texts" + _REDIS_HASH_TRANSLATIONS = "translations" + + def __init__( + self, + db: Database, + FM: FeatureManager, + root_logger: logging.Logger, + redis_client: Redis, + default_dest: str = "en", + default_src: str = "en", + ): self.db: Database = db - self.root_logger = root_logger + self.redis: Redis = redis_client + self.FM: FeatureManager = FM + self.log = root_logger + self.default_dest = default_dest self.default_src = default_src - self.FM: FeatureManager = FM - self.create_table_translations() - self.create_table_texts() + + self._create_table_texts() + self._create_table_translations() def __call__( self, @@ -29,111 +47,117 @@ def __call__( ) -> str: return self.translate(text, dest=dest, src=src) - def translate(self, - text: str, - dest: Optional[str] = 'en', - src: Optional[str] = 'en') -> str: - try: - if self.FM.feature('translator'): - if dest == src or not text: - return text - dest = dest or self.default_dest - src = src or self.default_src - - - hash_value = to_hash(text) - hash_index = self.select_texts(hash_value) - if hash_index: - check = self.select_translations(hash_index, dest) - if check: - return check - else: - translated = GoogleTranslator(source=src, target=dest).translate(text) - self.insert_translations(text_id=hash_index, dest_lang=dest, translated_content=translated) - return translated - else: - hash_index = self.insert_texts(hash_value=hash_value, raw_text=text) - translated = GoogleTranslator(source=src, target=dest).translate(text) - self.insert_translations(text_id=hash_index, dest_lang=dest, translated_content=translated) - return translated - else: - return text - except Exception as e: - self.root_logger.info(f"Error in translator.py: {e}") + def translate( + self, + text: str, + dest: Optional[str] = None, + src: Optional[str] = None, + ) -> str: + if not self.FM.feature("translator") or not text: + return text + + dest = (dest or self.default_dest).lower() + src = (src or self.default_src).lower() + if dest == src: return text - - def create_table_texts(self): + + h = to_hash(text) + field_t = f"{h}:{dest}" try: - sql = """ - CREATE TABLE IF NOT EXISTS texts ( - id INT AUTO_INCREMENT PRIMARY KEY, - hash_value BIGINT UNSIGNED, - raw_text TEXT NOT NULL, - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, - deleted_at TIMESTAMP NULL DEFAULT NULL, - INDEX(hash_value) - ) - """ - self.db.cursor.execute(sql) - self.db.connection.commit() - except Exception as err: - self.root_logger.error(err) + cached = self.redis.hget(self._REDIS_HASH_TRANSLATIONS, field_t) + if cached: + return cached.decode() if isinstance(cached, bytes) else cached + except RedisError as err: + self.log.warning(f"Redis unavailable (translations): {err}") - def create_table_translations(self): + text_id = self._select_text_id(h) + if text_id: + mysql_translation = self._select_translation(text_id, dest) + if mysql_translation: + self._cache_translation_redis(field_t, mysql_translation) + return mysql_translation try: - sql = """ - CREATE TABLE IF NOT EXISTS `translations` ( - `id` INT AUTO_INCREMENT PRIMARY KEY, - `text_id` INT NOT NULL, - `dest_lang` CHAR(5) NOT NULL, - `translated_content` TEXT NOT NULL, - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - updated_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, - deleted_at TIMESTAMP NULL DEFAULT NULL, - FOREIGN KEY (text_id) REFERENCES texts(id) - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - """ - self.db.cursor.execute(sql) - self.db.connection.commit() + translated = GoogleTranslator(source=src, target=dest).translate(text) except Exception as err: - self.root_logger.error(err) + self.log.error(f"GoogleTranslator error: {err}") + return text + if not text_id: + text_id = self._insert_text(h, text) + self._insert_translation(text_id, dest, translated) + self._cache_translation_redis(field_t, translated) + return translated - def insert_texts(self, hash_value: str, raw_text: str): + def _cache_translation_redis(self, field: str, value: str) -> None: try: - sql = "INSERT INTO `texts` (`hash_value`, `raw_text`) VALUES (%s, %s)" - values = (hash_value, raw_text) - self.db.cursor.execute(sql, values) - self.db.connection.commit() - return self.db.cursor.lastrowid - except Exception as err: - self.root_logger.error(err) + self.redis.hset(self._REDIS_HASH_TRANSLATIONS, field, value) + except RedisError as err: + self.log.warning(f"Redis cache write failed: {err}") + + def _insert_text(self, hash_value: str, raw_text: str) -> int: + sql = "INSERT INTO texts (hash_value, raw_text) VALUES (%s, %s)" + self._exec(sql, (hash_value, raw_text)) + return self.db.cursor.lastrowid - def insert_translations(self, text_id: int, dest_lang: str, translated_content: str): + def _insert_translation(self, text_id: int, dest_lang: str, translated: str) -> None: + sql = ( + "INSERT INTO translations (text_id, dest_lang, translated_content) " + "VALUES (%s, %s, %s)" + ) + self._exec(sql, (text_id, dest_lang, translated)) + + def _select_text_id(self, hash_value: str) -> Optional[int]: + sql = "SELECT id FROM texts WHERE hash_value = %s LIMIT 1" + row = self._fetchone(sql, (hash_value,)) + return row["id"] if row else None + + def _select_translation(self, text_id: int, dest_lang: str) -> Optional[str]: + sql = ( + "SELECT translated_content FROM translations " + "WHERE text_id = %s AND dest_lang = %s LIMIT 1" + ) + row = self._fetchone(sql, (text_id, dest_lang)) + return row["translated_content"] if row else None + + def _exec(self, sql: str, params: tuple) -> None: try: - sql = "INSERT INTO `translations` (`text_id`, `dest_lang`, `translated_content`) VALUES (%s, %s, %s)" - values = (text_id, dest_lang, translated_content) - self.db.cursor.execute(sql, values) + self.db.cursor.execute(sql, params) self.db.connection.commit() except Exception as err: - self.root_logger.error(err) + self.log.error(err) - def select_texts(self, hash_value: str): + def _fetchone(self, sql: str, params: tuple): try: - sql = "SELECT * FROM `texts` WHERE `hash_value` = %s LIMIT 1" - values = (hash_value,) - self.db.cursor.execute(sql, values) - result = self.db.cursor.fetchone() - return None if result is None else result['id'] + self.db.cursor.execute(sql, params) + return self.db.cursor.fetchone() except Exception as err: - self.root_logger.error(err) + self.log.error(err) - def select_translations(self, text_id: int, dest_lang: str): - try: - sql = "SELECT * FROM `translations` WHERE `text_id` = %s AND `dest_lang` = %s LIMIT 1" - values = (text_id, dest_lang) - self.db.cursor.execute(sql, values) - result = self.db.cursor.fetchone() - return None if result is None else result['translated_content'] - except Exception as err: - self.root_logger.error(err) + def _create_table_texts(self): + sql = """ + CREATE TABLE IF NOT EXISTS texts ( + id INT AUTO_INCREMENT PRIMARY KEY, + hash_value BIGINT UNSIGNED, + raw_text TEXT NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + deleted_at TIMESTAMP NULL DEFAULT NULL, + INDEX(hash_value) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """ + self._exec(sql, ()) + + def _create_table_translations(self): + sql = """ + CREATE TABLE IF NOT EXISTS translations ( + id INT AUTO_INCREMENT PRIMARY KEY, + text_id INT NOT NULL, + dest_lang CHAR(5) NOT NULL, + translated_content TEXT NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + deleted_at TIMESTAMP NULL DEFAULT NULL, + FOREIGN KEY (text_id) REFERENCES texts(id) + ON DELETE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """ + self._exec(sql, ()) diff --git a/bot/loader.py b/bot/loader.py index 1aa2208..dd2e645 100755 --- a/bot/loader.py +++ b/bot/loader.py @@ -28,7 +28,7 @@ log_format = '%(filename)s - %(funcName)s - %(lineno)d - %(name)s - %(levelname)s - %(message)s' formatter = logging.Formatter(log_format) -redis = Redis(host="localhost", port=6379, db=0, decode_responses=True) +redis = Redis(host="localhost", port=6379, db=5, decode_responses=True) async_redis = AsyncRedis(host="localhost", port=6379, db=1, decode_responses=True) @@ -46,10 +46,7 @@ AM = AdminsManager(db=db, redis_client=redis, root_logger=root_logger) SM = SettingsManager(db=db, redis_client=redis, root_logger=root_logger) -translator = Translator(db=db, FM=FM, root_logger=root_logger) - - - +translator = Translator(db=db, FM=FM, root_logger=root_logger, redis_client=redis) From 4d131b629627031a7513c2cce545245c92490d9f Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Fri, 23 May 2025 23:22:35 +0500 Subject: [PATCH 61/71] refactor: Enhance AdminsManager and related filters with improved admin checks and feature management --- bot/core/admin_rights_manager.py | 36 +++++- bot/filters/admin.py | 120 +++++++++--------- .../admins/admin_settings/add_admin.py | 19 ++- .../admin_settings/add_admin_first_step.py | 10 +- bot/handlers/users/help.py | 10 -- .../test_admin_rights_manager_integration.py | 10 ++ 6 files changed, 117 insertions(+), 88 deletions(-) diff --git a/bot/core/admin_rights_manager.py b/bot/core/admin_rights_manager.py index 1f343db..2729368 100644 --- a/bot/core/admin_rights_manager.py +++ b/bot/core/admin_rights_manager.py @@ -6,6 +6,7 @@ from redis import Redis from bot.db.database import Database +from bot.data.config import ADMIN class AdminsManager: @@ -24,9 +25,13 @@ def __init__( self.create_table_admin_rights() def __call__(self, user_id: int, feature: str) -> Optional[bool]: - return self.get(user_id, feature) + return self.get(user_id, feature) or user_id == ADMIN + + def get(self, user_id: int, feature: str = None) -> Optional[bool]: + + if user_id == ADMIN: return True + if feature is None: return self.is_admin(user_id) - def get(self, user_id: int, feature: str) -> Optional[bool]: key = self._redis_key(user_id, feature) if (cached := self.redis.get(key)) is not None: @@ -55,6 +60,31 @@ def get(self, user_id: int, feature: str) -> Optional[bool]: self.db.reconnect() return None + def is_admin(self, user_id: int) -> bool: + if user_id == ADMIN: return True + + key = f"{self.ns}:{user_id}:__is_admin__" + cached = self.redis.get(key) + if cached is not None: + return cached == "1" + try: + sql = """ + SELECT 1 + FROM admins + WHERE user_id = %s + AND is_active = TRUE + LIMIT 1; + """ + self.db.cursor.execute(sql, (user_id,)) + row = self.db.cursor.fetchone() + is_admin = bool(row) + self.redis.set(key, "1" if is_admin else "0") + return is_admin + except mysql.connector.Error as err: + self.log.error(f"MySQL (is_admin) xatosi: {err}") + self.db.reconnect() + return False + def update(self, user_id: int, feature: str, value: bool, is_active: bool = True) -> None: try: sql = """ @@ -88,6 +118,8 @@ def add(self, user_id: int) -> None: (user_id,), ) self.db.connection.commit() + key = f"{self.ns}:{user_id}:__is_admin__" + self.redis.set(key, "1") except mysql.connector.Error as err: self.log.error(f"MySQL (add) xatosi: {err}") self.db.reconnect() diff --git a/bot/filters/admin.py b/bot/filters/admin.py index 99d44e1..b8cce99 100644 --- a/bot/filters/admin.py +++ b/bot/filters/admin.py @@ -33,63 +33,63 @@ async def __call__(self, message: Message) -> bool: return False -class AdminFilter: - - def __init__(self, user_id): - self.user_id = user_id - self.super_admin = ADMIN - self.dada = db.select_admin(user_id=self.user_id) - - def __call__(self): - if self.dada is not None: - return True - else: - return False - - def send_message(self) -> bool: - if self.user_id == self.super_admin: - return True - elif self.dada['send_message'] == 1: - return True - else: - return False - - def view_statistika(self) -> bool: - if self.user_id == self.super_admin: - return True - elif self.dada['statistika'] == 1: - return True - else: - return False - - def download_statistika(self) -> bool: - if self.user_id == self.super_admin: - return True - elif self.dada['download_statistika'] == 1: - return True - else: - return False - - def block_user(self) -> bool: - if self.user_id == self.super_admin: - return True - elif self.dada['block_user'] == 1: - return True - else: - return False - - def channel_settings(self) -> bool: - if self.user_id == self.super_admin: - return True - elif self.dada['channel_settings'] == 1: - return True - else: - return False - - def add_admin(self) -> bool: - if self.user_id == self.super_admin: - return True - elif self.dada['add_admin'] == 1: - return True - else: - return False \ No newline at end of file +# class AdminFilter: + +# def __init__(self, user_id): +# self.user_id = user_id +# self.super_admin = ADMIN +# self.dada = db.select_admin(user_id=self.user_id) + +# def __call__(self): +# if self.dada is not None: +# return True +# else: +# return False + +# def send_message(self) -> bool: +# if self.user_id == self.super_admin: +# return True +# elif self.dada['send_message'] == 1: +# return True +# else: +# return False + +# def view_statistika(self) -> bool: +# if self.user_id == self.super_admin: +# return True +# elif self.dada['statistika'] == 1: +# return True +# else: +# return False + +# def download_statistika(self) -> bool: +# if self.user_id == self.super_admin: +# return True +# elif self.dada['download_statistika'] == 1: +# return True +# else: +# return False + +# def block_user(self) -> bool: +# if self.user_id == self.super_admin: +# return True +# elif self.dada['block_user'] == 1: +# return True +# else: +# return False + +# def channel_settings(self) -> bool: +# if self.user_id == self.super_admin: +# return True +# elif self.dada['channel_settings'] == 1: +# return True +# else: +# return False + +# def add_admin(self) -> bool: +# if self.user_id == self.super_admin: +# return True +# elif self.dada['add_admin'] == 1: +# return True +# else: +# return False \ No newline at end of file diff --git a/bot/handlers/admins/admin_settings/add_admin.py b/bot/handlers/admins/admin_settings/add_admin.py index 26b5853..d173dc0 100755 --- a/bot/handlers/admins/admin_settings/add_admin.py +++ b/bot/handlers/admins/admin_settings/add_admin.py @@ -1,10 +1,10 @@ import logging from aiogram import types from aiogram.fsm.context import FSMContext -from bot.filters.admin import IsAdmin, AdminFilter +from bot.filters.admin import IsAdmin from bot.keyboards.inline.admin_btn import admin_setting from bot.keyboards.inline.close_btn import close_btn -from bot.loader import dp, bot, db, translator +from bot.loader import dp, bot, db, translator, AM from bot.states.admin_state import AdminState @@ -13,24 +13,21 @@ async def add_admin(msg: types.Message, state: FSMContext): try: user_id = msg.from_user.id - mid = msg.message_id + message_id = msg.message_id language_code = msg.from_user.language_code - data = AdminFilter(user_id=user_id) - add_admin_db = data.add_admin() target_user_id = int(msg.text) - if add_admin_db: + if AM(user_id=user_id, feature='add_admin_db'): data_state = await state.get_data() btn = await admin_setting(user_id=user_id, language_code=language_code) text = "🔴 Failed because admin was not found!\n" try: user = await bot.get_chat(chat_id=target_user_id) - check = db.select_admin(user_id=target_user_id) + check = AM.get(target_user_id) if check is None: - db.insert_admin(user_id=target_user_id, - initiator_user_id=user_id) + AM.add(user_id=target_user_id,) text = translator(text="✅ Admin has been successfully added\n\nName: ", dest=language_code) text += f"{user.full_name}\n" @@ -67,11 +64,11 @@ async def add_admin(msg: types.Message, state: FSMContext): dest=language_code) btn = close_btn() await bot.edit_message_text(chat_id=user_id, - message_id=mid, + message_id=message_id, text=f"{text}", reply_markup=btn) await state.update_data({ - "message_id": mid + "message_id": message_id }) except Exception as err: logging.error(err) diff --git a/bot/handlers/admins/admin_settings/add_admin_first_step.py b/bot/handlers/admins/admin_settings/add_admin_first_step.py index f20f886..f7d97ba 100755 --- a/bot/handlers/admins/admin_settings/add_admin_first_step.py +++ b/bot/handlers/admins/admin_settings/add_admin_first_step.py @@ -5,7 +5,7 @@ from bot.keyboards.inline.admin_btn import admin_setting from bot.keyboards.inline.button import AdminCallback from bot.keyboards.inline.close_btn import close_btn -from bot.loader import dp, bot, root_logger, translator +from bot.loader import dp, bot, root_logger, translator, AM from bot.states.admin_state import AdminState @@ -13,11 +13,11 @@ async def add_admin_first(call: types.CallbackQuery, state: FSMContext): try: user_id = call.from_user.id - mid = call.message.message_id + message_id = call.message.message_id language_code = call.from_user.language_code - admin = AdminFilter(user_id=user_id) - if admin.add_admin() : + + if AM(user_id=user_id, feature='add_admin'): text = translator(text="🔰 Please send the admin ID number you want to add...", dest=language_code) btn = await admin_setting(user_id=user_id, language_code=language_code) await state.set_state(AdminState.add_admin) @@ -26,7 +26,7 @@ async def add_admin_first(call: types.CallbackQuery, state: FSMContext): btn = close_btn() await bot.edit_message_text(chat_id=user_id, - message_id=mid, + message_id=message_id, text=f'{text}', reply_markup=btn) await state.update_data({"message_id": call.message.message_id}) diff --git a/bot/handlers/users/help.py b/bot/handlers/users/help.py index 26dca58..57b917e 100755 --- a/bot/handlers/users/help.py +++ b/bot/handlers/users/help.py @@ -9,16 +9,6 @@ @dp.message(Command(commands='help')) async def help_handler(msg: types.Message): - """ - Handles the /help command to provide users with information about the bot - and a button to share the bot's URL. - - Args: - msg (types.Message): The incoming message object. - - Returns: - None - """ try: # Get the user's language code user_language = msg.from_user.language_code diff --git a/tests/moduls/test_admin_rights_manager_integration.py b/tests/moduls/test_admin_rights_manager_integration.py index 1bef747..b7d1646 100644 --- a/tests/moduls/test_admin_rights_manager_integration.py +++ b/tests/moduls/test_admin_rights_manager_integration.py @@ -2,6 +2,7 @@ import pytest from bot.loader import db, redis, AM +from bot.data.config import ADMIN @pytest.mark.integration @@ -57,6 +58,15 @@ def test_admins_manager_full_cycle(): redis.delete(AM._redis_key(user_id, feat)) assert AM.get(user_id, feat) is None + + assert AM.is_admin(ADMIN) is True + assert AM(user_id=ADMIN, feature="test") is True + + AM.update(user_id=ADMIN, feature="test", value=False) + assert AM.get(user_id=ADMIN, feature="test") is True + assert AM.get(user_id=ADMIN) is True + + db.cursor.execute("DELETE FROM admin_rights WHERE admin_id=%s", (admin_pk,)) db.cursor.execute("DELETE FROM admins WHERE id=%s", (admin_pk,)) db.connection.commit() From 22b80758edd3fa600e8a17822ae029ae53f32ade Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Tue, 3 Jun 2025 21:20:32 +0500 Subject: [PATCH 62/71] refactor: Remove unnecessary comments and streamline admin checks in button handlers --- bot/api/translator.py | 6 -- .../admins/admin_settings/add_admin.py | 7 +-- bot/keyboards/inline/admin_btn.py | 56 ++++++++----------- 3 files changed, 26 insertions(+), 43 deletions(-) diff --git a/bot/api/translator.py b/bot/api/translator.py index f06a2b8..2bf556a 100644 --- a/bot/api/translator.py +++ b/bot/api/translator.py @@ -10,12 +10,6 @@ class Translator: - """ - Tarjima servisi: Redis → MySQL → GoogleTranslator - * Redis: texts, translations (hash) - * MySQL: texts, translations (tablalar) - """ - _REDIS_HASH_TEXTS = "texts" _REDIS_HASH_TRANSLATIONS = "translations" diff --git a/bot/handlers/admins/admin_settings/add_admin.py b/bot/handlers/admins/admin_settings/add_admin.py index d173dc0..2a5f267 100755 --- a/bot/handlers/admins/admin_settings/add_admin.py +++ b/bot/handlers/admins/admin_settings/add_admin.py @@ -24,9 +24,8 @@ async def add_admin(msg: types.Message, state: FSMContext): try: user = await bot.get_chat(chat_id=target_user_id) - check = AM.get(target_user_id) - - if check is None: + is_admin, initiator_user_id, created_at = AM(target_user_id) + if is_admin is None: AM.add(user_id=target_user_id,) text = translator(text="✅ Admin has been successfully added\n\nName: ", dest=language_code) @@ -44,7 +43,7 @@ async def add_admin(msg: types.Message, state: FSMContext): text += f'Username: @{user.username}\n' text += translator(text="Add date: ", dest=language_code) - text += f'{check[9]}\n{check[2]}' + text += f'{created_at}\n{check[2]}' text += translator(text="Added by", dest=language_code) except Exception as err: diff --git a/bot/keyboards/inline/admin_btn.py b/bot/keyboards/inline/admin_btn.py index 1c91af2..23ce0f2 100644 --- a/bot/keyboards/inline/admin_btn.py +++ b/bot/keyboards/inline/admin_btn.py @@ -4,9 +4,8 @@ from .close_btn import close_btn from bot.data.config import ADMIN -from bot.loader import db, bot, translator, FM, root_logger +from bot.loader import db, bot, translator, root_logger, FM, AM, SM from bot.function.function import x_or_y -from bot.filters.admin import AdminFilter def main_btn(): @@ -25,24 +24,24 @@ def main_admin_panel_btn(user_id, language_code): btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = AdminFilter(user_id=user_id) - if is_admin.add_admin() and FM.feature('admin_settings'): + + if AM['add_admin', user_id]: btn.button(text=translator(text=f"👮‍♂️ Admins settings!", dest=language_code), callback_data=AdminCallback(action="admin_settings", data="").pack()) - if is_admin.send_message(): + if AM('send_message', user_id): btn.button(text=translator(text=f"✈Send advertisement!", dest=language_code), callback_data=AdminCallback(action="send_advertisement", data="").pack()) - if is_admin.view_statistika(): + if AM('view_statistika', user_id): btn.button(text=translator(text=f"📜Statistika!", dest=language_code), callback_data=AdminCallback(action="statistika", data="").pack()) - if is_admin.block_user(): + if AM('block_user', user_id): btn.button(text=translator(text=f"👁‍🗨Check user!", dest=language_code), callback_data=AdminCallback(action="check_user", data="").pack()) - if is_admin.channel_settings(): + if AM('channel_settings', user_id): btn.button(text=translator(text=f"🔰Channel setting!", dest=language_code), callback_data=AdminCallback(action="channel_setting", data="").pack()) @@ -82,13 +81,12 @@ def attach_admin(user_id, language_code): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = AdminFilter(user_id=user_id) - send_message_tx = x_or_y(is_admin.send_message()) - wiew_statistika_tx = x_or_y(is_admin.view_statistika()) - download_statistika_tx = x_or_y(is_admin.download_statistika()) - block_user_tx = x_or_y(is_admin.block_user()) - channel_settings_tx = x_or_y(is_admin.channel_settings()) - add_admin_tx = x_or_y(is_admin.add_admin()) + send_message_tx = x_or_y(AM('send_message', user_id)) + wiew_statistika_tx = x_or_y(AM('view_statistika', user_id)) + download_statistika_tx = x_or_y(AM('download_statistika', user_id)) + block_user_tx = x_or_y(AM('block_user', user_id)) + channel_settings_tx = x_or_y(AM('channel_settings', user_id)) + add_admin_tx = x_or_y(AM('add_admin', user_id)) btn.button(text=translator(text=f"{send_message_tx} Send a message!", dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='send_message').pack()) @@ -125,13 +123,12 @@ def attach_admin_btn(user_id, language_code): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = AdminFilter(user_id=user_id) - send_message_tx = x_or_y(is_admin.send_message()) - wiew_statistika_tx = x_or_y(is_admin.view_statistika()) - download_statistika_tx = x_or_y(is_admin.download_statistika()) - block_user_tx = x_or_y(is_admin.block_user()) - channel_settings_tx = x_or_y(is_admin.channel_settings()) - add_admin_tx = x_or_y(is_admin.add_admin()) + send_message_tx = x_or_y(AM('send_message', user_id)) + wiew_statistika_tx = x_or_y(AM('view_statistika', user_id)) + download_statistika_tx = x_or_y(AM('download_statistika', user_id)) + block_user_tx = x_or_y(AM('block_user', user_id)) + channel_settings_tx = x_or_y(AM('channel_settings', user_id)) + add_admin_tx = x_or_y(AM('add_admin', user_id)) btn.button(text=translator(text=f"{send_message_tx} Send a message!", dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='send_message').pack()) @@ -168,7 +165,7 @@ def channel_settings(language_code): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - mandatory_membership = db.select_setting('mandatory_membership') + mandatory_membership = SM('mandatory_membership') if mandatory_membership == 'True': text = translator(text=f'✅ Mandatory membership of', dest=language_code) @@ -197,8 +194,7 @@ def block_user(attention_user_id, language_code, user_id): btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = AdminFilter(user_id=user_id) - if is_admin.block_user(): + if AM('block_user', user_id): data = db.check_user_ban(user_id=attention_user_id) if data is None: btn.button(text=translator(text=f"🚫Block user!", @@ -221,8 +217,7 @@ def download_statistika(user_id, language_code): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - is_admin = AdminFilter(user_id=user_id) - if is_admin.download_statistika(): + if AM('download_statistika', user_id): btn.button(text=translator(text=f"📜 Dowload statistika!", dest=language_code), callback_data=AdminCallback(action="download_statistika", data="").pack()) @@ -236,21 +231,16 @@ def download_statistika(user_id, language_code): def stop_advertisement(): try: - # Initialize the inline keyboard builder btn = InlineKeyboardBuilder() - # Add a button labeled "🚫 Stop!" with callback data to handle the stop_ads action + btn.button( text='🚫 Stop!', callback_data=AdminCallback(action="stop_ads", data="").pack() ) - # Return the constructed inline keyboard markup return btn.as_markup() except Exception as err: - # Log any exceptions that occur during the button creation process root_logger.error(f"Error in stop_ads function: {err}") - - # Return False to indicate the failure of the operation return False From c9b927431a5b393c7c9c929d684065e513e2e986 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Tue, 3 Jun 2025 22:25:11 +0500 Subject: [PATCH 63/71] refactor: Enhance AdminsManager with improved feature management and initiator tracking --- bot/core/admin_rights_manager.py | 143 ++++++++++++------ bot/db/template.sql | 29 ++++ .../test_admin_rights_manager_integration.py | 131 ++++++++++------ 3 files changed, 211 insertions(+), 92 deletions(-) create mode 100644 bot/db/template.sql diff --git a/bot/core/admin_rights_manager.py b/bot/core/admin_rights_manager.py index 2729368..d54ca51 100644 --- a/bot/core/admin_rights_manager.py +++ b/bot/core/admin_rights_manager.py @@ -24,23 +24,27 @@ def __init__( self.create_table_admins() self.create_table_admin_rights() - def __call__(self, user_id: int, feature: str) -> Optional[bool]: - return self.get(user_id, feature) or user_id == ADMIN - def get(self, user_id: int, feature: str = None) -> Optional[bool]: + def __call__(self, user_id: int, feature: str, return_intiator: bool = False) -> Optional[bool]: if user_id == ADMIN: return True - if feature is None: return self.is_admin(user_id) + if not self[user_id][0]: return None - key = self._redis_key(user_id, feature) + key = f"{self.ns}:{user_id}:features:feature:{feature}:is_active" if (cached := self.redis.get(key)) is not None: + if return_intiator: + initiator_key = f"{self.ns}:{user_id}:features:feature:{feature}:initiator_user_id" + initiator_user_id = self.redis.get(initiator_key) + return cached == "1", int(initiator_user_id) if initiator_user_id else None return cached == "1" try: - sql = """ - SELECT `value` - FROM `admin_rights` AS ar + sql = f""" + SELECT + `value` + {", `initiator_user_id`" if return_intiator else ""} + FROM `admin_rights` AS ar INNER JOIN `admins` AS a ON ar.admin_id=a.id WHERE a.user_id = %s @@ -53,55 +57,84 @@ def get(self, user_id: int, feature: str = None) -> Optional[bool]: if row: value = bool(row["value"]) self.redis.set(key, "1" if value else "0") + if return_intiator: + initiator_user_id = row.get("initiator_user_id") + initiator_key = f"{self.ns}:{user_id}:features:feature:{feature}:initiator_user_id" + self.redis.set(initiator_key, initiator_user_id) + return value, int(initiator_user_id) return value + + if return_intiator: + return None, None return None except mysql.connector.Error as err: self.log.error(f"MySQL (get) xatosi: {err}") self.db.reconnect() return None - def is_admin(self, user_id: int) -> bool: - if user_id == ADMIN: return True + def __getitem__(self, user_id: int) -> (bool | int): + if user_id == ADMIN: return True, None, "super_admin" + + is_active = f"{self.ns}:{user_id}:is_active" + cached = self.redis.get(is_active) + initiator_user_id = self.redis.get(f"{self.ns}:{user_id}:initiator_user_id") + role = self.redis.get(f"{self.ns}:{user_id}:role") - key = f"{self.ns}:{user_id}:__is_admin__" - cached = self.redis.get(key) if cached is not None: - return cached == "1" + return cached == "1", int(initiator_user_id), role try: sql = """ - SELECT 1 - FROM admins - WHERE user_id = %s - AND is_active = TRUE + SELECT + `is_active`, + `initiator_user_id`, + `role` + FROM `admins + WHERE `user_id` = %s + AND `is_active` = TRUE LIMIT 1; """ self.db.cursor.execute(sql, (user_id,)) row = self.db.cursor.fetchone() - is_admin = bool(row) - self.redis.set(key, "1" if is_admin else "0") - return is_admin + if not row: + return False, None, None + is_admin = row["is_active"] + + self.redis.set(is_active, "1" if is_admin else "0") + self.redis.set(f"{self.ns}:{user_id}:initiator_user_id", row["initiator_user_id"]) + self.redis.set(f"{self.ns}:{user_id}:role", row["role"]) + return is_admin, row["initiator_user_id"], row["role"] except mysql.connector.Error as err: self.log.error(f"MySQL (is_admin) xatosi: {err}") self.db.reconnect() return False - def update(self, user_id: int, feature: str, value: bool, is_active: bool = True) -> None: + def update(self, user_id: int, feature: str, value: bool, initiator_user_id: int) -> None: try: - sql = """ - INSERT INTO admin_rights (admin_id, name, value, is_active) - VALUES ( - (SELECT id FROM admins WHERE user_id = %s), - %s, -- feature - %s, -- value - %s -- is_active - ) - ON DUPLICATE KEY UPDATE - value = VALUES(value), - is_active = VALUES(is_active), - updated_at = CURRENT_TIMESTAMP; - """ - self.db.cursor.execute(sql, (user_id, feature, int(value), is_active)) - self.db.connection.commit() + is_admin = self[user_id] + check = self(user_id, feature, return_intiator=True) + if initiator_user_id == check[1] or is_admin[1] == initiator_user_id or initiator_user_id == ADMIN: + if is_admin[0] is False: + self.log.warning(f"User {user_id} is not an admin, cannot update feature {feature}.") + return + elif check[0] == value: + self.log.info(f"Feature {feature} for user {user_id} is already set to {value}.") + return + elif check[0]: + self.db.cursor.execute( + "UPDATE `admin_rights` SET `value` = %s, `updater_user_id` = %s WHERE `admin_id` = (SELECT id FROM admins WHERE user_id = %s) AND `name` = %s;", + (value, initiator_user_id, user_id, feature) + ) + else: + self.db.cursor.execute( + "INSERT INTO `admin_rights` (`admin_id`, `name`, `value`, `initiator_user_id`) VALUES ((SELECT id FROM admins WHERE user_id = %s), %s, %s, %s);", + (user_id, feature, value, initiator_user_id) + ) + self.redis.set(f"{self.ns}:{user_id}:features:feature:{feature}:is_active", "1" if value else "0") + self.redis.set(f"{self.ns}:{user_id}:features:feature:{feature}:initiator_user_id", initiator_user_id) + self.db.connection.commit() + else: + self.log.warning(f"User {initiator_user_id} is not authorized to update feature {feature} for user {user_id}.") + return except mysql.connector.Error as err: self.log.error(f"MySQL (update) xatosi: {err}") self.db.reconnect() @@ -111,22 +144,44 @@ def update(self, user_id: int, feature: str, value: bool, is_active: bool = True key = self._redis_key(user_id, feature) self.redis.set(key, "1" if value else "0") - def add(self, user_id: int) -> None: + def add(self, user_id: int, initiator_user_id: int, role: str = 'admin') -> None: try: + if self[user_id][0]: + return + self.db.cursor.execute( - "INSERT INTO `admins` (`user_id`) VALUES (%s);", - (user_id,), + "INSERT INTO `admins` (`user_id`, `initiator_user_id`, `role`) VALUES (%s, %s, %s);", + (user_id, initiator_user_id, role), ) self.db.connection.commit() - key = f"{self.ns}:{user_id}:__is_admin__" - self.redis.set(key, "1") + self.redis.set(f"{self.ns}:{user_id}:is_active", "1") + self.redis.set(f"{self.ns}:{user_id}:initiator_user_id", initiator_user_id) + self.redis.set(f"{self.ns}:{user_id}:role", role) except mysql.connector.Error as err: self.log.error(f"MySQL (add) xatosi: {err}") self.db.reconnect() - def _redis_key(self, admin_id: int, feature: str) -> str: - return f"{self.ns}:{admin_id}:{feature}" - + def remove(self, user_id: int, initiator_user_id: int) -> None: + try: + check = self[user_id] + if not check[0]: + return + elif check[1] == initiator_user_id: + sql = """ + UPDATE `admins` + SET `is_active` = FALSE, `deleted_at` = CURRENT_TIMESTAMP, `updater_user_id` = %s + WHERE `user_id` = %s; + """ + self.db.cursor.execute(sql, (initiator_user_id, user_id)) + self.db.connection.commit() + self.redis.set(f"{self.ns}:{user_id}:is_active", "0") + self.redis.set(f"{self.ns}:{user_id}:initiator_user_id", initiator_user_id) + self.redis.set(f"{self.ns}:{user_id}:role", None) + + except mysql.connector.Error as err: + self.log.error(f"MySQL (remove) xatosi: {err}") + self.db.reconnect() + def create_table_admins(self): try: sql = """ diff --git a/bot/db/template.sql b/bot/db/template.sql new file mode 100644 index 0000000..c424112 --- /dev/null +++ b/bot/db/template.sql @@ -0,0 +1,29 @@ +CREATE TABLE IF NOT EXISTS `admins` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `user_id` BIGINT NOT NULL UNIQUE, + `initiator_user_id` BIGINT, + `updater_user_id` BIGINT, + `role` ENUM('admin', 'moderator') DEFAULT 'admin', + `is_active` BOOLEAN DEFAULT TRUE, + `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP NULL DEFAULT NULL +); + +CREATE TABLE IF NOT EXISTS `admin_rights` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `admin_id` INT NOT NULL, + `name` VARCHAR(255) NOT NULL, + `value` BOOLEAN NOT NULL, + `is_active` BOOLEAN DEFAULT TRUE, + `description` TEXT, + `initiator_user_id` BIGINT, + `updater_user_id` BIGINT, + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP NULL, + UNIQUE KEY `uq_admin_feature` (`admin_id`,`name`), + CONSTRAINT `fk_rights_admin` + FOREIGN KEY (`admin_id`) REFERENCES `admins`(`id`) + ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; \ No newline at end of file diff --git a/tests/moduls/test_admin_rights_manager_integration.py b/tests/moduls/test_admin_rights_manager_integration.py index b7d1646..392f3a3 100644 --- a/tests/moduls/test_admin_rights_manager_integration.py +++ b/tests/moduls/test_admin_rights_manager_integration.py @@ -1,74 +1,109 @@ import random import pytest -from bot.loader import db, redis, AM -from bot.data.config import ADMIN +from bot.loader import db, redis, AM # allaqachon tayyor obyektlar +from bot.data.config import ADMIN # super-admin user_id +FEATURES = ["can_ban_users", "can_post", "is_super_admin"] -@pytest.mark.integration -def test_admins_manager_full_cycle(): + +def r_key(user_id: int, feature: str) -> str: + """is_active kesh kaliti.""" + return f"{AM.ns}:{user_id}:features:feature:{feature}:is_active" + + +def r_init_key(user_id: int, feature: str) -> str: + """initiator_user_id kesh kaliti.""" + return f"{AM.ns}:{user_id}:features:feature:{feature}:initiator_user_id" +@pytest.mark.integration +def test_admins_manager_full_cycle(): + # --- 1. Tayyorlov ------------------------------------------------------ user_id = random.randint(10**10, 10**11 - 1) - features = ["can_ban_users", "can_post", "is_super_admin"] - db.cursor.execute("DELETE FROM admin_rights WHERE admin_id IN (SELECT id FROM admins WHERE user_id = %s)", (user_id,)) - db.cursor.execute("DELETE FROM admins WHERE user_id = %s", (user_id,)) + # DB va Redisni tozalash (bo‘lishi mumkin bo‘lgan eski qoldiqlarni o‘chirib tashlash) + db.cursor.execute( + "DELETE FROM admin_rights WHERE admin_id IN (SELECT id FROM admins WHERE user_id=%s)", + (user_id,), + ) + db.cursor.execute("DELETE FROM admins WHERE user_id=%s", (user_id,)) db.connection.commit() - for f in features: - redis.delete(AM._redis_key(user_id, f)) + for key in list(redis.scan_iter(f"{AM.ns}:{user_id}*")): + redis.delete(key) - AM.add(user_id) - AM.add(user_id) + # --- 2. Admin qo‘shish -------------------------------------------------- + AM.add(user_id=user_id, initiator_user_id=ADMIN) + # bazaga yozilganini tekshirish db.cursor.execute("SELECT id FROM admins WHERE user_id=%s", (user_id,)) admin_row = db.cursor.fetchone() - assert admin_row, "Admin qo'shilmadi" + assert admin_row, "Admin qo'shilmadi." admin_pk = admin_row["id"] - for feat in features: + # __getitem__ keshga ham yozishini tekshiramiz + is_admin, init_id, role = AM[user_id] + assert (is_admin, init_id, role) == (True, ADMIN, "admin") + assert redis.get(f"{AM.ns}:{user_id}:is_active") == "1" - assert AM.get(user_id, feat) is None + # --- 3. Har bir feature bo‘yicha sikl ---------------------------------- + for feat in FEATURES: + # 3.1 Boshlang‘ich holat: huquq yo‘q + assert AM(user_id, feat) is None - AM.update(user_id, feat, True) + # 3.2 Huquqni yoqish + AM.update(user_id, feat, True, initiator_user_id=ADMIN) + # DB db.cursor.execute( - "SELECT value, is_active FROM admin_rights WHERE admin_id=%s AND name=%s", + "SELECT value, is_active, initiator_user_id " + "FROM admin_rights WHERE admin_id=%s AND name=%s;", (admin_pk, feat), ) row = db.cursor.fetchone() - assert row and row["value"] == 1 and row["is_active"] == 1 - - assert redis.get(AM._redis_key(user_id, feat)) == "1" - - assert AM.get(user_id, feat) is True - - AM.update(user_id, feat, False) - - db.cursor.execute( - "SELECT value FROM admin_rights WHERE admin_id=%s AND name=%s", - (admin_pk, feat), - ) - assert db.cursor.fetchone()["value"] == 0 - assert redis.get(AM._redis_key(user_id, feat)) == "0" - assert AM.get(user_id, feat) is False - - AM.update(user_id, feat, False, is_active=False) - - redis.delete(AM._redis_key(user_id, feat)) - assert AM.get(user_id, feat) is None - - - assert AM.is_admin(ADMIN) is True - assert AM(user_id=ADMIN, feature="test") is True - - AM.update(user_id=ADMIN, feature="test", value=False) - assert AM.get(user_id=ADMIN, feature="test") is True - assert AM.get(user_id=ADMIN) is True - - + assert row and row["value"] == 1 and row["is_active"] == 1 and row["initiator_user_id"] == ADMIN + + # Redis + assert redis.get(r_key(user_id, feat)) == "1" + assert redis.get(r_init_key(user_id, feat)) == str(ADMIN) + + # __call__ (keshdan o‘qiydi) + assert AM(user_id, feat) is True + + # 3.3 Huquqni o‘chirish + AM.update(user_id, feat, False, initiator_user_id=ADMIN) + assert AM(user_id, feat) is False + assert redis.get(r_key(user_id, feat)) == "0" + + # 3.4 Noto‘g‘ri initiator urinishini rad etish + wrong_initiator = random.randint(10**10, 10**11 - 1) + AM.update(user_id, feat, True, initiator_user_id=wrong_initiator) + # qiymat o‘zgarmasligi kerak + assert AM(user_id, feat) is False + + # --- 4. Adminni o‘chirish ---------------------------------------------- + AM.remove(user_id, initiator_user_id=ADMIN) + is_admin, *_ = AM[user_id] + assert is_admin is False + assert redis.get(f"{AM.ns}:{user_id}:is_active") == "0" + + # --- 5. Super-admin tezkor yo‘llari ------------------------------------ + # __getitem__ + sa_is_admin, sa_init, sa_role = AM[ADMIN] + assert sa_is_admin is True and sa_role == "super_admin" + + # __call__ (huquq nomi muhim emas) + assert AM(ADMIN, "qandaydir_huquq") is True + status, initiator = AM(ADMIN, "another", return_intiator=True) + assert status is True and initiator == ADMIN + + # Super-admin huquqi yangilansa ham effekt qilmasligi kerak + AM.update(user_id=ADMIN, feature="any_feature", value=False, initiator_user_id=ADMIN) + assert AM(ADMIN, "any_feature") is True + + # --- 6. Tozalash -------------------------------------------------------- db.cursor.execute("DELETE FROM admin_rights WHERE admin_id=%s", (admin_pk,)) db.cursor.execute("DELETE FROM admins WHERE id=%s", (admin_pk,)) db.connection.commit() - for f in features: - redis.delete(AM._redis_key(user_id, f)) + for key in list(redis.scan_iter(f"{AM.ns}:{user_id}*")): + redis.delete(key) From 4eb368de4e58be2b045fcb5a213d941dd271d42a Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Sun, 29 Jun 2025 12:43:04 +0500 Subject: [PATCH 64/71] Refactor admin rights management system - Simplified admin filter logic by removing redundant code and utilizing a new AM class for admin checks. - Updated admin settings handlers to integrate with the new AM class for managing admin rights. - Enhanced admin button generation to dynamically reflect available rights based on the AM class. - Improved integration tests for the admin rights manager, ensuring comprehensive coverage of admin functionalities. - Added new features to the admin rights management system, allowing for more granular control over admin capabilities. --- bot/core/admin_rights_manager.py | 683 ++++++++++++------ bot/db/database.py | 38 +- bot/db/template.sql | 42 +- bot/filters/admin.py | 73 +- .../admins/admin_settings/add_admin.py | 8 +- .../admin_settings/add_admin_first_step.py | 2 +- .../admins/admin_settings/admin_setting.py | 7 +- .../admins/admin_settings/attach_admins.py | 37 +- .../admins/admin_settings/edit_admin.py | 55 +- bot/keyboards/inline/admin_btn.py | 89 +-- bot/main.py | 11 + bot/middlewares/throttling.py | 10 +- .../test_admin_rights_manager_integration.py | 446 +++++++++--- 13 files changed, 969 insertions(+), 532 deletions(-) diff --git a/bot/core/admin_rights_manager.py b/bot/core/admin_rights_manager.py index d54ca51..7f217b2 100644 --- a/bot/core/admin_rights_manager.py +++ b/bot/core/admin_rights_manager.py @@ -1,235 +1,510 @@ -# bot/core/admin_rights_manager.py +import json import logging -from typing import Optional - -import mysql.connector from redis import Redis +from datetime import datetime +from typing import Tuple, Optional, List, Dict, Any + from bot.db.database import Database from bot.data.config import ADMIN class AdminsManager: - def __init__( - self, - db: Database, - redis_client: Redis, - root_logger: logging.Logger, - redis_namespace: str = "admin_setting", - ) -> None: + """ + Telegram botida administratorlarni va ularning huquqlarini boshqarish uchun klass. + Redis va MySQL ma'lumotlar bazalaridan foydalanadi. + """ + + def __init__(self, db: Database, + redis_client: Redis, + root_logger: logging.Logger, + redis_namespace: str = "admin_setting"): + """ + Klass konstruktori + + Args: + db: MySQL bilan ishlash uchun abstraksiya obyekti + redis_client: Redis bilan muloqot qiluvchi obyekt + root_logger: Loyihaviy loglar uchun logger + redis_namespace: Redis kalitlari prefiksi + """ self.db = db self.redis = redis_client + self.logger = root_logger self.ns = redis_namespace - self.log = root_logger.getChild(self.__class__.__name__) - self.create_table_admins() - self.create_table_admin_rights() - - - def __call__(self, user_id: int, feature: str, return_intiator: bool = False) -> Optional[bool]: + self.now = datetime.now() - if user_id == ADMIN: return True - if not self[user_id][0]: return None - - key = f"{self.ns}:{user_id}:features:feature:{feature}:is_active" - - if (cached := self.redis.get(key)) is not None: - if return_intiator: - initiator_key = f"{self.ns}:{user_id}:features:feature:{feature}:initiator_user_id" - initiator_user_id = self.redis.get(initiator_key) - return cached == "1", int(initiator_user_id) if initiator_user_id else None - return cached == "1" - - try: - sql = f""" - SELECT - `value` - {", `initiator_user_id`" if return_intiator else ""} - FROM `admin_rights` AS ar - INNER JOIN `admins` AS a - ON ar.admin_id=a.id - WHERE a.user_id = %s - AND `name` = %s - AND ar.`is_active` = TRUE - LIMIT 1 + # Kerakli jadvallarni yaratish + self._create_tables() + + def _create_tables(self): + """Ma'lumotlar bazasida kerakli jadvallarni yaratish""" + tables = [ + """ + CREATE TABLE IF NOT EXISTS `admins` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `user_id` BIGINT NOT NULL, + `initiator_user_id` BIGINT, + `updater_user_id` BIGINT, + `role` ENUM('admin','moderator') DEFAULT 'admin', + `is_active` BOOLEAN DEFAULT TRUE, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP NULL, + KEY `idx_user_id`(`user_id`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """, """ - self.db.cursor.execute(sql, (user_id, feature)) - row = self.db.cursor.fetchone() - if row: - value = bool(row["value"]) - self.redis.set(key, "1" if value else "0") - if return_intiator: - initiator_user_id = row.get("initiator_user_id") - initiator_key = f"{self.ns}:{user_id}:features:feature:{feature}:initiator_user_id" - self.redis.set(initiator_key, initiator_user_id) - return value, int(initiator_user_id) - return value + CREATE TABLE IF NOT EXISTS `rights` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(100), + `key` VARCHAR(100) NOT NULL, + `description` TEXT, + `is_active` BOOLEAN DEFAULT TRUE, + `initiator_user_id` BIGINT, + `updater_user_id` BIGINT, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP NULL, + KEY `idx_key`(`key`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """, + """ + CREATE TABLE IF NOT EXISTS admin_rights ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `admin_id` INT NOT NULL, + `rights_id` INT NOT NULL, + `value` BOOLEAN NOT NULL, + `description` TEXT, + `initiator_user_id` BIGINT, + `updater_user_id` BIGINT, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP NULL, + UNIQUE KEY uq_admin_right (`admin_id`, `rights_id`), + CONSTRAINT fk_admin_rights_admin + FOREIGN KEY (`admin_id`) REFERENCES `admins`(id) + ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT fk_admin_rights_right + FOREIGN KEY (`rights_id`) REFERENCES `rights`(id) + ON DELETE CASCADE ON UPDATE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """ + ] - if return_intiator: - return None, None - return None - except mysql.connector.Error as err: - self.log.error(f"MySQL (get) xatosi: {err}") - self.db.reconnect() - return None - - def __getitem__(self, user_id: int) -> (bool | int): - if user_id == ADMIN: return True, None, "super_admin" - - is_active = f"{self.ns}:{user_id}:is_active" - cached = self.redis.get(is_active) - initiator_user_id = self.redis.get(f"{self.ns}:{user_id}:initiator_user_id") - role = self.redis.get(f"{self.ns}:{user_id}:role") - - if cached is not None: - return cached == "1", int(initiator_user_id), role try: - sql = """ - SELECT - `is_active`, - `initiator_user_id`, - `role` - FROM `admins - WHERE `user_id` = %s - AND `is_active` = TRUE - LIMIT 1; + for table_sql in tables: + self.db.cursor.execute(table_sql) + except Exception as e: + self.logger.error(f"Jadvallarni yaratishda xatolik: {e}") + + def __call__(self, user_id: int, feature: str, return_initiator: bool = False) -> Tuple[Optional[bool], Optional[int]]: + """ + Admin huquqini tekshirish + + Args: + user_id: Admin telegram user ID + feature: Xususiyat nomi + return_initiator: Initiator ID qaytarish kerakmi + + Returns: + (is_active, initiator_user_id) yoki (is_active,) yoki (None, None) + """ + try: + if user_id == ADMIN: + return True, None if return_initiator else True + + feature_active_key = f"{self.ns}:rights:{feature}:is_active" + feature_active = self.redis.get(feature_active_key) + + if feature_active is None: + # MySQL dan feature faolligini tekshirish + query = "SELECT is_active FROM rights WHERE `key` = %s AND deleted_at IS NULL" + self.db.cursor.execute(query, (feature,)) + result = self.db.cursor.fetchone() + + if not result: + return None, None if return_initiator else None + + feature_active = result['is_active'] + self.redis.set(feature_active_key, str(int(feature_active))) + else: + feature_active = bool(int(feature_active)) + + if not feature_active: + return None, None if return_initiator else None + + # Redis dan qidirish + redis_key = f"{self.ns}:admin_rights:{user_id}:{feature}" + cached_data = self.redis.get(redis_key) + + if cached_data: + data = json.loads(cached_data) + if return_initiator: + return data.get('value', False), data.get('initiator_user_id') + return data.get('value', False) + + # MySQL dan qidirish + query = """ + SELECT ar.value, ar.initiator_user_id + FROM admin_rights ar + JOIN admins a ON ar.admin_id = a.id + JOIN rights r ON ar.rights_id = r.id + WHERE a.user_id = %s AND r.key = %s + AND a.is_active = TRUE AND a.deleted_at IS NULL + AND r.is_active = TRUE AND r.deleted_at IS NULL + AND ar.deleted_at IS NULL """ - self.db.cursor.execute(sql, (user_id,)) - row = self.db.cursor.fetchone() - if not row: - return False, None, None - is_admin = row["is_active"] - - self.redis.set(is_active, "1" if is_admin else "0") - self.redis.set(f"{self.ns}:{user_id}:initiator_user_id", row["initiator_user_id"]) - self.redis.set(f"{self.ns}:{user_id}:role", row["role"]) - return is_admin, row["initiator_user_id"], row["role"] - except mysql.connector.Error as err: - self.log.error(f"MySQL (is_admin) xatosi: {err}") - self.db.reconnect() - return False + + self.db.cursor.execute(query, (user_id, feature)) + result = self.db.cursor.fetchone() + + if result: + # Redis ga saqlash + cache_data = { + 'value': result['value'], + 'initiator_user_id': result['initiator_user_id'] + } + self.redis.set(redis_key, json.dumps(cache_data)) + + if return_initiator: + return result['value'], result['initiator_user_id'] + return result['value'] + + return False, None if return_initiator else False + + except Exception as e: + self.logger.error(f"Huquq tekshirishda xatolik: {e}") + return (None, None) if return_initiator else None + def __getitem__(self, user_id: int) -> Tuple[Optional[bool], Optional[int], Optional[str], Optional[datetime]]: + """ + Admin ekanligini tekshirish + + Args: + user_id: Tekshirilayotgan admin telegram ID + + Returns: + (is_admin, initiator_user_id, role, created_at) + """ + try: + if user_id == ADMIN: + return True, None, 'super_admin', None + + redis_key = f"{self.ns}:admins:{user_id}" + cached_data = self.redis.get(redis_key) + + if cached_data: + data = json.loads(cached_data) + created_at = datetime.fromisoformat(data['created_at']) if data.get('created_at') else None + return data.get('is_active'), data.get('initiator_user_id'), data.get('role'), created_at + + # MySQL dan qidirish + query = """ + SELECT is_active, initiator_user_id, role, created_at + FROM admins + WHERE user_id = %s AND deleted_at IS NULL + """ + + self.db.cursor.execute(query, (user_id,)) + result = self.db.cursor.fetchone() + + if result: + # Redis ga saqlash + cache_data = { + 'is_active': result['is_active'], + 'initiator_user_id': result['initiator_user_id'], + 'role': result['role'], + 'created_at': result['created_at'].isoformat() if result['created_at'] else None + } + self.redis.set(redis_key, json.dumps(cache_data)) + + return result['is_active'], result['initiator_user_id'], result['role'], result['created_at'] + + return None, None, None, None + + except Exception as e: + self.logger.error(f"Admin tekshirishda xatolik: {e}") + return None, None, None, None + def update(self, user_id: int, feature: str, value: bool, initiator_user_id: int) -> None: + """ + Admin huquqini yangilash yoki yaratish + + Args: + user_id: Yangilanayotgan admin telegram user ID + feature: Yangilanayotgan xususiyat + value: Huquq qiymati + initiator_user_id: Huquq berayotgan admin telegram user ID + """ try: - is_admin = self[user_id] - check = self(user_id, feature, return_intiator=True) - if initiator_user_id == check[1] or is_admin[1] == initiator_user_id or initiator_user_id == ADMIN: - if is_admin[0] is False: - self.log.warning(f"User {user_id} is not an admin, cannot update feature {feature}.") - return - elif check[0] == value: - self.log.info(f"Feature {feature} for user {user_id} is already set to {value}.") - return - elif check[0]: - self.db.cursor.execute( - "UPDATE `admin_rights` SET `value` = %s, `updater_user_id` = %s WHERE `admin_id` = (SELECT id FROM admins WHERE user_id = %s) AND `name` = %s;", - (value, initiator_user_id, user_id, feature) - ) - else: - self.db.cursor.execute( - "INSERT INTO `admin_rights` (`admin_id`, `name`, `value`, `initiator_user_id`) VALUES ((SELECT id FROM admins WHERE user_id = %s), %s, %s, %s);", - (user_id, feature, value, initiator_user_id) - ) - self.redis.set(f"{self.ns}:{user_id}:features:feature:{feature}:is_active", "1" if value else "0") - self.redis.set(f"{self.ns}:{user_id}:features:feature:{feature}:initiator_user_id", initiator_user_id) - self.db.connection.commit() - else: - self.log.warning(f"User {initiator_user_id} is not authorized to update feature {feature} for user {user_id}.") + # Admin ekanligini tekshirish + is_admin, _, _, _ = self.__getitem__(user_id) + if not is_admin: + self.logger.warning(f"User {user_id} admin emas") return - except mysql.connector.Error as err: - self.log.error(f"MySQL (update) xatosi: {err}") - self.db.reconnect() - return - - # Redis keshini yangilash - key = self._redis_key(user_id, feature) - self.redis.set(key, "1" if value else "0") - + + # Rights mavjudligini tekshirish + rights_query = "SELECT id FROM rights WHERE `key` = %s AND is_active = TRUE AND deleted_at IS NULL" + self.db.cursor.execute(rights_query, (feature,)) + right_result = self.db.cursor.fetchone() + + if not right_result: + # self.logger.warning(f"Feature '{feature}' mavjud emas yoki faol emas") + return + + rights_id = right_result['id'] + + # Admin ID olish + admin_query = "SELECT id FROM admins WHERE user_id = %s AND deleted_at IS NULL" + self.db.cursor.execute(admin_query, (user_id,)) + admin_result = self.db.cursor.fetchone() + + if not admin_result: + self.logger.warning(f"Admin {user_id} topilmadi") + return + + admin_id = admin_result['id'] + + # Admin_rights da mavjudligini tekshirish + check_query = "SELECT id FROM admin_rights WHERE admin_id = %s AND rights_id = %s AND deleted_at IS NULL" + self.db.cursor.execute(check_query, (admin_id, rights_id)) + existing = self.db.cursor.fetchone() + + current_time = datetime.now() + + if existing: + # Yangilash + update_query = """ + UPDATE admin_rights + SET value = %s, updater_user_id = %s, updated_at = %s + WHERE id = %s + """ + self.db.cursor.execute(update_query, (value, initiator_user_id, current_time, existing['id'])) + else: + # Yaratish + insert_query = """ + INSERT INTO admin_rights (admin_id, rights_id, value, initiator_user_id, updater_user_id, created_at, updated_at) + VALUES (%s, %s, %s, %s, %s, %s, %s) + """ + self.db.cursor.execute(insert_query, (admin_id, rights_id, value, initiator_user_id, initiator_user_id, current_time, current_time)) + + # Redis dan o'chirish (keyingi so'rovda yangilanadi) + redis_key = f"{self.ns}:admin_rights:{user_id}:{feature}" + self.redis.delete(redis_key) + + # self.logger.info(f"Admin {user_id} uchun {feature} huquqi {value} ga o'zgartirildi") + + except Exception as e: + self.logger.error(f"Huquq yangilashda xatolik: {e}") + def add(self, user_id: int, initiator_user_id: int, role: str = 'admin') -> None: + """ + Yangi admin qo'shish + + Args: + user_id: Qo'shilayotgan admin telegram ID + initiator_user_id: Qo'shayotgan admin ID + role: Admin roli + """ try: - if self[user_id][0]: + # Allaqachon admin emasligini tekshirish + is_admin, _, _, _ = self.__getitem__(user_id) + if is_admin: + self.logger.warning(f"User {user_id} allaqachon admin") return + + # Initiator admin ekanligini va add_admin huquqini tekshirish + if initiator_user_id != ADMIN: + initiator_is_admin, _, _, _ = self.__getitem__(initiator_user_id) + if not initiator_is_admin: + self.logger.warning(f"Initiator {initiator_user_id} admin emas") + return + + can_add_admin = self.__call__(initiator_user_id, 'add_admin') + if not can_add_admin: + self.logger.warning(f"Initiator {initiator_user_id} da add_admin huquqi yo'q") + return + + # Yangi admin qo'shish + current_time = datetime.now() + insert_query = """ + INSERT INTO admins (user_id, initiator_user_id, updater_user_id, role, is_active, created_at, updated_at) + VALUES (%s, %s, %s, %s, %s, %s, %s) + """ + self.db.cursor.execute(insert_query, (user_id, initiator_user_id, initiator_user_id, role, True, current_time, current_time)) + + # Redis dan o'chirish + redis_key = f"{self.ns}:admins:{user_id}" + cache_data = { + "is_active": True, + "initiator_user_id": initiator_user_id, + "role": role, + "created_at": current_time.isoformat() + } + self.redis.set(redis_key, json.dumps(cache_data)) - self.db.cursor.execute( - "INSERT INTO `admins` (`user_id`, `initiator_user_id`, `role`) VALUES (%s, %s, %s);", - (user_id, initiator_user_id, role), - ) - self.db.connection.commit() - self.redis.set(f"{self.ns}:{user_id}:is_active", "1") - self.redis.set(f"{self.ns}:{user_id}:initiator_user_id", initiator_user_id) - self.redis.set(f"{self.ns}:{user_id}:role", role) - except mysql.connector.Error as err: - self.log.error(f"MySQL (add) xatosi: {err}") - self.db.reconnect() - + + self.logger.info(f"Yangi admin qo'shildi: {user_id}, initiator: {initiator_user_id}") + + except Exception as e: + self.logger.error(f"Admin qo'shishda xatolik: {e}") + def remove(self, user_id: int, initiator_user_id: int) -> None: + """ + Admin faolligini o'chirish + + Args: + user_id: O'chiriladigan admin telegram ID + initiator_user_id: O'chirmoqchi bo'lgan admin ID + """ try: - check = self[user_id] - if not check[0]: + # Admin ma'lumotlarini olish + is_admin, admin_initiator_id, _, _ = self.__getitem__(user_id) + if not is_admin: + self.logger.warning(f"User {user_id} admin emas") return - elif check[1] == initiator_user_id: - sql = """ - UPDATE `admins` - SET `is_active` = FALSE, `deleted_at` = CURRENT_TIMESTAMP, `updater_user_id` = %s - WHERE `user_id` = %s; - """ - self.db.cursor.execute(sql, (initiator_user_id, user_id)) - self.db.connection.commit() - self.redis.set(f"{self.ns}:{user_id}:is_active", "0") - self.redis.set(f"{self.ns}:{user_id}:initiator_user_id", initiator_user_id) - self.redis.set(f"{self.ns}:{user_id}:role", None) + + # Huquqni tekshirish: faqat shu adminni qo'shgan yoki super admin o'chira oladi + if initiator_user_id != ADMIN and initiator_user_id != admin_initiator_id: + self.logger.warning(f"Initiator {initiator_user_id} admin {user_id} ni o'chira olmaydi") + return + + # Admin faolligini o'chirish + current_time = datetime.now() + update_query = """ + UPDATE admins + SET is_active = FALSE, updater_user_id = %s, updated_at = %s + WHERE user_id = %s AND deleted_at IS NULL + """ + self.db.cursor.execute(update_query, (initiator_user_id, current_time, user_id)) + + # Redis dan o'chirish + redis_key = f"{self.ns}:admins:{user_id}" + self.redis.delete(redis_key) + + # Admin huquqlarini ham Redis dan o'chirish + redis_pattern = f"{self.ns}:admin_rights:{user_id}:*" + keys = self.redis.keys(redis_pattern) + if keys: + self.redis.delete(*keys) + + self.logger.info(f"Admin {user_id} o'chirildi, initiator: {initiator_user_id}") + + except Exception as e: + self.logger.error(f"Admin o'chirishda xatolik: {e}") + + def list_features(self) -> List[Dict[str, Any]]: + """ + Barcha xususiyatlarni ro'yxat shaklida qaytarish - except mysql.connector.Error as err: - self.log.error(f"MySQL (remove) xatosi: {err}") - self.db.reconnect() - - def create_table_admins(self): + Returns: + Xususiyatlar ro'yxati + """ try: - sql = """ - CREATE TABLE IF NOT EXISTS `admins` ( - `id` INT AUTO_INCREMENT PRIMARY KEY, - `user_id` BIGINT NOT NULL UNIQUE, - `initiator_user_id` BIGINT, - `updater_user_id` BIGINT, - `role` ENUM('admin', 'moderator') DEFAULT 'admin', - `is_active` BOOLEAN DEFAULT TRUE, - `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, - `deleted_at` TIMESTAMP NULL DEFAULT NULL - ); - """ - self.db.cursor.execute(sql) - self.db.connection.commit() - except mysql.connector.Error as err: - self.log.error(err) - self.db.reconnect() - except Exception as err: - self.log.error(err) - - def create_table_admin_rights(self): + query = "SELECT * FROM rights WHERE deleted_at IS NULL ORDER BY created_at DESC" + self.db.cursor.execute(query) + return self.db.cursor.fetchall() + except Exception as e: + self.logger.error(f"Xususiyatlar ro'yxatini olishda xatolik: {e}") + return [] + + def update_features(self, key: str, initiator_user_id: int, name: str = None, + description: str = None, is_active: bool = False) -> None: + """ + Yangi feature qo'shish yoki yangilash + + Args: + key: Huquq kaliti + initiator_user_id: Qo'shayotgan admin telegram ID + name: Huquq nomi + description: Huquq haqida ma'lumot + is_active: Feature faolligi + """ try: - sql = """ - CREATE TABLE IF NOT EXISTS `admin_rights` ( - `id` INT AUTO_INCREMENT PRIMARY KEY, - `admin_id` INT NOT NULL, - `name` VARCHAR(255) NOT NULL, - `value` BOOLEAN NOT NULL, - `is_active` BOOLEAN DEFAULT TRUE, - `description` TEXT, - `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - `deleted_at` TIMESTAMP NULL, - UNIQUE KEY `uq_admin_feature` (`admin_id`,`name`), - CONSTRAINT `fk_rights_admin` - FOREIGN KEY (`admin_id`) REFERENCES `admins`(`id`) - ON DELETE CASCADE ON UPDATE CASCADE - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - """ - self.db.cursor.execute(sql) - self.db.connection.commit() - except mysql.connector.Error as err: - self.log.error(err) - self.db.reconnect() - except Exception as err: - self.log.error(err) - self.db.reconnect() + # add_rights maxsus huquq uchun faqat super admin + if key == 'add_rights': + if initiator_user_id != ADMIN: + self.logger.warning(f"add_rights huquqini faqat super admin o'zgartira oladi") + return + else: + # Boshqa huquqlar uchun add_rights huquqini tekshirish + if initiator_user_id != ADMIN: + initiator_is_admin, _, _, _ = self.__getitem__(initiator_user_id) + if not initiator_is_admin: + self.logger.warning(f"Initiator {initiator_user_id} admin emas") + return + + can_add_rights = self.__call__(initiator_user_id, 'add_rights') + if not can_add_rights: + self.logger.warning(f"Initiator {initiator_user_id} da add_rights huquqi yo'q") + return + + # Mavjudligini tekshirish + check_query = "SELECT id FROM rights WHERE `key` = %s AND deleted_at IS NULL" + self.db.cursor.execute(check_query, (key,)) + existing = self.db.cursor.fetchone() + + current_time = datetime.now() + + if existing: + # Yangilash + update_query = """ + UPDATE rights + SET name = %s, description = %s, is_active = %s, updater_user_id = %s, updated_at = %s + WHERE id = %s + """ + self.db.cursor.execute(update_query, (name, description, is_active, initiator_user_id, current_time, existing['id'])) + else: + # Yaratish + insert_query = """ + INSERT INTO rights (name, `key`, description, is_active, initiator_user_id, updater_user_id, created_at, updated_at) + VALUES (%s, %s, %s, %s, %s, %s, %s, %s) + """ + self.db.cursor.execute(insert_query, (name, key, description, is_active, initiator_user_id, initiator_user_id, current_time, current_time)) + + # Redis dan feature faolligini yangilash + feature_active_key = f"{self.ns}:rights:{key}:is_active" + self.redis.set(feature_active_key, str(int(is_active))) + + # self.logger.info(f"Feature '{key}' yangilandi/yaratildi, initiator: {initiator_user_id}") + + except Exception as e: + self.logger.error(f"Feature yangilashda xatolik: {e}") + def my_admins(self, user_id: int) -> List[Dict[str, Any]]: + """ + Berilgan user_id uchun qo'shgan adminlar ro'yxati + + Args: + user_id: Tekshirilayotgan admin telegram ID + + Returns: + Adminlar ro'yxati + """ + try: + # Super admin uchun barcha adminlar + if user_id == ADMIN: + query = "SELECT * FROM admins WHERE deleted_at IS NULL ORDER BY created_at DESC" + self.db.cursor.execute(query) + return self.db.cursor.fetchall() + + # Oddiy admin uchun tekshirish + is_admin, _, _, _ = self.__getitem__(user_id) + if not is_admin: + self.logger.warning(f"User {user_id} admin emas") + return [] + + can_add_admin = self.__call__(user_id, 'add_admin') + if not can_add_admin: + self.logger.warning(f"User {user_id} da add_admin huquqi yo'q") + return [] + + # Shu user tomonidan qo'shilgan adminlar + query = "SELECT * FROM admins WHERE initiator_user_id = %s AND deleted_at IS NULL ORDER BY created_at DESC" + self.db.cursor.execute(query, (user_id,)) + return self.db.cursor.fetchall() + + except Exception as e: + self.logger.error(f"Adminlar ro'yxatini olishda xatolik: {e}") + return [] \ No newline at end of file diff --git a/bot/db/database.py b/bot/db/database.py index c5b904b..f14b46e 100755 --- a/bot/db/database.py +++ b/bot/db/database.py @@ -292,6 +292,40 @@ def check_user(self, user_id): self.root_logger.error(err) + def select_channels(self): + """ + Select all channels from the 'channels' table. + + Returns: + list: A list of tuples containing all channels' information. + """ + try: + self.cursor.execute("SELECT * FROM `channels`") + results = self.cursor.fetchall() + return results + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) + + + + + + + + + + + + + + + + + + class MySQLHandler(logging.Handler): @@ -353,4 +387,6 @@ def emit(self, record): def close(self): self.cursor.close() self.connection.close() - super().close() \ No newline at end of file + super().close() + + diff --git a/bot/db/template.sql b/bot/db/template.sql index c424112..696b688 100644 --- a/bot/db/template.sql +++ b/bot/db/template.sql @@ -1,29 +1,47 @@ CREATE TABLE IF NOT EXISTS `admins` ( `id` INT AUTO_INCREMENT PRIMARY KEY, - `user_id` BIGINT NOT NULL UNIQUE, + `user_id` BIGINT NOT NULL, `initiator_user_id` BIGINT, `updater_user_id` BIGINT, - `role` ENUM('admin', 'moderator') DEFAULT 'admin', + `role` ENUM('admin','moderator') DEFAULT 'admin', `is_active` BOOLEAN DEFAULT TRUE, - `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, - `deleted_at` TIMESTAMP NULL DEFAULT NULL -); + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP NULL ON UPDATE CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP NULL, + KEY `idx_user_id`(`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + + +CREATE TABLE IF NOT EXISTS `rights` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(100), + `key` VARCHAR(100) NOT NULL, + `description` TEXT, + `is_active` BOOLEAN DEFAULT TRUE, + `initiator_user_id` BIGINT, + `updater_user_id` BIGINT, + `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP NULL, + KEY `idx_key`(`key`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; CREATE TABLE IF NOT EXISTS `admin_rights` ( `id` INT AUTO_INCREMENT PRIMARY KEY, `admin_id` INT NOT NULL, - `name` VARCHAR(255) NOT NULL, + `rights_id` INT NOT NULL, `value` BOOLEAN NOT NULL, - `is_active` BOOLEAN DEFAULT TRUE, `description` TEXT, `initiator_user_id` BIGINT, `updater_user_id` BIGINT, - `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, `deleted_at` TIMESTAMP NULL, - UNIQUE KEY `uq_admin_feature` (`admin_id`,`name`), - CONSTRAINT `fk_rights_admin` - FOREIGN KEY (`admin_id`) REFERENCES `admins`(`id`) + UNIQUE KEY uq_admin_right (`admin_id`, `rights_id`), + CONSTRAINT fk_admin_rights_admin + FOREIGN KEY (`admin_id`) REFERENCES `admins`(id) + ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT fk_admin_rights_right + FOREIGN KEY (`rights_id`) REFERENCES `rights`(id) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; \ No newline at end of file diff --git a/bot/filters/admin.py b/bot/filters/admin.py index b8cce99..d2c7141 100644 --- a/bot/filters/admin.py +++ b/bot/filters/admin.py @@ -3,7 +3,7 @@ from typing import Optional, Any from bot.data.config import ADMIN -from bot.loader import db, redis +from bot.loader import db, redis, AM class IsSuperAdmin(BaseFilter): @@ -24,72 +24,7 @@ def __init__(self): async def __call__(self, message: Message) -> bool: self.user_id = message.from_user.id - self.dada = db.select_admin(user_id=self.user_id) - if self.user_id == ADMIN: - return True - elif self.dada is not None: - return True - else: - return False - - -# class AdminFilter: - -# def __init__(self, user_id): -# self.user_id = user_id -# self.super_admin = ADMIN -# self.dada = db.select_admin(user_id=self.user_id) - -# def __call__(self): -# if self.dada is not None: -# return True -# else: -# return False - -# def send_message(self) -> bool: -# if self.user_id == self.super_admin: -# return True -# elif self.dada['send_message'] == 1: -# return True -# else: -# return False - -# def view_statistika(self) -> bool: -# if self.user_id == self.super_admin: -# return True -# elif self.dada['statistika'] == 1: -# return True -# else: -# return False - -# def download_statistika(self) -> bool: -# if self.user_id == self.super_admin: -# return True -# elif self.dada['download_statistika'] == 1: -# return True -# else: -# return False - -# def block_user(self) -> bool: -# if self.user_id == self.super_admin: -# return True -# elif self.dada['block_user'] == 1: -# return True -# else: -# return False - -# def channel_settings(self) -> bool: -# if self.user_id == self.super_admin: -# return True -# elif self.dada['channel_settings'] == 1: -# return True -# else: -# return False + is_admin, _, _, _ = AM.__getitem__(self.user_id) + print(is_admin) + return True if is_admin else False -# def add_admin(self) -> bool: -# if self.user_id == self.super_admin: -# return True -# elif self.dada['add_admin'] == 1: -# return True -# else: -# return False \ No newline at end of file diff --git a/bot/handlers/admins/admin_settings/add_admin.py b/bot/handlers/admins/admin_settings/add_admin.py index 2a5f267..2203716 100755 --- a/bot/handlers/admins/admin_settings/add_admin.py +++ b/bot/handlers/admins/admin_settings/add_admin.py @@ -4,7 +4,7 @@ from bot.filters.admin import IsAdmin from bot.keyboards.inline.admin_btn import admin_setting from bot.keyboards.inline.close_btn import close_btn -from bot.loader import dp, bot, db, translator, AM +from bot.loader import dp, bot, translator, AM from bot.states.admin_state import AdminState @@ -24,9 +24,9 @@ async def add_admin(msg: types.Message, state: FSMContext): try: user = await bot.get_chat(chat_id=target_user_id) - is_admin, initiator_user_id, created_at = AM(target_user_id) + is_admin, initiator_user_id, role, created_at = AM[target_user_id] if is_admin is None: - AM.add(user_id=target_user_id,) + AM.add(user_id=target_user_id, initiator_user_id=user_id) text = translator(text="✅ Admin has been successfully added\n\nName: ", dest=language_code) text += f"{user.full_name}\n" @@ -43,7 +43,7 @@ async def add_admin(msg: types.Message, state: FSMContext): text += f'Username: @{user.username}\n' text += translator(text="Add date: ", dest=language_code) - text += f'{created_at}\n{check[2]}' + text += f'{created_at}\n{initiator_user_id}' text += translator(text="Added by", dest=language_code) except Exception as err: diff --git a/bot/handlers/admins/admin_settings/add_admin_first_step.py b/bot/handlers/admins/admin_settings/add_admin_first_step.py index f7d97ba..e7ecbc6 100755 --- a/bot/handlers/admins/admin_settings/add_admin_first_step.py +++ b/bot/handlers/admins/admin_settings/add_admin_first_step.py @@ -1,7 +1,7 @@ from aiogram import types, F from aiogram.fsm.context import FSMContext -from bot.filters.admin import IsAdmin, AdminFilter +from bot.filters.admin import IsAdmin from bot.keyboards.inline.admin_btn import admin_setting from bot.keyboards.inline.button import AdminCallback from bot.keyboards.inline.close_btn import close_btn diff --git a/bot/handlers/admins/admin_settings/admin_setting.py b/bot/handlers/admins/admin_settings/admin_setting.py index fc455fb..e9595ca 100755 --- a/bot/handlers/admins/admin_settings/admin_setting.py +++ b/bot/handlers/admins/admin_settings/admin_setting.py @@ -2,11 +2,11 @@ from aiogram import types, F from aiogram.fsm.context import FSMContext -from bot.filters.admin import IsAdmin, AdminFilter +from bot.filters.admin import IsAdmin from bot.keyboards.inline.admin_btn import admin_setting from bot.keyboards.inline.button import AdminCallback from bot.keyboards.inline.close_btn import close_btn -from bot.loader import dp, bot, translator +from bot.loader import dp, bot, translator, AM @@ -16,9 +16,8 @@ async def admin_settings(call: types.CallbackQuery, state: FSMContext): user_id = call.from_user.id mid = call.message.message_id language_code = call.from_user.language_code - admin = AdminFilter(user_id=user_id) - if admin.add_admin(): + if AM[user_id]: text = translator(text="❗ You are in the Admin settings section!", dest=language_code) btn = await admin_setting(user_id=user_id, language_code=language_code) else: diff --git a/bot/handlers/admins/admin_settings/attach_admins.py b/bot/handlers/admins/admin_settings/attach_admins.py index ec1a0cf..0a1e5b5 100755 --- a/bot/handlers/admins/admin_settings/attach_admins.py +++ b/bot/handlers/admins/admin_settings/attach_admins.py @@ -2,12 +2,12 @@ from aiogram.fsm.context import FSMContext from bot.data.config import ADMIN -from bot.filters.admin import IsAdmin, AdminFilter +from bot.filters.admin import IsAdmin from bot.function.function import x_or_y from bot.keyboards.inline.admin_btn import attach_admin_btn from bot.keyboards.inline.button import AdminSetting from bot.keyboards.inline.close_btn import close_btn -from bot.loader import dp, bot, db, root_logger, translator +from bot.loader import dp, bot, root_logger, translator, AM from bot.states.admin_state import AdminState @@ -19,33 +19,18 @@ async def attach_admins(call: types.CallbackQuery, callback_data: AdminSetting, user_id = call.from_user.id mid = call.message.message_id language_code = call.from_user.language_code - admin_user_id = callback_data.user_id - data = AdminFilter(user_id=user_id) + target_user_id = callback_data.user_id btn = close_btn() - if data.add_admin(): - admin_data = db.select_admin(user_id=admin_user_id) - if admin_data['initiator_user_id'] == user_id or user_id == ADMIN: - btn = attach_admin_btn(user_id=admin_user_id, + if AM[user_id]: + is_admin, initiator_user_id, role, created_at = AM[target_user_id] + if initiator_user_id == user_id or user_id == ADMIN: + btn = attach_admin_btn(user_id=target_user_id, language_code=language_code) - is_admin = AdminFilter(user_id=admin_user_id) - - - send_message_tx = x_or_y(is_admin.send_message()) - view_statistika_tx = x_or_y(is_admin.view_statistika()) - download_statistika_tx = x_or_y(is_admin.download_statistika()) - block_user_tx = x_or_y(is_admin.block_user()) - channel_settings_tx = x_or_y(is_admin.channel_settings()) - add_admin_tx = x_or_y(is_admin.add_admin()) - - text = f'👮‍♂️Admin rights!\n\n' \ - f'Send message: {send_message_tx}\n' \ - f'View statistics: {view_statistika_tx}\n' \ - f'Download statistics: {download_statistika_tx}\n' \ - f'Block user: {block_user_tx}\n' \ - f'Channel settings: {channel_settings_tx}\n' \ - f'Add admin: {add_admin_tx}\n' \ - f'Date added: ' + + text = f'👮‍♂️Admin rights!\n\n' + for f in AM.list_features(): + text += f"{f['name']}: {x_or_y(AM(user_id=target_user_id, feature=f['key']))}\n" else: text = translator(text='😪You can only change the admin rights you added!', dest=language_code) else: diff --git a/bot/handlers/admins/admin_settings/edit_admin.py b/bot/handlers/admins/admin_settings/edit_admin.py index 4addf14..65be3c8 100755 --- a/bot/handlers/admins/admin_settings/edit_admin.py +++ b/bot/handlers/admins/admin_settings/edit_admin.py @@ -2,10 +2,10 @@ from aiogram.fsm.context import FSMContext from bot.data.config import ADMIN -from bot.filters.admin import IsAdmin, AdminFilter +from bot.filters.admin import IsAdmin from bot.function.function import x_or_y from bot.keyboards.inline.close_btn import close_btn -from bot.loader import dp, bot, db, root_logger, translator +from bot.loader import dp, bot, db, root_logger, translator, AM from bot.states.admin_state import AdminState from bot.keyboards.inline.button import EditAdminSetting from bot.keyboards.inline.admin_btn import attach_admin_btn @@ -17,46 +17,31 @@ async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, user_id = call.from_user.id mid = call.message.message_id language_code = call.from_user.language_code - admin_user_id = callback_data.user_id + target_user_id = callback_data.user_id edit_key = callback_data.data - data = AdminFilter(user_id=user_id) - add_admin = data.add_admin() btn = close_btn() - if add_admin: - admin_data = db.select_admin(user_id=admin_user_id) - if admin_data is None: - text = f'⛔{admin_user_id} {translator(text="😪 Not available in admin list!", dest=language_code)}' + if AM(user_id=user_id, feature='add_admin'): + is_admin, initiator_user_id, role, created_at = AM.__getitem__(target_user_id) + if not is_admin: + text = f'⛔{target_user_id} {translator(text="😪 Not available in admin list!", dest=language_code)}' else: - if admin_data['initiator_user_id'] == user_id or user_id == ADMIN: + if initiator_user_id == user_id or user_id == ADMIN: if edit_key == "delete_admin": - db.delete_admin(user_id=admin_user_id) - admin_info = await bot.get_chat(chat_id=admin_user_id) + AM.remove(user_id=target_user_id, initiator_user_id=user_id) + admin_info = await bot.get_chat(chat_id=target_user_id) text = f'🔪 @{admin_info.username} {translator(text="✅ Removed from admin!", dest=language_code)}' - await bot.send_message(chat_id=admin_user_id, text='😪 Your admin rights have been revoked!') + await bot.send_message(chat_id=target_user_id, text='😪 Your admin rights have been revoked!') else: - select_column = db.select_admin_column(user_id=admin_user_id, column=edit_key) - new_value = 0 if select_column['result'] == 1 else 1 - db.update_admin_data(user_id=admin_user_id, column=edit_key, value=new_value, updater_user_id=user_id) - btn = attach_admin_btn(user_id=admin_user_id, language_code=language_code) - is_admin = AdminFilter(user_id=admin_user_id) - send_message_tx = x_or_y(is_admin.send_message()) - view_statistika_tx = x_or_y(is_admin.view_statistika()) - download_statistika_tx = x_or_y(is_admin.download_statistika()) - block_user_tx = x_or_y(is_admin.block_user()) - channel_settings_tx = x_or_y(is_admin.channel_settings()) - add_admin_tx = x_or_y(is_admin.add_admin()) - text = f'👮 Change saved!\n\n' \ - f'Send message: {send_message_tx}\n' \ - f'View statistics: {view_statistika_tx}\n' \ - f'Download statistics: {download_statistika_tx}\n' \ - f'Block user: {block_user_tx}\n' \ - f'Channel settings: {channel_settings_tx}\n' \ - f'Add admin: {add_admin_tx}\n' \ - f'Date added: ' - text += str(admin_data['created_at']) - text += f'\nUpdated added: ' - text += str(admin_data['updated_at']) + feature = AM(user_id=edit_key, feature=edit_key) + value = False if feature else True + AM.update(user_id=target_user_id, feature=edit_key, value=value, initiator_user_id=user_id) + + btn = attach_admin_btn(user_id=target_user_id, language_code=language_code) + + text = '👮 Change saved!\n\n' + for feature in AM.list_features(): + text += f"{feature['name']}: {x_or_y(AM(user_id=user_id, feature=feature['key']))}\n" else: text = translator(text='🛑 You can only change the admin rights you assigned!', dest=language_code) diff --git a/bot/keyboards/inline/admin_btn.py b/bot/keyboards/inline/admin_btn.py index 23ce0f2..07419f6 100644 --- a/bot/keyboards/inline/admin_btn.py +++ b/bot/keyboards/inline/admin_btn.py @@ -23,28 +23,14 @@ def main_admin_panel_btn(user_id, language_code): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - - - if AM['add_admin', user_id]: - btn.button(text=translator(text=f"👮‍♂️ Admins settings!", - dest=language_code), - callback_data=AdminCallback(action="admin_settings", data="").pack()) - if AM('send_message', user_id): - btn.button(text=translator(text=f"✈Send advertisement!", - dest=language_code), - callback_data=AdminCallback(action="send_advertisement", data="").pack()) - if AM('view_statistika', user_id): - btn.button(text=translator(text=f"📜Statistika!", - dest=language_code), - callback_data=AdminCallback(action="statistika", data="").pack()) - if AM('block_user', user_id): - btn.button(text=translator(text=f"👁‍🗨Check user!", - dest=language_code), - callback_data=AdminCallback(action="check_user", data="").pack()) - if AM('channel_settings', user_id): - btn.button(text=translator(text=f"🔰Channel setting!", - dest=language_code), - callback_data=AdminCallback(action="channel_setting", data="").pack()) + rights = AM.list_features() + for right in rights: + if AM.__call__(user_id=user_id, feature=right['key']): + text = translator(text=right['name'], + dest=language_code) + btn.button(text='👮‍♂️ ' + text, + callback_data=AdminCallback(action="admin_settings", data="").pack()) + btn.adjust(1, 2) btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) return btn.as_markup() @@ -52,20 +38,15 @@ def main_admin_panel_btn(user_id, language_code): root_logger.error(err) return False - async def admin_setting(user_id, language_code): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - if user_id == ADMIN: - data = db.select_all_admins() - else: - data = db.select_add_admin(user_id=user_id) - if data is not None: - for x in data: - info = await bot.get_chat(chat_id=x['user_id']) - btn.button(text=f"👮‍♂️ @{info.username}: {info.full_name}!", - callback_data=AdminSetting(action="attach_admin", user_id=x['user_id']).pack()) + admins = AM.my_admins(user_id=user_id) + for x in admins: + info = await bot.get_chat(chat_id=x['user_id']) + btn.button(text=f"{x_or_y(x['is_active'])} @{info.username}: {info.full_name}!", + callback_data=AdminSetting(action="attach_admin", user_id=x['user_id']).pack()) btn.button(text=translator(text=f"👮‍♂️ ADD Admin!", dest=language_code), callback_data=AdminCallback(action="add_admin", data="").pack()) @@ -76,7 +57,6 @@ async def admin_setting(user_id, language_code): root_logger.error(err) return False - def attach_admin(user_id, language_code): try: btn = InlineKeyboardBuilder() @@ -118,38 +98,23 @@ def attach_admin(user_id, language_code): root_logger.error(err) return False - def attach_admin_btn(user_id, language_code): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - send_message_tx = x_or_y(AM('send_message', user_id)) - wiew_statistika_tx = x_or_y(AM('view_statistika', user_id)) - download_statistika_tx = x_or_y(AM('download_statistika', user_id)) - block_user_tx = x_or_y(AM('block_user', user_id)) - channel_settings_tx = x_or_y(AM('channel_settings', user_id)) - add_admin_tx = x_or_y(AM('add_admin', user_id)) - btn.button(text=translator(text=f"{send_message_tx} Send a message!", - dest=language_code), - callback_data=EditAdminSetting(action="edit", user_id=user_id, data='send_message').pack()) - btn.button(text=translator(text=f"{wiew_statistika_tx} Wiew statistics!", - dest=language_code), - callback_data=EditAdminSetting(action="edit", user_id=user_id, data='statistika').pack()) - - btn.button(text=translator(text=f"{download_statistika_tx} Download statistics!", - dest=language_code), - callback_data=EditAdminSetting(action="edit", user_id=user_id, data='download_statistika').pack()) - - btn.button(text=translator(text=f"{block_user_tx} Block user!", - dest=language_code), - callback_data=EditAdminSetting(action="edit", user_id=user_id, data='block_user').pack()) - btn.button(text=translator(text=f"{channel_settings_tx} Channel settings!", - dest=language_code), - callback_data=EditAdminSetting(action="edit", user_id=user_id, data='channel_settings').pack()) - btn.button(text=translator(text=f"{add_admin_tx} Add a admin!", - dest=language_code), - callback_data=EditAdminSetting(action="edit", user_id=user_id, data='add_admin').pack()) + rights = AM.list_features() + for right in rights: + check = AM.__call__(user_id=user_id, feature=right['key']) + text = x_or_y(check) + ' ' + translator(text=right['name'], + dest=language_code) + + btn.button(text=text, + callback_data=EditAdminSetting( + action="edit", + user_id=user_id, + data=right['key']).pack()) + btn.button(text=translator(text=f"🔪Delete admin!", dest=language_code), callback_data=EditAdminSetting(action="edit", user_id=user_id, data='delete_admin').pack()) @@ -160,7 +125,6 @@ def attach_admin_btn(user_id, language_code): root_logger.error(err) return False - def channel_settings(language_code): try: btn = InlineKeyboardBuilder() @@ -188,7 +152,6 @@ def channel_settings(language_code): root_logger.error(err) return False - def block_user(attention_user_id, language_code, user_id): try: btn = InlineKeyboardBuilder() @@ -212,7 +175,6 @@ def block_user(attention_user_id, language_code, user_id): root_logger.error(err) return False - def download_statistika(user_id, language_code): try: btn = InlineKeyboardBuilder() @@ -228,7 +190,6 @@ def download_statistika(user_id, language_code): root_logger.error(err) return False - def stop_advertisement(): try: btn = InlineKeyboardBuilder() diff --git a/bot/main.py b/bot/main.py index 0feec94..4ba25cf 100755 --- a/bot/main.py +++ b/bot/main.py @@ -1,6 +1,7 @@ import bot.handlers import logging from bot.loader import * +from bot.data.config import ADMIN from bot.utils.notify_admins import on_startup_notify from bot.utils.set_bot_commands import set_default_commands from bot.db.database import MySQLHandler @@ -11,6 +12,16 @@ async def main(): await set_default_commands() try: + + admin_rights = [ + ('add_admin', 'Add admins.', 'Yangi adminlar qo\'shish imkoniyati.'), + ('add_rights', 'Add rights.', 'Adminlar uchun qushimcha huqqu qushish.'), + ('add_features', 'Add features', 'Bot uchun yangi imkoniyatlar qushish.'), + ] + + for key, name, description in admin_rights: + AM.update_features(key, ADMIN, name, description, True) + # middlewares if FM.feature('middlewares'): from bot.middlewares.throttling import ThrottlingMiddleware diff --git a/bot/middlewares/throttling.py b/bot/middlewares/throttling.py index 39806ca..65397e7 100755 --- a/bot/middlewares/throttling.py +++ b/bot/middlewares/throttling.py @@ -6,7 +6,7 @@ from bot.data.config import ADMIN from bot.keyboards.inline.close_btn import close_btn from bot.keyboards.inline.button import MainCallback -from bot.loader import translator, root_logger, FM +from bot.loader import translator, root_logger, FM, AM from bot.db.database import Database @@ -135,17 +135,15 @@ async def check_ban(self, user_data): else: return False except Exception as err: - logging.error(err) + root_logger.error(err) return False async def check_member(self, user_id, language_code): try: - is_mandatory = self.db.select_setting('mandatory_membership') + is_mandatory = FM('mandatory_membership') if is_mandatory is None: - self.db.update_settings_key(updater_user_id=1, - key='mandatory_membership', - value=False) + FM.upsert_feature('mandatory_membership', enabled=False) return False elif is_mandatory == 'False': return False diff --git a/tests/moduls/test_admin_rights_manager_integration.py b/tests/moduls/test_admin_rights_manager_integration.py index 392f3a3..44662e7 100644 --- a/tests/moduls/test_admin_rights_manager_integration.py +++ b/tests/moduls/test_admin_rights_manager_integration.py @@ -1,109 +1,343 @@ -import random -import pytest +import asyncio +import time +from datetime import datetime +from bot.loader import AM +from bot.data.config import ADMIN -from bot.loader import db, redis, AM # allaqachon tayyor obyektlar -from bot.data.config import ADMIN # super-admin user_id +def test_admins_manager_complete(): + """ + AdminsManager klassining to'liq funksionalligini test qilish + """ + print("=== AdminsManager Test Boshlandi ===\n") + + # Test ma'lumotlari + SUPER_ADMIN_ID = ADMIN + TEST_ADMIN_1 = 987654321 # Test admin 1 + TEST_ADMIN_2 = 111222333 # Test admin 2 + TEST_USER = 444555666 # Oddiy user (admin emas) + + try: + print("1. DASTLABKI HOLATNI TEKSHIRISH") + print("-" * 40) + + # Avval barcha test ma'lumotlarini tozalash + print("Test ma'lumotlarini tozalash...") + + # MySQL dan tozalash + AM.db.cursor.execute("DELETE FROM admin_rights WHERE admin_id IN (SELECT id FROM admins WHERE user_id IN (%s, %s, %s))", + (TEST_ADMIN_1, TEST_ADMIN_2, TEST_USER)) + AM.db.cursor.execute("DELETE FROM admins WHERE user_id IN (%s, %s, %s)", + (TEST_ADMIN_1, TEST_ADMIN_2, TEST_USER)) + AM.db.cursor.execute("DELETE FROM rights WHERE `key` IN ('test_feature', 'add_admin', 'delete_admin', 'edit_rights', 'add_rights')") + + # Redis dan tozalash + redis_keys = AM.redis.keys(f"{AM.ns}:*") + if redis_keys: + AM.redis.delete(*redis_keys) + + print("✓ Test ma'lumotlari tozalandi") + + print("\n2. SUPER ADMIN TEKSHIRISH") + print("-" * 40) + + # Super admin qo'shish (bu odatda dastur boshida amalga oshiriladi) + AM.add(SUPER_ADMIN_ID, SUPER_ADMIN_ID, 'admin') + + # Super admin ekanligini tekshirish + is_admin, initiator, role, created_at = AM[SUPER_ADMIN_ID] + print(f"Super admin tekshiruvi: is_admin={is_admin}, role={role}") + assert is_admin == True, "Super admin qo'shilmadi" + print("✓ Super admin muvaffaqiyatli qo'shildi") + + print("\n3. FEATURES (HUQUQLAR) YARATISH") + print("-" * 40) + + # Asosiy huquqlarni yaratish + features_to_create = [ + ('add_admin', 'Admin qo\'shish huquqi', 'Yangi adminlar qo\'shish imkoniyati'), + ('delete_admin', 'Admin o\'chirish huquqi', 'Adminlarni o\'chirish imkoniyati'), + ('edit_rights', 'Huquqlarni tahrirlash', 'Admin huquqlarini o\'zgartirish'), + ('add_rights', 'Yangi huquq qo\'shish', 'Yangi huquqlar yaratish'), + ('test_feature', 'Test huquq', 'Test uchun yaratilgan huquq') + ] + + for key, name, description in features_to_create: + AM.update_features(key, SUPER_ADMIN_ID, name, description, True) + print(f"✓ '{key}' huquqi yaratildi") + + # Huquqlar ro'yxatini tekshirish + features_list = AM.list_features() + print(f"Jami huquqlar soni: {len(features_list)}") + assert len(features_list) >= 5, "Huquqlar to'liq yaratilmadi" + + print("\n4. SUPER ADMIN HUQUQLARINI BERISH") + print("-" * 40) + + # Super admin ga barcha huquqlarni berish + for key, _, _ in features_to_create: + AM.update(SUPER_ADMIN_ID, key, True, SUPER_ADMIN_ID) + print(f"✓ Super admin ga '{key}' huquqi berildi") + + # Huquqlarni tekshirish + can_add_admin = AM(SUPER_ADMIN_ID, 'add_admin') + can_delete_admin = AM(SUPER_ADMIN_ID, 'delete_admin') + can_edit_rights = AM(SUPER_ADMIN_ID, 'edit_rights') + + print(f"Super admin huquqlari: add_admin={can_add_admin}, delete_admin={can_delete_admin}, edit_rights={can_edit_rights}") + assert all([can_add_admin, can_delete_admin, can_edit_rights]), "Super admin huquqlari noto'g'ri" + + print("\n5. YANGI ADMINLAR QO'SHISH") + print("-" * 40) + + # Birinchi admin qo'shish + AM.add(TEST_ADMIN_1, SUPER_ADMIN_ID, 'admin') + is_admin_1, initiator_1, role_1, created_1 = AM[TEST_ADMIN_1] + print(f"Admin 1 qo'shildi: is_admin={is_admin_1}, initiator={initiator_1}, role={role_1}") + assert is_admin_1 == True, "Test admin 1 qo'shilmadi" + assert initiator_1 == SUPER_ADMIN_ID, "Initiator noto'g'ri" + + # Ikkinchi admin qo'shish + AM.add(TEST_ADMIN_2, SUPER_ADMIN_ID, 'moderator') + is_admin_2, initiator_2, role_2, created_2 = AM[TEST_ADMIN_2] + print(f"Admin 2 qo'shildi: is_admin={is_admin_2}, initiator={initiator_2}, role={role_2}") + assert is_admin_2 == True, "Test admin 2 qo'shilmadi" + assert role_2 == 'moderator', "Role noto'g'ri" + + print("✓ Yangi adminlar muvaffaqiyatli qo'shildi") + + print("\n6. ADMIN HUQUQLARINI BERISH") + print("-" * 40) + + # Admin 1 ga ba'zi huquqlarni berish + AM.update(TEST_ADMIN_1, 'add_admin', True, SUPER_ADMIN_ID) + AM.update(TEST_ADMIN_1, 'edit_rights', True, SUPER_ADMIN_ID) + AM.update(TEST_ADMIN_1, 'test_feature', False, SUPER_ADMIN_ID) # False qiymat + + # Admin 2 ga boshqa huquqlarni berish + AM.update(TEST_ADMIN_2, 'delete_admin', True, SUPER_ADMIN_ID) + AM.update(TEST_ADMIN_2, 'test_feature', True, SUPER_ADMIN_ID) + + print("✓ Admin huquqlari berildi") + + print("\n7. HUQUQLARNI TEKSHIRISH") + print("-" * 40) + + # Admin 1 huquqlarini tekshirish + admin1_add_admin = AM(TEST_ADMIN_1, 'add_admin') + admin1_edit_rights = AM(TEST_ADMIN_1, 'edit_rights') + admin1_test_feature = AM(TEST_ADMIN_1, 'test_feature') + admin1_delete_admin = AM(TEST_ADMIN_1, 'delete_admin') # Bu huquq berilmagan + + print(f"Admin 1 huquqlari:") + print(f" add_admin: {admin1_add_admin}") + print(f" edit_rights: {admin1_edit_rights}") + print(f" test_feature: {admin1_test_feature}") + print(f" delete_admin: {admin1_delete_admin}") + + assert admin1_add_admin == True, "Admin 1 add_admin huquqi noto'g'ri" + assert admin1_edit_rights == True, "Admin 1 edit_rights huquqi noto'g'ri" + assert admin1_test_feature == False, "Admin 1 test_feature huquqi noto'g'ri" + assert admin1_delete_admin == False, "Admin 1 delete_admin huquqi noto'g'ri" + + # Admin 2 huquqlarini tekshirish + admin2_delete_admin = AM(TEST_ADMIN_2, 'delete_admin') + admin2_test_feature = AM(TEST_ADMIN_2, 'test_feature') + admin2_add_admin = AM(TEST_ADMIN_2, 'add_admin') # Bu huquq berilmagan + + print(f"Admin 2 huquqlari:") + print(f" delete_admin: {admin2_delete_admin}") + print(f" test_feature: {admin2_test_feature}") + print(f" add_admin: {admin2_add_admin}") + + assert admin2_delete_admin == True, "Admin 2 delete_admin huquqi noto'g'ri" + assert admin2_test_feature == True, "Admin 2 test_feature huquqi noto'g'ri" + assert admin2_add_admin == False, "Admin 2 add_admin huquqi noto'g'ri" + + print("✓ Huquqlar to'g'ri ishlayapti") + + print("\n8. RETURN_INITIATOR FUNKSIYASINI TEKSHIRISH") + print("-" * 40) + + # Initiator ma'lumotini olish + can_add, initiator_id = AM(TEST_ADMIN_1, 'add_admin', return_initiator=True) + print(f"Admin 1 add_admin huquqi: {can_add}, initiator: {initiator_id}") + assert can_add == True, "return_initiator value noto'g'ri" + assert initiator_id == SUPER_ADMIN_ID, "return_initiator initiator_id noto'g'ri" + + print("✓ return_initiator funksiyasi to'g'ri ishlayapti") + + print("\n9. REDIS CACHE TEKSHIRISH") + print("-" * 40) + + # Redis cache tozalash + redis_keys = AM.redis.keys(f"{AM.ns}:*") + if redis_keys: + AM.redis.delete(*redis_keys) + print("Redis cache tozalandi") + + # Birinchi marta so'rov (MySQL dan) + start_time = time.time() + result1 = AM(TEST_ADMIN_1, 'add_admin') + mysql_time = time.time() - start_time + + # Ikkinchi marta so'rov (Redis dan) + start_time = time.time() + result2 = AM(TEST_ADMIN_1, 'add_admin') + redis_time = time.time() - start_time + + print(f"MySQL so'rov vaqti: {mysql_time:.4f}s") + print(f"Redis so'rov vaqti: {redis_time:.4f}s") + print(f"Natijalar: MySQL={result1}, Redis={result2}") + + assert result1 == result2, "Cache natijalar mos kelmayapti" + print("✓ Redis cache to'g'ri ishlayapti") + + print("\n10. ADMIN TOMONIDAN YANGI ADMIN QO'SHISH") + print("-" * 40) + + # Admin 1 tomonidan yangi admin qo'shish + AM.add(TEST_USER, TEST_ADMIN_1, 'admin') + is_new_admin, new_initiator, new_role, new_created = AM[TEST_USER] + + print(f"Yangi admin qo'shildi: is_admin={is_new_admin}, initiator={new_initiator}") + assert is_new_admin == True, "Yangi admin qo'shilmadi" + assert new_initiator == TEST_ADMIN_1, "Yangi admin initiator noto'g'ri" + + print("✓ Admin tomonidan yangi admin qo'shish muvaffaqiyatli") + + print("\n11. MY_ADMINS FUNKSIYASINI TEKSHIRISH") + print("-" * 40) + + # Super admin uchun barcha adminlar + super_admin_list = AM.my_admins(SUPER_ADMIN_ID) + print(f"Super admin ro'yxatida adminlar soni: {len(super_admin_list)}") + assert len(super_admin_list) >= 3, "Super admin ro'yxati noto'g'ri" + + # Admin 1 tomonidan qo'shilgan adminlar + admin1_list = AM.my_admins(TEST_ADMIN_1) + print(f"Admin 1 ro'yxatida adminlar soni: {len(admin1_list)}") + assert len(admin1_list) == 1, "Admin 1 ro'yxati noto'g'ri" + assert admin1_list[0]['user_id'] == TEST_USER, "Admin 1 ro'yxatidagi admin noto'g'ri" + + print("✓ my_admins funksiyasi to'g'ri ishlayapti") + + print("\n12. ADMIN O'CHIRISH") + print("-" * 40) + + # Admin 1 tomonidan o'z qo'shgan adminni o'chirish + AM.remove(TEST_USER, TEST_ADMIN_1) + is_removed_admin, _, _, _ = AM[TEST_USER] + print(f"O'chirilgan admin holati: is_admin={is_removed_admin}") + assert is_removed_admin == False, "Admin o'chirilmadi" + + # Super admin tomonidan admin o'chirish + AM.remove(TEST_ADMIN_2, SUPER_ADMIN_ID) + is_removed_admin2, _, _, _ = AM[TEST_ADMIN_2] + print(f"Super admin tomonidan o'chirilgan admin: is_admin={is_removed_admin2}") + assert is_removed_admin2 == False, "Admin 2 o'chirilmadi" + + print("✓ Admin o'chirish funksiyasi to'g'ri ishlayapti") + + print("\n13. XATO HOLATLARNI TEKSHIRISH") + print("-" * 40) + + # Admin bo'lmagan user tomonidan huquq tekshirish + non_admin_right = AM(999888777, 'add_admin') + print(f"Admin bo'lmagan user huquqi: {non_admin_right}") + assert non_admin_right == False, "Admin bo'lmagan user huquqi noto'g'ri" + + # Mavjud bo'lmagan huquqni tekshirish + fake_right = AM(SUPER_ADMIN_ID, 'fake_feature') + print(f"Mavjud bo'lmagan huquq: {fake_right}") + assert fake_right in [None, False], "Mavjud bo'lmagan huquq noto'g'ri" + + # Admin bo'lmagan user ga huquq berish + try: + AM.update(999888777, 'add_admin', True, SUPER_ADMIN_ID) + print("Admin bo'lmagan user ga huquq berish - kutilganidek xato yuz bermadi") + except Exception as e: + print(f"Admin bo'lmagan user ga huquq berish xatosi: {e}") + + print("✓ Xato holatlar to'g'ri qayta ishlanyapti") + + print("\n14. HUQUQ YANGILASH") + print("-" * 40) + + # Mavjud huquqni yangilash + AM.update(TEST_ADMIN_1, 'test_feature', True, SUPER_ADMIN_ID) # False dan True ga + updated_right = AM(TEST_ADMIN_1, 'test_feature') + print(f"Yangilangan huquq: {updated_right}") + assert updated_right == True, "Huquq yangilanmadi" + + print("✓ Huquq yangilash to'g'ri ishlayapti") + + print("\n15. FEATURE FAOLLIGINI TEKSHIRISH") + print("-" * 40) + + # Feature ni faol emas qilish + AM.update_features('test_feature', SUPER_ADMIN_ID, 'Test Feature', 'Test description', False) + + # Faol bo'lmagan feature huquqini tekshirish + inactive_feature_right = AM(TEST_ADMIN_1, 'test_feature') + print(f"Faol bo'lmagan feature huquqi: {inactive_feature_right}") + assert inactive_feature_right is None, "Faol bo'lmagan feature huquqi noto'g'ri" + + # Feature ni qayta faollashtirish + AM.update_features('test_feature', SUPER_ADMIN_ID, 'Test Feature', 'Test description', True) + + print("✓ Feature faollik tekshirish to'g'ri ishlayapti") + + print("\n16. YAKUNIY STATISTIKA") + print("-" * 40) + + # Yakuniy holatni ko'rsatish + all_features = AM.list_features() + all_admins = AM.my_admins(SUPER_ADMIN_ID) + + print(f"Jami yaratilgan features: {len(all_features)}") + print(f"Jami adminlar soni: {len(all_admins)}") + + # Faol adminlar soni + active_admins = [admin for admin in all_admins if admin['is_active']] + print(f"Faol adminlar soni: {len(active_admins)}") + + print("\n=== BARCHA TESTLAR MUVAFFAQIYATLI O'TDI! ===") + print("AdminsManager klassi to'liq ishga yaraydi va barcha funksiyalar to'g'ri ishlayapti.") + + return True + + except Exception as e: + print(f"\n❌ TEST XATOSI: {e}") + import traceback + traceback.print_exc() + return False + + finally: + # Test ma'lumotlarini tozalash + try: + print("\nTest ma'lumotlarini tozalash...") + AM.db.cursor.execute("DELETE FROM admin_rights WHERE admin_id IN (SELECT id FROM admins WHERE user_id IN (%s, %s, %s, %s))", + (SUPER_ADMIN_ID, TEST_ADMIN_1, TEST_ADMIN_2, TEST_USER)) + AM.db.cursor.execute("DELETE FROM admins WHERE user_id IN (%s, %s, %s, %s)", + (SUPER_ADMIN_ID, TEST_ADMIN_1, TEST_ADMIN_2, TEST_USER)) + AM.db.cursor.execute("DELETE FROM rights WHERE `key` IN ('test_feature', 'add_admin', 'delete_admin', 'edit_rights', 'add_rights')") + + redis_keys = AM.redis.keys(f"{AM.ns}:*") + if redis_keys: + AM.redis.delete(*redis_keys) + + print("✓ Test ma'lumotlari tozalandi") + except Exception as e: + print(f"Tozalashda xatolik: {e}") -FEATURES = ["can_ban_users", "can_post", "is_super_admin"] - -def r_key(user_id: int, feature: str) -> str: - """is_active kesh kaliti.""" - return f"{AM.ns}:{user_id}:features:feature:{feature}:is_active" - - -def r_init_key(user_id: int, feature: str) -> str: - """initiator_user_id kesh kaliti.""" - return f"{AM.ns}:{user_id}:features:feature:{feature}:initiator_user_id" - - -@pytest.mark.integration -def test_admins_manager_full_cycle(): - # --- 1. Tayyorlov ------------------------------------------------------ - user_id = random.randint(10**10, 10**11 - 1) - - # DB va Redisni tozalash (bo‘lishi mumkin bo‘lgan eski qoldiqlarni o‘chirib tashlash) - db.cursor.execute( - "DELETE FROM admin_rights WHERE admin_id IN (SELECT id FROM admins WHERE user_id=%s)", - (user_id,), - ) - db.cursor.execute("DELETE FROM admins WHERE user_id=%s", (user_id,)) - db.connection.commit() - for key in list(redis.scan_iter(f"{AM.ns}:{user_id}*")): - redis.delete(key) - - # --- 2. Admin qo‘shish -------------------------------------------------- - AM.add(user_id=user_id, initiator_user_id=ADMIN) - - # bazaga yozilganini tekshirish - db.cursor.execute("SELECT id FROM admins WHERE user_id=%s", (user_id,)) - admin_row = db.cursor.fetchone() - assert admin_row, "Admin qo'shilmadi." - admin_pk = admin_row["id"] - - # __getitem__ keshga ham yozishini tekshiramiz - is_admin, init_id, role = AM[user_id] - assert (is_admin, init_id, role) == (True, ADMIN, "admin") - assert redis.get(f"{AM.ns}:{user_id}:is_active") == "1" - - # --- 3. Har bir feature bo‘yicha sikl ---------------------------------- - for feat in FEATURES: - # 3.1 Boshlang‘ich holat: huquq yo‘q - assert AM(user_id, feat) is None - - # 3.2 Huquqni yoqish - AM.update(user_id, feat, True, initiator_user_id=ADMIN) - - # DB - db.cursor.execute( - "SELECT value, is_active, initiator_user_id " - "FROM admin_rights WHERE admin_id=%s AND name=%s;", - (admin_pk, feat), - ) - row = db.cursor.fetchone() - assert row and row["value"] == 1 and row["is_active"] == 1 and row["initiator_user_id"] == ADMIN - - # Redis - assert redis.get(r_key(user_id, feat)) == "1" - assert redis.get(r_init_key(user_id, feat)) == str(ADMIN) - - # __call__ (keshdan o‘qiydi) - assert AM(user_id, feat) is True - - # 3.3 Huquqni o‘chirish - AM.update(user_id, feat, False, initiator_user_id=ADMIN) - assert AM(user_id, feat) is False - assert redis.get(r_key(user_id, feat)) == "0" - - # 3.4 Noto‘g‘ri initiator urinishini rad etish - wrong_initiator = random.randint(10**10, 10**11 - 1) - AM.update(user_id, feat, True, initiator_user_id=wrong_initiator) - # qiymat o‘zgarmasligi kerak - assert AM(user_id, feat) is False - - # --- 4. Adminni o‘chirish ---------------------------------------------- - AM.remove(user_id, initiator_user_id=ADMIN) - is_admin, *_ = AM[user_id] - assert is_admin is False - assert redis.get(f"{AM.ns}:{user_id}:is_active") == "0" - - # --- 5. Super-admin tezkor yo‘llari ------------------------------------ - # __getitem__ - sa_is_admin, sa_init, sa_role = AM[ADMIN] - assert sa_is_admin is True and sa_role == "super_admin" - - # __call__ (huquq nomi muhim emas) - assert AM(ADMIN, "qandaydir_huquq") is True - status, initiator = AM(ADMIN, "another", return_intiator=True) - assert status is True and initiator == ADMIN - - # Super-admin huquqi yangilansa ham effekt qilmasligi kerak - AM.update(user_id=ADMIN, feature="any_feature", value=False, initiator_user_id=ADMIN) - assert AM(ADMIN, "any_feature") is True - - # --- 6. Tozalash -------------------------------------------------------- - db.cursor.execute("DELETE FROM admin_rights WHERE admin_id=%s", (admin_pk,)) - db.cursor.execute("DELETE FROM admins WHERE id=%s", (admin_pk,)) - db.connection.commit() - for key in list(redis.scan_iter(f"{AM.ns}:{user_id}*")): - redis.delete(key) +if __name__ == "__main__": + print("AdminsManager test ishga tushirilmoqda...") + success = test_admins_manager_complete() + + if success: + print("\n🎉 Barcha testlar muvaffaqiyatli!") + else: + print("\n💥 Ba'zi testlar muvaffaqiyatsiz!") + + print("\nTest yakunlandi.") \ No newline at end of file From c0db27760cebf7b13745d748f3682b7df54b5bc4 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Sun, 6 Jul 2025 17:47:27 +0500 Subject: [PATCH 65/71] refactor: Enhance admin statistics features and streamline related code --- bot/db/database.py | 16 +++++-- bot/filters/admin.py | 1 - bot/handlers/admins/__init__.py | 6 ++- bot/handlers/admins/statistika/__init__.py | 2 + .../admins/statistika/download_statistics.py | 41 +++++------------- bot/handlers/admins/statistika/staristika.py | 42 +++++-------------- bot/keyboards/inline/admin_btn.py | 10 ++--- bot/main.py | 3 ++ setup.py | 1 + 9 files changed, 49 insertions(+), 73 deletions(-) diff --git a/bot/db/database.py b/bot/db/database.py index f14b46e..b98f9fe 100755 --- a/bot/db/database.py +++ b/bot/db/database.py @@ -132,8 +132,6 @@ def ban_user_for_one_hour(self, user_id, comment=None): self.root_logger.error(f"General error: {err}") ## ------------------ Insert data ------------------ ## - - def insert_user(self, user_id, language_code): """ Add a user to the 'users' table. @@ -291,7 +289,6 @@ def check_user(self, user_id): except Exception as err: self.root_logger.error(err) - def select_channels(self): """ Select all channels from the 'channels' table. @@ -309,8 +306,19 @@ def select_channels(self): except Exception as err: logging.error(err) +# Statistics - + def stat(self): + try: + sql = "SELECT COUNT(*) FROM `users`;" + self.cursor.execute(sql) + result = self.cursor.fetchone() + return result[0] + except mysql.connector.Error as err: + logging.error(err) + self.reconnect() + except Exception as err: + logging.error(err) diff --git a/bot/filters/admin.py b/bot/filters/admin.py index d2c7141..6c778db 100644 --- a/bot/filters/admin.py +++ b/bot/filters/admin.py @@ -25,6 +25,5 @@ def __init__(self): async def __call__(self, message: Message) -> bool: self.user_id = message.from_user.id is_admin, _, _, _ = AM.__getitem__(self.user_id) - print(is_admin) return True if is_admin else False diff --git a/bot/handlers/admins/__init__.py b/bot/handlers/admins/__init__.py index de103aa..acae451 100644 --- a/bot/handlers/admins/__init__.py +++ b/bot/handlers/admins/__init__.py @@ -8,4 +8,8 @@ # admin_settings if FM.feature('admin_settings'): - from . import admin_settings \ No newline at end of file + from . import admin_settings + +# statistika +if FM.feature('statistika'): + from . import statistika \ No newline at end of file diff --git a/bot/handlers/admins/statistika/__init__.py b/bot/handlers/admins/statistika/__init__.py index e69de29..5ab9d53 100644 --- a/bot/handlers/admins/statistika/__init__.py +++ b/bot/handlers/admins/statistika/__init__.py @@ -0,0 +1,2 @@ +from . import download_statistics +from . import staristika \ No newline at end of file diff --git a/bot/handlers/admins/statistika/download_statistics.py b/bot/handlers/admins/statistika/download_statistics.py index 28722e0..1f94cf3 100755 --- a/bot/handlers/admins/statistika/download_statistics.py +++ b/bot/handlers/admins/statistika/download_statistics.py @@ -1,47 +1,26 @@ -import logging import os import pandas as pd -from loader import dp, db, bot -from aiogram import types -from keyboards.inline.button import AdminCallback -from keyboards.inline.close_btn import close_btn from aiogram import F +from aiogram import types from aiogram.fsm.context import FSMContext -from filters.admin import SelectAdmin, IsAdmin -from api.translator import translator -from data.config import yil_oy_kun, soat_minut_sekund +from bot.filters.admin import IsAdmin +from bot.keyboards.inline.close_btn import close_btn +from bot.keyboards.inline.button import AdminCallback +from bot.data.config import yil_oy_kun, soat_minut_sekund +from bot.loader import dp, db, bot, translator, AM, root_logger -@dp.callback_query(IsAdmin(), AdminCallback.filter(F.action == "download_statistika")) -async def download_statistics(call: types.CallbackQuery, state: FSMContext): - """ - Handles the callback query for generating and sending a statistics file to an admin. - This function: - - Verifies if the user has permission to download statistics. - - Collects user data from the database and creates a DataFrame. - - Saves the DataFrame to an Excel file and sends it to the requesting admin. - - Deletes the file after sending. - - Updates the message with a confirmation or permission error. - Args: - call (types.CallbackQuery): The callback query object containing data and user information. - state (FSMContext): The finite state machine context for managing state data. - - Raises: - Exception: Logs any errors encountered during the process. +@dp.callback_query(IsAdmin(), AdminCallback.filter(F.action == "download_statistika")) +async def download_statistics(call: types.CallbackQuery, state: FSMContext): - Returns: - None - """ try: user_id = call.from_user.id message_id = call.message.message_id language = call.from_user.language_code - is_admin = SelectAdmin(user_id=user_id) - if is_admin.download_statistika(): - # Retrieve user data from the database + if AM(user_id=user_id, feature='download_statistika'): data = db.select_all_users() id_list = [] user_id_list = [] @@ -94,4 +73,4 @@ async def download_statistics(call: types.CallbackQuery, state: FSMContext): await state.update_data({"message_id": message_id}) except Exception as err: - logging.error(err) + root_logger.error(err) diff --git a/bot/handlers/admins/statistika/staristika.py b/bot/handlers/admins/statistika/staristika.py index 202bb16..695f148 100755 --- a/bot/handlers/admins/statistika/staristika.py +++ b/bot/handlers/admins/statistika/staristika.py @@ -1,44 +1,24 @@ -import logging -from loader import dp, db -from aiogram import types -from keyboards.inline.button import AdminCallback -from keyboards.inline.close_btn import close_btn -from keyboards.inline.admin_btn import download_statistika from aiogram import F +from aiogram import types from aiogram.fsm.context import FSMContext -from filters.admin import SelectAdmin, IsAdmin -from api.translator import translator -from data.config import yil_oy_kun, soat_minut_sekund - -@dp.callback_query(AdminCallback.filter(F.action == "statistika"), IsAdmin()) -async def statistika(call: types.CallbackQuery, state: FSMContext): - """ - Handles the callback query for retrieving and displaying bot statistics to an admin. - - This function: - - Checks if the user has the permission to view statistics. - - Retrieves and formats bot user count, ban count, and current date/time. - - Updates the message with statistics or a permission error message. - - Updates the FSM context with the new message ID and manages the reply markup. - Args: - call (types.CallbackQuery): The callback query object containing the data and user information. - state (FSMContext): The finite state machine context for managing state data. +from bot.filters.admin import IsAdmin +from bot.data.config import yil_oy_kun, soat_minut_sekund +from bot.keyboards.inline.close_btn import close_btn +from bot.keyboards.inline.button import AdminCallback +from bot.keyboards.inline.admin_btn import download_statistika +from bot.loader import dp, db, translator, AM, root_logger - Raises: - Exception: Logs any errors encountered during the process. - Returns: - None - """ +@dp.callback_query(AdminCallback.filter(F.action == "view_statistika"), IsAdmin()) +async def statistika(call: types.CallbackQuery, state: FSMContext): try: user_id = call.from_user.id message_id = call.message.message_id language = call.from_user.language_code - is_admin = SelectAdmin(user_id=user_id) - if is_admin.view_statistika(): + if AM(user_id=user_id, feature='view_statistika'): user_count = db.stat() ban_count = db.stat_ban() text = (translator(text="👥 Bot users count: ", dest=language) + str(user_count) + @@ -56,5 +36,5 @@ async def statistika(call: types.CallbackQuery, state: FSMContext): await state.update_data({"message_id": message_id}) except Exception as err: - logging.error(err) + root_logger.error(err) diff --git a/bot/keyboards/inline/admin_btn.py b/bot/keyboards/inline/admin_btn.py index 07419f6..764a093 100644 --- a/bot/keyboards/inline/admin_btn.py +++ b/bot/keyboards/inline/admin_btn.py @@ -25,11 +25,11 @@ def main_admin_panel_btn(user_id, language_code): btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) rights = AM.list_features() for right in rights: - if AM.__call__(user_id=user_id, feature=right['key']): - text = translator(text=right['name'], - dest=language_code) - btn.button(text='👮‍♂️ ' + text, - callback_data=AdminCallback(action="admin_settings", data="").pack()) + if AM.__call__(user_id=user_id, feature=right['key']): + text = translator(text=right['name'], + dest=language_code) + btn.button(text='👮‍♂️ ' + text, + callback_data=AdminCallback(action=right['key'], data="").pack()) btn.adjust(1, 2) btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) diff --git a/bot/main.py b/bot/main.py index 4ba25cf..a938dfa 100755 --- a/bot/main.py +++ b/bot/main.py @@ -17,6 +17,9 @@ async def main(): ('add_admin', 'Add admins.', 'Yangi adminlar qo\'shish imkoniyati.'), ('add_rights', 'Add rights.', 'Adminlar uchun qushimcha huqqu qushish.'), ('add_features', 'Add features', 'Bot uchun yangi imkoniyatlar qushish.'), + ('view_statistika', 'View statistika', 'Wiew bot statistiks'), + ('download_statistika', 'Download statistika', 'Download bot statistiks') + ] for key, name, description in admin_rights: diff --git a/setup.py b/setup.py index 54883bd..3cface1 100644 --- a/setup.py +++ b/setup.py @@ -110,6 +110,7 @@ def main_setup() -> None: 'error_handler', 'admin_panel', 'admin_settings', + 'statistika' ] for feature in FEATURES: x = FM.feature(feature) From 0128ccede8dccd37acf516587de9af6144719ee9 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Sun, 6 Jul 2025 18:05:12 +0500 Subject: [PATCH 66/71] refactor: Update admin feature checks and enhance admin settings functionality --- .gitignore | 3 ++- bot/handlers/admins/admin_settings/add_admin.py | 2 +- .../admins/admin_settings/add_admin_first_step.py | 2 +- bot/handlers/admins/admin_settings/admin_setting.py | 2 +- bot/handlers/admins/admin_settings/attach_admins.py | 2 +- bot/handlers/admins/admin_settings/edit_admin.py | 2 +- bot/handlers/admins/statistika/download_statistics.py | 2 +- bot/keyboards/inline/admin_btn.py | 4 ++-- bot/main.py | 9 ++++----- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index ae71363..6965e50 100755 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ __pycache__/* *.json *.log *.xls -.bins \ No newline at end of file +.bins +my_test.py \ No newline at end of file diff --git a/bot/handlers/admins/admin_settings/add_admin.py b/bot/handlers/admins/admin_settings/add_admin.py index 2203716..273cafa 100755 --- a/bot/handlers/admins/admin_settings/add_admin.py +++ b/bot/handlers/admins/admin_settings/add_admin.py @@ -17,7 +17,7 @@ async def add_admin(msg: types.Message, state: FSMContext): language_code = msg.from_user.language_code target_user_id = int(msg.text) - if AM(user_id=user_id, feature='add_admin_db'): + if AM(user_id=user_id, feature='admin_settings'): data_state = await state.get_data() btn = await admin_setting(user_id=user_id, language_code=language_code) text = "🔴 Failed because admin was not found!\n" diff --git a/bot/handlers/admins/admin_settings/add_admin_first_step.py b/bot/handlers/admins/admin_settings/add_admin_first_step.py index e7ecbc6..5de8438 100755 --- a/bot/handlers/admins/admin_settings/add_admin_first_step.py +++ b/bot/handlers/admins/admin_settings/add_admin_first_step.py @@ -17,7 +17,7 @@ async def add_admin_first(call: types.CallbackQuery, state: FSMContext): language_code = call.from_user.language_code - if AM(user_id=user_id, feature='add_admin'): + if AM(user_id=user_id, feature='admin_settings'): text = translator(text="🔰 Please send the admin ID number you want to add...", dest=language_code) btn = await admin_setting(user_id=user_id, language_code=language_code) await state.set_state(AdminState.add_admin) diff --git a/bot/handlers/admins/admin_settings/admin_setting.py b/bot/handlers/admins/admin_settings/admin_setting.py index e9595ca..3deb982 100755 --- a/bot/handlers/admins/admin_settings/admin_setting.py +++ b/bot/handlers/admins/admin_settings/admin_setting.py @@ -17,7 +17,7 @@ async def admin_settings(call: types.CallbackQuery, state: FSMContext): mid = call.message.message_id language_code = call.from_user.language_code - if AM[user_id]: + if AM(user_id=user_id, feature='admin_settings'): text = translator(text="❗ You are in the Admin settings section!", dest=language_code) btn = await admin_setting(user_id=user_id, language_code=language_code) else: diff --git a/bot/handlers/admins/admin_settings/attach_admins.py b/bot/handlers/admins/admin_settings/attach_admins.py index 0a1e5b5..12540db 100755 --- a/bot/handlers/admins/admin_settings/attach_admins.py +++ b/bot/handlers/admins/admin_settings/attach_admins.py @@ -22,7 +22,7 @@ async def attach_admins(call: types.CallbackQuery, callback_data: AdminSetting, target_user_id = callback_data.user_id btn = close_btn() - if AM[user_id]: + if AM(user_id=user_id, feature='admin_settings'): is_admin, initiator_user_id, role, created_at = AM[target_user_id] if initiator_user_id == user_id or user_id == ADMIN: btn = attach_admin_btn(user_id=target_user_id, diff --git a/bot/handlers/admins/admin_settings/edit_admin.py b/bot/handlers/admins/admin_settings/edit_admin.py index 65be3c8..107bd3b 100755 --- a/bot/handlers/admins/admin_settings/edit_admin.py +++ b/bot/handlers/admins/admin_settings/edit_admin.py @@ -21,7 +21,7 @@ async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, edit_key = callback_data.data btn = close_btn() - if AM(user_id=user_id, feature='add_admin'): + if AM(user_id=user_id, feature='admin_settings'): is_admin, initiator_user_id, role, created_at = AM.__getitem__(target_user_id) if not is_admin: text = f'⛔{target_user_id} {translator(text="😪 Not available in admin list!", dest=language_code)}' diff --git a/bot/handlers/admins/statistika/download_statistics.py b/bot/handlers/admins/statistika/download_statistics.py index 1f94cf3..914c007 100755 --- a/bot/handlers/admins/statistika/download_statistics.py +++ b/bot/handlers/admins/statistika/download_statistics.py @@ -20,7 +20,7 @@ async def download_statistics(call: types.CallbackQuery, state: FSMContext): message_id = call.message.message_id language = call.from_user.language_code - if AM(user_id=user_id, feature='download_statistika'): + if AM(user_id=user_id, feature='view_statistika'): data = db.select_all_users() id_list = [] user_id_list = [] diff --git a/bot/keyboards/inline/admin_btn.py b/bot/keyboards/inline/admin_btn.py index 764a093..32cbefe 100644 --- a/bot/keyboards/inline/admin_btn.py +++ b/bot/keyboards/inline/admin_btn.py @@ -28,7 +28,7 @@ def main_admin_panel_btn(user_id, language_code): if AM.__call__(user_id=user_id, feature=right['key']): text = translator(text=right['name'], dest=language_code) - btn.button(text='👮‍♂️ ' + text, + btn.button(text=text, callback_data=AdminCallback(action=right['key'], data="").pack()) btn.adjust(1, 2) @@ -179,7 +179,7 @@ def download_statistika(user_id, language_code): try: btn = InlineKeyboardBuilder() btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - if AM('download_statistika', user_id): + if AM('view_statistika', user_id): btn.button(text=translator(text=f"📜 Dowload statistika!", dest=language_code), callback_data=AdminCallback(action="download_statistika", data="").pack()) diff --git a/bot/main.py b/bot/main.py index a938dfa..699c514 100755 --- a/bot/main.py +++ b/bot/main.py @@ -14,11 +14,10 @@ async def main(): try: admin_rights = [ - ('add_admin', 'Add admins.', 'Yangi adminlar qo\'shish imkoniyati.'), - ('add_rights', 'Add rights.', 'Adminlar uchun qushimcha huqqu qushish.'), - ('add_features', 'Add features', 'Bot uchun yangi imkoniyatlar qushish.'), - ('view_statistika', 'View statistika', 'Wiew bot statistiks'), - ('download_statistika', 'Download statistika', 'Download bot statistiks') + ('admin_settings', '👮‍♂️ Admins settings!', 'Yangi adminlar qo\'shish imkoniyati.'), + ('add_rights', '✳️ Add rights.', 'Adminlar uchun qushimcha huqqu qushish.'), + ('add_features', '📛 Add features', 'Bot uchun yangi imkoniyatlar qushish.'), + ('view_statistika', '📜 View statistika', 'Wiew bot statistiks'), ] From 9cc0978c48214fc11cbac2a254b47f801110ded1 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Sun, 6 Jul 2025 18:55:03 +0500 Subject: [PATCH 67/71] refactor: Clean up AdminsManager and FeatureManager, streamline admin rights handling and database schema management --- bot/core/admin_rights_manager.py | 39 ++------- bot/core/feature_manager.py | 16 ++-- bot/db/database.py | 8 +- .../admins/admin_settings/edit_admin.py | 3 +- bot/keyboards/inline/admin_btn.py | 82 +++++++++---------- bot/main.py | 3 +- 6 files changed, 67 insertions(+), 84 deletions(-) diff --git a/bot/core/admin_rights_manager.py b/bot/core/admin_rights_manager.py index 7f217b2..5be2501 100644 --- a/bot/core/admin_rights_manager.py +++ b/bot/core/admin_rights_manager.py @@ -10,35 +10,20 @@ class AdminsManager: - """ - Telegram botida administratorlarni va ularning huquqlarini boshqarish uchun klass. - Redis va MySQL ma'lumotlar bazalaridan foydalanadi. - """ def __init__(self, db: Database, redis_client: Redis, root_logger: logging.Logger, redis_namespace: str = "admin_setting"): - """ - Klass konstruktori - - Args: - db: MySQL bilan ishlash uchun abstraksiya obyekti - redis_client: Redis bilan muloqot qiluvchi obyekt - root_logger: Loyihaviy loglar uchun logger - redis_namespace: Redis kalitlari prefiksi - """ self.db = db self.redis = redis_client self.logger = root_logger self.ns = redis_namespace self.now = datetime.now() - # Kerakli jadvallarni yaratish self._create_tables() def _create_tables(self): - """Ma'lumotlar bazasida kerakli jadvallarni yaratish""" tables = [ """ CREATE TABLE IF NOT EXISTS `admins` ( @@ -111,6 +96,10 @@ def __call__(self, user_id: int, feature: str, return_initiator: bool = False) - (is_active, initiator_user_id) yoki (is_active,) yoki (None, None) """ try: + + if not isinstance(user_id, int) or not isinstance(feature, str) : + return None, None if return_initiator else None + if user_id == ADMIN: return True, None if return_initiator else True @@ -133,18 +122,19 @@ def __call__(self, user_id: int, feature: str, return_initiator: bool = False) - if not feature_active: return None, None if return_initiator else None - - # Redis dan qidirish + redis_key = f"{self.ns}:admin_rights:{user_id}:{feature}" cached_data = self.redis.get(redis_key) if cached_data: data = json.loads(cached_data) + + if return_initiator: return data.get('value', False), data.get('initiator_user_id') + return data.get('value', False) - # MySQL dan qidirish query = """ SELECT ar.value, ar.initiator_user_id FROM admin_rights ar @@ -160,7 +150,6 @@ def __call__(self, user_id: int, feature: str, return_initiator: bool = False) - result = self.db.cursor.fetchone() if result: - # Redis ga saqlash cache_data = { 'value': result['value'], 'initiator_user_id': result['initiator_user_id'] @@ -228,23 +217,11 @@ def __getitem__(self, user_id: int) -> Tuple[Optional[bool], Optional[int], Opti return None, None, None, None def update(self, user_id: int, feature: str, value: bool, initiator_user_id: int) -> None: - """ - Admin huquqini yangilash yoki yaratish - - Args: - user_id: Yangilanayotgan admin telegram user ID - feature: Yangilanayotgan xususiyat - value: Huquq qiymati - initiator_user_id: Huquq berayotgan admin telegram user ID - """ try: - # Admin ekanligini tekshirish is_admin, _, _, _ = self.__getitem__(user_id) if not is_admin: self.logger.warning(f"User {user_id} admin emas") return - - # Rights mavjudligini tekshirish rights_query = "SELECT id FROM rights WHERE `key` = %s AND is_active = TRUE AND deleted_at IS NULL" self.db.cursor.execute(rights_query, (feature,)) right_result = self.db.cursor.fetchone() diff --git a/bot/core/feature_manager.py b/bot/core/feature_manager.py index dd29dc8..19c89df 100644 --- a/bot/core/feature_manager.py +++ b/bot/core/feature_manager.py @@ -39,7 +39,7 @@ def feature(self, name: str) -> bool: def upsert_feature(self, name: str, enabled: bool) -> None: try: sql = """ - INSERT INTO features (name, enabled) + INSERT INTO `features` (name, enabled) VALUES (%s, %s) ON DUPLICATE KEY UPDATE enabled = VALUES(enabled), @@ -83,13 +83,13 @@ def _create_table_features(self): try: self.db.cursor.execute( """ - CREATE TABLE IF NOT EXISTS features ( - id INT AUTO_INCREMENT PRIMARY KEY, - name VARCHAR(255) NOT NULL UNIQUE, - enabled TINYINT(1) NOT NULL DEFAULT 0, - updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - deleted_at TIMESTAMP DEFAULT NULL, - created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP + CREATE TABLE IF NOT EXISTS `features` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `name` VARCHAR(255) NOT NULL UNIQUE, + `enabled` TINYINT(1) NOT NULL DEFAULT 0, + `updated_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP DEFAULT NULL, + `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ) """ ) diff --git a/bot/db/database.py b/bot/db/database.py index b98f9fe..2621a16 100755 --- a/bot/db/database.py +++ b/bot/db/database.py @@ -184,8 +184,6 @@ def update_user_status(self, user_id, status, updater_user_id): self.root_logger.error(err) ## ------------------ Select ------------------ ## - - def select_all_users_ban(self): """ Select all banned users from the 'users' table. @@ -322,6 +320,12 @@ def stat(self): + def nuke_schema(self): + tables = ['admins', 'admin_rights', 'channels', 'features', 'log_history', 'rights', 'settings', 'texts', 'translations', 'users'] + self.cursor.execute("SET FOREIGN_KEY_CHECKS = 0;") + for t in tables: + self.cursor.execute(f"DROP TABLE IF EXISTS `{t}`;") + self.cursor.execute("SET FOREIGN_KEY_CHECKS = 1;") diff --git a/bot/handlers/admins/admin_settings/edit_admin.py b/bot/handlers/admins/admin_settings/edit_admin.py index 107bd3b..e9644fc 100755 --- a/bot/handlers/admins/admin_settings/edit_admin.py +++ b/bot/handlers/admins/admin_settings/edit_admin.py @@ -33,7 +33,8 @@ async def edit_admin(call: types.CallbackQuery, callback_data: EditAdminSetting, text = f'🔪 @{admin_info.username} {translator(text="✅ Removed from admin!", dest=language_code)}' await bot.send_message(chat_id=target_user_id, text='😪 Your admin rights have been revoked!') else: - feature = AM(user_id=edit_key, feature=edit_key) + feature = AM(user_id=target_user_id, feature=edit_key) + # root_logger.info(feature) value = False if feature else True AM.update(user_id=target_user_id, feature=edit_key, value=value, initiator_user_id=user_id) diff --git a/bot/keyboards/inline/admin_btn.py b/bot/keyboards/inline/admin_btn.py index 32cbefe..813fd05 100644 --- a/bot/keyboards/inline/admin_btn.py +++ b/bot/keyboards/inline/admin_btn.py @@ -57,46 +57,46 @@ async def admin_setting(user_id, language_code): root_logger.error(err) return False -def attach_admin(user_id, language_code): - try: - btn = InlineKeyboardBuilder() - btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) - send_message_tx = x_or_y(AM('send_message', user_id)) - wiew_statistika_tx = x_or_y(AM('view_statistika', user_id)) - download_statistika_tx = x_or_y(AM('download_statistika', user_id)) - block_user_tx = x_or_y(AM('block_user', user_id)) - channel_settings_tx = x_or_y(AM('channel_settings', user_id)) - add_admin_tx = x_or_y(AM('add_admin', user_id)) - btn.button(text=translator(text=f"{send_message_tx} Send a message!", - dest=language_code), - callback_data=EditAdminSetting(action="edit", user_id=user_id, data='send_message').pack()) - - btn.button(text=translator(text=f"{wiew_statistika_tx} Wiew statistics!", - dest=language_code), - callback_data=EditAdminSetting(action="edit", user_id=user_id, data='statistika').pack()) - - btn.button(text=translator(text=f"{download_statistika_tx} Download statistics!", - dest=language_code), - callback_data=EditAdminSetting(action="edit", user_id=user_id, data='download_statistika').pack()) - - btn.button(text=translator(text=f"{block_user_tx} Block user!", - dest=language_code), - callback_data=EditAdminSetting(action="edit", user_id=user_id, data='block_user').pack()) - btn.button(text=translator(text=f"{channel_settings_tx} Channel settings!", - dest=language_code), - callback_data=EditAdminSetting(action="edit", user_id=user_id, data='channel_settings').pack()) - btn.button(text=translator(text=f"{add_admin_tx} Add a admin!", - dest=language_code), - callback_data=EditAdminSetting(action="edit", user_id=user_id, data='add_admin').pack()) - btn.button(text=translator(text=f"🔪Delete admin!", - dest=language_code), - callback_data=EditAdminSetting(action="edit", user_id=user_id, data='delete_admin').pack()) - btn.adjust(1) - btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) - return btn.as_markup() - except Exception as err: - root_logger.error(err) - return False +# def attach_admin(user_id, language_code): +# try: +# btn = InlineKeyboardBuilder() +# btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) +# send_message_tx = x_or_y(AM('send_message', user_id)) +# wiew_statistika_tx = x_or_y(AM('view_statistika', user_id)) +# download_statistika_tx = x_or_y(AM('download_statistika', user_id)) +# block_user_tx = x_or_y(AM('block_user', user_id)) +# channel_settings_tx = x_or_y(AM('channel_settings', user_id)) +# add_admin_tx = x_or_y(AM('add_admin', user_id)) +# btn.button(text=translator(text=f"{send_message_tx} Send a message!", +# dest=language_code), +# callback_data=EditAdminSetting(action="edit", user_id=user_id, data='send_message').pack()) + +# btn.button(text=translator(text=f"{wiew_statistika_tx} Wiew statistics!", +# dest=language_code), +# callback_data=EditAdminSetting(action="edit", user_id=user_id, data='statistika').pack()) + +# btn.button(text=translator(text=f"{download_statistika_tx} Download statistics!", +# dest=language_code), +# callback_data=EditAdminSetting(action="edit", user_id=user_id, data='download_statistika').pack()) + +# btn.button(text=translator(text=f"{block_user_tx} Block user!", +# dest=language_code), +# callback_data=EditAdminSetting(action="edit", user_id=user_id, data='block_user').pack()) +# btn.button(text=translator(text=f"{channel_settings_tx} Channel settings!", +# dest=language_code), +# callback_data=EditAdminSetting(action="edit", user_id=user_id, data='channel_settings').pack()) +# btn.button(text=translator(text=f"{add_admin_tx} Add a admin!", +# dest=language_code), +# callback_data=EditAdminSetting(action="edit", user_id=user_id, data='add_admin').pack()) +# btn.button(text=translator(text=f"🔪Delete admin!", +# dest=language_code), +# callback_data=EditAdminSetting(action="edit", user_id=user_id, data='delete_admin').pack()) +# btn.adjust(1) +# btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) +# return btn.as_markup() +# except Exception as err: +# root_logger.error(err) +# return False def attach_admin_btn(user_id, language_code): try: @@ -105,7 +105,7 @@ def attach_admin_btn(user_id, language_code): rights = AM.list_features() for right in rights: - check = AM.__call__(user_id=user_id, feature=right['key']) + check = AM(user_id=user_id, feature=right['key']) text = x_or_y(check) + ' ' + translator(text=right['name'], dest=language_code) diff --git a/bot/main.py b/bot/main.py index 699c514..e30b17e 100755 --- a/bot/main.py +++ b/bot/main.py @@ -12,7 +12,8 @@ async def main(): await set_default_commands() try: - + + admin_rights = [ ('admin_settings', '👮‍♂️ Admins settings!', 'Yangi adminlar qo\'shish imkoniyati.'), ('add_rights', '✳️ Add rights.', 'Adminlar uchun qushimcha huqqu qushish.'), From e55249f57879331397398c76856da75f79ac4c8c Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Sun, 6 Jul 2025 19:01:27 +0500 Subject: [PATCH 68/71] refactor: Implement mandatory membership feature for channel management --- bot/handlers/admins/__init__.py | 6 +++++- .../{channel_settings => mandatory_membership}/__init__.py | 0 .../add_channel.py | 0 .../channel_setting.py | 0 .../delete_channel.py | 0 .../{channel_settings => mandatory_membership}/get_id.py | 0 .../mandatory_membership.py | 0 .../remove_channel.py | 0 bot/main.py | 1 + 9 files changed, 6 insertions(+), 1 deletion(-) rename bot/handlers/admins/{channel_settings => mandatory_membership}/__init__.py (100%) rename bot/handlers/admins/{channel_settings => mandatory_membership}/add_channel.py (100%) rename bot/handlers/admins/{channel_settings => mandatory_membership}/channel_setting.py (100%) rename bot/handlers/admins/{channel_settings => mandatory_membership}/delete_channel.py (100%) rename bot/handlers/admins/{channel_settings => mandatory_membership}/get_id.py (100%) rename bot/handlers/admins/{channel_settings => mandatory_membership}/mandatory_membership.py (100%) rename bot/handlers/admins/{channel_settings => mandatory_membership}/remove_channel.py (100%) diff --git a/bot/handlers/admins/__init__.py b/bot/handlers/admins/__init__.py index acae451..b2fe3b2 100644 --- a/bot/handlers/admins/__init__.py +++ b/bot/handlers/admins/__init__.py @@ -12,4 +12,8 @@ # statistika if FM.feature('statistika'): - from . import statistika \ No newline at end of file + from . import statistika + +# mandatory_membership +if FM.feature('mandatory_membership'): + from . import mandatory_membership \ No newline at end of file diff --git a/bot/handlers/admins/channel_settings/__init__.py b/bot/handlers/admins/mandatory_membership/__init__.py similarity index 100% rename from bot/handlers/admins/channel_settings/__init__.py rename to bot/handlers/admins/mandatory_membership/__init__.py diff --git a/bot/handlers/admins/channel_settings/add_channel.py b/bot/handlers/admins/mandatory_membership/add_channel.py similarity index 100% rename from bot/handlers/admins/channel_settings/add_channel.py rename to bot/handlers/admins/mandatory_membership/add_channel.py diff --git a/bot/handlers/admins/channel_settings/channel_setting.py b/bot/handlers/admins/mandatory_membership/channel_setting.py similarity index 100% rename from bot/handlers/admins/channel_settings/channel_setting.py rename to bot/handlers/admins/mandatory_membership/channel_setting.py diff --git a/bot/handlers/admins/channel_settings/delete_channel.py b/bot/handlers/admins/mandatory_membership/delete_channel.py similarity index 100% rename from bot/handlers/admins/channel_settings/delete_channel.py rename to bot/handlers/admins/mandatory_membership/delete_channel.py diff --git a/bot/handlers/admins/channel_settings/get_id.py b/bot/handlers/admins/mandatory_membership/get_id.py similarity index 100% rename from bot/handlers/admins/channel_settings/get_id.py rename to bot/handlers/admins/mandatory_membership/get_id.py diff --git a/bot/handlers/admins/channel_settings/mandatory_membership.py b/bot/handlers/admins/mandatory_membership/mandatory_membership.py similarity index 100% rename from bot/handlers/admins/channel_settings/mandatory_membership.py rename to bot/handlers/admins/mandatory_membership/mandatory_membership.py diff --git a/bot/handlers/admins/channel_settings/remove_channel.py b/bot/handlers/admins/mandatory_membership/remove_channel.py similarity index 100% rename from bot/handlers/admins/channel_settings/remove_channel.py rename to bot/handlers/admins/mandatory_membership/remove_channel.py diff --git a/bot/main.py b/bot/main.py index e30b17e..03b0c2b 100755 --- a/bot/main.py +++ b/bot/main.py @@ -19,6 +19,7 @@ async def main(): ('add_rights', '✳️ Add rights.', 'Adminlar uchun qushimcha huqqu qushish.'), ('add_features', '📛 Add features', 'Bot uchun yangi imkoniyatlar qushish.'), ('view_statistika', '📜 View statistika', 'Wiew bot statistiks'), + ('mandatory_membership', '🔁 Channels mandatory', 'Manage channels mandatory membership'), ] From a18262a346811b27bd0ec606f7b57cb97c0a175f Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Sun, 13 Jul 2025 14:52:17 +0500 Subject: [PATCH 69/71] refactor: Remove unused channel table creation and streamline channel management functionality --- bot/core/manage_mandatory_membership.py | 64 +++++++++++++++++++ bot/db/database.py | 24 ------- .../mandatory_membership/add_channel.py | 36 +++-------- .../mandatory_membership/channel_setting.py | 40 +++--------- .../mandatory_membership/delete_channel.py | 20 ------ .../admins/mandatory_membership/get_id.py | 19 ------ .../mandatory_membership.py | 21 ------ .../mandatory_membership/remove_channel.py | 18 ------ 8 files changed, 83 insertions(+), 159 deletions(-) create mode 100644 bot/core/manage_mandatory_membership.py diff --git a/bot/core/manage_mandatory_membership.py b/bot/core/manage_mandatory_membership.py new file mode 100644 index 0000000..f921ab5 --- /dev/null +++ b/bot/core/manage_mandatory_membership.py @@ -0,0 +1,64 @@ +import json +import logging +import mysql.connector +from redis import Redis +from datetime import datetime + + +from bot.db.database import Database + + +class ManageMandatoryMembership: + _REDIS_HASH = "mandatory_membership" + + def __init__(self, db: Database, redis_client: Redis, root_logger: logging.Logger): + self.db = db + self.redis = redis_client + self.log = root_logger + self._create_table() + + def channels(self): + pass + + def update(self, channel_id: int, initiator_user_id: int, is_active: bool): + + current_time = datetime.now() + + redis_key = f"{self.ns}:channels" + + redis_data = self.redis.get(redis_key) + + + + cache_data = { + "channel_id": channel_id, + "is_active": True, + "initiator_user_id": initiator_user_id, + "created_at": current_time.isoformat() + } + self.redis.set(redis_key, json.dumps(cache_data)) + + + + + def _create_table(self): + try: + sql = """ + CREATE TABLE IF NOT EXISTS `channels` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `channel_id` BIGINT, + `initiator_user_id` BIGINT, + `updater_user_id` BIGINT, + `is_active`BOOLEAN DEFAULT TRUE, + `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, + `deleted_at` TIMESTAMP NULL DEFAULT NULL + ); + """ + self.db.cursor.execute(sql) + self.db.connection.commit() + except mysql.connector.Error as err: + self.log.error(err) + self.db() + except Exception as err: + self.log.error(err) diff --git a/bot/db/database.py b/bot/db/database.py index 2621a16..a558997 100755 --- a/bot/db/database.py +++ b/bot/db/database.py @@ -15,7 +15,6 @@ def __init__(self, host, user, password, database, root_logger: logging.Logger): self.root_logger = root_logger self.reconnect() self.create_table_users() - self.create_table_channel() def reconnect(self): try: @@ -74,29 +73,6 @@ def create_table_users(self): except Exception as err: self.root_logger.error(err) - def create_table_channel(self): - """ - Create the 'channels' table if it does not already exist. - """ - try: - sql = """ - CREATE TABLE IF NOT EXISTS `channels` ( - `id` INT AUTO_INCREMENT PRIMARY KEY, - `channel_id` BIGINT, - `initiator_user_id` BIGINT, - `updater_user_id` BIGINT, - `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, - `deleted_at` TIMESTAMP NULL DEFAULT NULL - ); - """ - self.cursor.execute(sql) - self.connection.commit() - except mysql.connector.Error as err: - self.root_logger.error(err) - self.reconnect() - except Exception as err: - self.root_logger.error(err) ## ---------------- Scheduler --------------------- def ban_user_for_one_hour(self, user_id, comment=None): diff --git a/bot/handlers/admins/mandatory_membership/add_channel.py b/bot/handlers/admins/mandatory_membership/add_channel.py index 895a85b..d3cc546 100755 --- a/bot/handlers/admins/mandatory_membership/add_channel.py +++ b/bot/handlers/admins/mandatory_membership/add_channel.py @@ -1,41 +1,23 @@ -import logging -from loader import dp, bot from aiogram import types, F -from keyboards.inline.button import AdminCallback -from keyboards.inline.close_btn import close_btn -from filters.admin import IsAdmin, SelectAdmin from aiogram.fsm.context import FSMContext -from api.translator import translator -from states.admin_state import AdminState -@dp.callback_query(AdminCallback.filter(F.action == "add_channel"), IsAdmin()) -async def add_channel(call: types.CallbackQuery, state: FSMContext): - """ - Handles the process of adding a channel by an admin in a Telegram bot. - Parameters: - - call (types.CallbackQuery): The callback query object containing details about the callback. - - state (FSMContext): Finite State Machine context used to manage the current state of the admin. +from bot.filters.admin import IsAdmin +from bot.states.admin_state import AdminState +from bot.keyboards.inline.close_btn import close_btn +from bot.keyboards.inline.button import AdminCallback +from bot.loader import dp, bot, root_logger, AM, translator - Functionality: - - Retrieves the admin's ID, message ID, and language_codeuage code from the callback query. - - Checks if the admin has the necessary permissions to add a channel using the `SelectAdmin` filter. - - If authorized, prompts the admin to send the channel ID and updates the admin's state to `AdminState.add_channel`. - - If not authorized, sends a message indicating that the admin lacks the necessary permissions. - - Edits the original message with the result of the permission check and the prompt for the channel ID. - - Logs any exceptions that occur during execution. - Returns: - - This function is asynchronous and does not return a value but performs actions such as sending messages and updating states. - """ +@dp.callback_query(AdminCallback.filter(F.action == "add_channel"), IsAdmin()) +async def add_channel(call: types.CallbackQuery, state: FSMContext): try: user_id = call.from_user.id # The ID of the admin initiating the action mid = call.message.message_id # The ID of the message triggering the callback language_code = call.from_user.language_code # The language_codeuage code of the admin for message translation - data = SelectAdmin(user_id=user_id) # Check if the admin has permission to manage channel settings btn = close_btn() # Inline button to close the message - if data.channel_settings(): + if AM(user_id=user_id, feature='mandatory_membership'): # If the admin is authorized, prompt for the channel ID await state.set_state(AdminState.add_channel) # Set the FSM state for adding a channel text = translator(text="😊 Please send the channel id...", dest=language_code) @@ -52,4 +34,4 @@ async def add_channel(call: types.CallbackQuery, state: FSMContext): ) await state.update_data({"message_id": call.message.message_id}) # Save the message ID in the FSM context except Exception as err: - logging.error(err) # Log any exceptions that occur + root_logger.error(err) # Log any exceptions that occur diff --git a/bot/handlers/admins/mandatory_membership/channel_setting.py b/bot/handlers/admins/mandatory_membership/channel_setting.py index 33b5d9a..ca6e342 100755 --- a/bot/handlers/admins/mandatory_membership/channel_setting.py +++ b/bot/handlers/admins/mandatory_membership/channel_setting.py @@ -1,44 +1,24 @@ -import logging -from loader import dp, bot, db from aiogram import types, F -from keyboards.inline.button import AdminCallback -from keyboards.inline.admin_btn import channel_settings -from keyboards.inline.close_btn import close_btn -from filters.admin import IsAdmin, SelectAdmin from aiogram.fsm.context import FSMContext -from api.translator import translator -from data.config import ADMIN -@dp.callback_query(AdminCallback.filter(F.action == "channel_setting"), IsAdmin()) -async def channel_setting(call: types.CallbackQuery, state: FSMContext): - """ - Handles the display of channel settings for an admin in a Telegram bot. - - Parameters: - - call (types.CallbackQuery): The callback query object containing details about the callback. - - state (FSMContext): Finite State Machine context used to manage the current state of the admin. +from bot.data.config import ADMIN +from bot.filters.admin import IsAdmin +from bot.loader import dp, bot, db, translator, root_logger, AM +from bot.keyboards.inline.close_btn import close_btn +from bot.keyboards.inline.button import AdminCallback +from bot.keyboards.inline.admin_btn import channel_settings - Functionality: - - Extracts the admin's ID, message ID, and language code from the callback query. - - Verifies if the admin has the necessary permissions to manage channel settings using the `SelectAdmin` filter. - - If the admin is the main ADMIN, retrieves all channels from the database; otherwise, retrieves channels added by the admin. - - Constructs a message displaying the list of channels, including details such as the channel's name, username, added date, and the admin who added it. - - If no channels are found, sends a message indicating the list is empty. - - Updates the message with channel settings and appropriate buttons. - - Logs any exceptions that occur during execution. - Returns: - - This function is asynchronous and does not return a value but performs actions such as sending messages and updating states. - """ +@dp.callback_query(AdminCallback.filter(F.action == "mandatory_membership"), IsAdmin()) +async def channel_setting(call: types.CallbackQuery, state: FSMContext): try: user_id = call.from_user.id # The ID of the admin initiating the action mid = call.message.message_id # The ID of the message triggering the callback language_code = call.from_user.language_code # The language code of the admin for message translation - data = SelectAdmin(user_id=user_id) # Check if the admin has permission to manage channel settings btn = close_btn() # Inline button to close the message - if data.channel_settings(): + if AM(user_id=user_id, feature='mandatory_membership'): if user_id == ADMIN: # Retrieve all channels if the admin is the main ADMIN data = db.select_channels() @@ -63,7 +43,7 @@ async def channel_setting(call: types.CallbackQuery, state: FSMContext): f"Added date: {x['created_at']}\n" f"Added by user_id: {x['initiator_user_id']}\n\n") except Exception as err: - logging.error(err) # Log any errors in retrieving channel details + root_logger.error(err) # Log any errors in retrieving channel details btn = channel_settings(language_code=language_code) # Button for channel settings else: # Inform the admin that they do not have the necessary permissions diff --git a/bot/handlers/admins/mandatory_membership/delete_channel.py b/bot/handlers/admins/mandatory_membership/delete_channel.py index 1c464ee..7401d52 100755 --- a/bot/handlers/admins/mandatory_membership/delete_channel.py +++ b/bot/handlers/admins/mandatory_membership/delete_channel.py @@ -10,26 +10,6 @@ @dp.callback_query(IsAdmin(), AdminCallback.filter(F.action == "delete_channel")) async def delete_channel(call: types.CallbackQuery, callback_data: AdminCallback, state: FSMContext): - """ - Handles the deletion of a channel in a Telegram bot by an authorized admin. - - Parameters: - - call (types.CallbackQuery): The callback query object containing details about the interaction. - - callback_data (AdminCallback): Contains the action and additional data, including the channel ID. - - state (FSMContext): FSM context used to manage the bot's state for the current conversation. - - Functionality: - - Retrieves the admin's user ID (`user_id`), the message ID (`mid`), and the language code (`lang`) from the callback query. - - Checks if the user has the necessary permissions to manage channel settings using the `SelectAdmin` filter. - - If authorized, retrieves the channel ID from `callback_data`, formats it, and checks its existence in the database. - - If the channel exists and the user is authorized, deletes the channel from the database and notifies the user. - - If the channel does not exist or the user is not authorized, sends an appropriate message to the user. - - Updates the bot message with the result of the operation and a close button (`close_btn`). - - Catches and logs any exceptions that occur during the execution. - - Returns: - - This function is asynchronous and does not return a value. It interacts with the Telegram API to send and edit messages. - """ try: user_id = call.from_user.id # The ID of the admin making the request mid = call.message.message_id # The ID of the message associated with the callback diff --git a/bot/handlers/admins/mandatory_membership/get_id.py b/bot/handlers/admins/mandatory_membership/get_id.py index a3e1d58..157335c 100755 --- a/bot/handlers/admins/mandatory_membership/get_id.py +++ b/bot/handlers/admins/mandatory_membership/get_id.py @@ -11,25 +11,6 @@ @dp.message(AdminState.add_channel, IsAdmin()) async def add_channel2(msg: types.Message, state: FSMContext): - """ - Handles the addition of a new channel to the bot's database by an authorized admin. - - Parameters: - - msg (types.Message): The message object containing the channel ID input by the user. - - state (FSMContext): FSM context used to manage the bot's state for the current conversation. - - Functionality: - - Retrieves the admin's user ID (`user_id`), the message ID (`mid`), and the language code (`lang`) from the message. - - Checks if the user has the necessary permissions to manage channel settings using the `SelectAdmin` filter. - - If authorized, attempts to convert the input text into a channel ID, checks if the channel is already in the database, and adds it if not. - - If the channel is already in the database, provides details about the existing entry. - - If the bot is not an admin in the channel or other errors occur, logs the error and informs the user. - - Clears the state and updates the bot message with the result of the operation and a close button (`close_btn`). - - Catches and logs any exceptions that occur during the execution. - - Returns: - - This function is asynchronous and does not return a value. It interacts with the Telegram API to send and edit messages. - """ try: user_id = msg.from_user.id # The ID of the admin making the request mid = msg.message_id # The ID of the message associated with the request diff --git a/bot/handlers/admins/mandatory_membership/mandatory_membership.py b/bot/handlers/admins/mandatory_membership/mandatory_membership.py index 8b60680..1912984 100755 --- a/bot/handlers/admins/mandatory_membership/mandatory_membership.py +++ b/bot/handlers/admins/mandatory_membership/mandatory_membership.py @@ -11,27 +11,6 @@ @dp.callback_query(AdminCallback.filter(F.action == "mandatory_membership"), IsAdmin()) async def mandatory_membership(call: types.CallbackQuery, state: FSMContext): - """ - Toggles the mandatory membership setting for a channel and updates the bot's response message. - - Parameters: - - call (types.CallbackQuery): The callback query object containing the information from the user's action. - - state (FSMContext): The FSM context to manage the bot's state during the conversation. - - Functionality: - - Retrieves the admin's user ID (`user_id`), the message ID (`mid`), and the language_codeuage code (`language_code`) from the callback query. - - Checks if the user has the required permissions to modify channel settings using the `SelectAdmin` filter. - - If authorized, reads the current mandatory membership status from the database. - - Toggles the membership requirement status: - - If currently enabled, disables it and updates the database. - - If currently disabled, enables it and updates the database. - - Updates the message in the chat with the new status and a close button (`close_btn`). - - If the user does not have the required permissions, informs them with an appropriate message. - - Updates the state with the message ID to reflect the latest changes. - - Returns: - - This function is asynchronous and does not return a value. It interacts with the Telegram API to update messages and with the database to modify settings. - """ try: user_id = call.from_user.id # The ID of the admin who initiated the action mid = call.message.message_id # The ID of the message to be updated diff --git a/bot/handlers/admins/mandatory_membership/remove_channel.py b/bot/handlers/admins/mandatory_membership/remove_channel.py index 1da271e..25f7673 100755 --- a/bot/handlers/admins/mandatory_membership/remove_channel.py +++ b/bot/handlers/admins/mandatory_membership/remove_channel.py @@ -12,24 +12,6 @@ @dp.callback_query(IsAdmin(), AdminCallback.filter(F.action == "remove_channel")) async def remove_channel(call: types.CallbackQuery, state: FSMContext): - """ - Handles the removal of channels by displaying a list of channels and allowing the admin to choose one to delete. - - Parameters: - - call (types.CallbackQuery): The callback query object containing information about the user's action. - - state (FSMContext): The FSM context to manage the bot's state during the conversation. - - Functionality: - - Retrieves the admin's user ID (`user_id`), the message ID (`mid`), and the language code (`lang`) from the callback query. - - Checks if the user has the necessary permissions to access channel settings using the `SelectAdmin` filter. - - If authorized, retrieves the list of channels either for all admins (if the user is the main admin) or for channels added by the specific admin. - - If the channel list is empty, informs the admin. If not, displays a list of channels with options to delete them. - - Creates an inline keyboard with buttons to choose channels for deletion and a close button. - - Updates the message in the chat with the channel list and the inline keyboard. - - Returns: - - This function is asynchronous and does not return a value. It interacts with the Telegram API to update messages and with the database to retrieve channel information. - """ try: user_id = call.from_user.id # The ID of the admin who initiated the action mid = call.message.message_id # The ID of the message to be updated From f82815bf26592acbafcedb1307d9c15148034200 Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Sun, 13 Jul 2025 23:14:29 +0500 Subject: [PATCH 70/71] refactor: Enhance ManageMandatoryMembership class with Redis synchronization and update methods --- bot/core/manage_mandatory_membership.py | 191 ++++++++++++++---- bot/loader.py | 5 +- .../test_manage_mandatory_membership.py | 57 ++++++ 3 files changed, 207 insertions(+), 46 deletions(-) create mode 100644 tests/moduls/test_manage_mandatory_membership.py diff --git a/bot/core/manage_mandatory_membership.py b/bot/core/manage_mandatory_membership.py index f921ab5..0d07e7c 100644 --- a/bot/core/manage_mandatory_membership.py +++ b/bot/core/manage_mandatory_membership.py @@ -1,64 +1,169 @@ import json +import datetime import logging import mysql.connector -from redis import Redis -from datetime import datetime - - +import redis +from bot.data.config import ADMIN from bot.db.database import Database class ManageMandatoryMembership: - _REDIS_HASH = "mandatory_membership" - - def __init__(self, db: Database, redis_client: Redis, root_logger: logging.Logger): + """ + Manages mandatory membership channels for a Telegram bot, synchronizing Redis cache and MySQL storage. + """ + def __init__(self, db: Database, redis_client: redis.Redis): self.db = db self.redis = redis_client - self.log = root_logger + self.logger = logging.getLogger(__name__) self._create_table() - def channels(self): - pass + def _create_table(self): + """ + Ensures the `mandatory_membership` table exists in MySQL. + """ + sql = """ + CREATE TABLE IF NOT EXISTS mandatory_membership ( + id INT AUTO_INCREMENT PRIMARY KEY, + channel_id BIGINT NOT NULL UNIQUE, + initiator_user_id BIGINT NOT NULL, + updater_user_id BIGINT, + is_active TINYINT(1) NOT NULL DEFAULT 1, + created_at DATETIME NOT NULL, + updated_at DATETIME NOT NULL, + deleted_at DATETIME NULL + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """ + self.db.cursor.execute(sql) - def update(self, channel_id: int, initiator_user_id: int, is_active: bool): + def channels(self) -> list[int]: + """ + Returns a list of all active channel IDs. + Attempts to read from Redis first; if cache is empty, falls back to MySQL and repopulates cache. + """ + pattern = "mandatory_membership:*" + try: + keys = self.redis.keys(pattern) + except Exception as e: + self.logger.error(f"Redis error on keys(): {e}") + keys = [] - current_time = datetime.now() + active_channels = [] + for key in keys: + try: + raw = self.redis.get(key) + if not raw: + continue + record = json.loads(raw) + if record.get("is_active"): + active_channels.append(int(record["channel_id"])) + except Exception: + continue - redis_key = f"{self.ns}:channels" + if active_channels: + return active_channels - redis_data = self.redis.get(redis_key) - - + # Cache miss: load from DB + sql = ( + "SELECT id, channel_id, initiator_user_id, updater_user_id, is_active, created_at, updated_at, deleted_at " + "FROM mandatory_membership WHERE is_active = 1 AND deleted_at IS NULL" + ) + self.db.cursor.execute(sql) + rows = self.db.cursor.fetchall() - cache_data = { - "channel_id": channel_id, - "is_active": True, - "initiator_user_id": initiator_user_id, - "created_at": current_time.isoformat() - } - self.redis.set(redis_key, json.dumps(cache_data)) + for row in rows: + key = f"mandatory_membership:{row['channel_id']}" + record = { + "id": row["id"], + "channel_id": row["channel_id"], + "initiator_user_id": row["initiator_user_id"], + "updater_user_id": row["updater_user_id"], + "is_active": bool(row["is_active"]), + "created_at": row["created_at"].isoformat(), + "updated_at": row["updated_at"].isoformat(), + "deleted_at": row["deleted_at"].isoformat() if row["deleted_at"] else None + } + try: + self.redis.set(key, json.dumps(record)) + except Exception as e: + self.logger.error(f"Redis error on set(): {e}") + active_channels.append(int(row["channel_id"])) + return active_channels + def update(self, channel_id: int, is_active: bool, updater_user_id: int) -> dict: + """ + Adds a new channel or updates the active status of an existing one. + - If the channel does not exist, it is inserted (initiator_user_id = updater_user_id). + - If it exists, only the original initiator or super admin may update it. + - Synchronizes changes to both MySQL and Redis. - def _create_table(self): + Returns the record dict after update. + """ + now = datetime.datetime.utcnow() + # Check for existing record + sql_select = ( + "SELECT * FROM mandatory_membership WHERE channel_id = %s AND deleted_at IS NULL" + ) + self.db.cursor.execute(sql_select, (channel_id,)) + row = self.db.cursor.fetchone() + + deleted_at = None + if row is None: + # Insert new record + sql_insert = ( + "INSERT INTO mandatory_membership " + "(channel_id, initiator_user_id, updater_user_id, is_active, created_at, updated_at) " + "VALUES (%s, %s, %s, %s, %s, %s)" + ) + self.db.cursor.execute(sql_insert, ( + channel_id, + updater_user_id, + updater_user_id, + int(is_active), + now, + now + )) + record_id = self.db.cursor.lastrowid + initiator_id = updater_user_id + created_at = now + else: + # Permission check + initiator_id = row["initiator_user_id"] + created_at = row["created_at"] + if updater_user_id not in (initiator_id, ADMIN): + raise PermissionError("Only the initiator or super admin can update this channel") + # Handle deactivation + if not is_active: + deleted_at = now + sql_update = ( + "UPDATE mandatory_membership SET is_active = %s, updater_user_id = %s, updated_at = %s, deleted_at = %s " + "WHERE channel_id = %s" + ) + self.db.cursor.execute(sql_update, ( + int(is_active), + updater_user_id, + now, + deleted_at, + channel_id + )) + record_id = row["id"] + + # Build cache record + cache_key = f"mandatory_membership:{channel_id}" + cache_record = { + "id": record_id, + "channel_id": channel_id, + "initiator_user_id": initiator_id, + "updater_user_id": updater_user_id, + "is_active": is_active, + "created_at": created_at.isoformat(), + "updated_at": now.isoformat(), + "deleted_at": deleted_at.isoformat() if deleted_at else None + } try: - sql = """ - CREATE TABLE IF NOT EXISTS `channels` ( - `id` INT AUTO_INCREMENT PRIMARY KEY, - `channel_id` BIGINT, - `initiator_user_id` BIGINT, - `updater_user_id` BIGINT, - `is_active`BOOLEAN DEFAULT TRUE, - `created_at` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, - `updated_at` TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP, - `deleted_at` TIMESTAMP NULL DEFAULT NULL - ); - """ - self.db.cursor.execute(sql) - self.db.connection.commit() - except mysql.connector.Error as err: - self.log.error(err) - self.db() - except Exception as err: - self.log.error(err) + self.redis.set(cache_key, json.dumps(cache_record)) + except Exception as e: + self.logger.error(f"Redis error on set(): {e}") + + return cache_record diff --git a/bot/loader.py b/bot/loader.py index dd2e645..6208081 100755 --- a/bot/loader.py +++ b/bot/loader.py @@ -11,7 +11,7 @@ from bot.core.feature_manager import FeatureManager from bot.core.settings_manager import SettingsManager from bot.core.admin_rights_manager import AdminsManager - +from bot.core.manage_mandatory_membership import ManageMandatoryMembership @@ -49,5 +49,4 @@ translator = Translator(db=db, FM=FM, root_logger=root_logger, redis_client=redis) - - +MMM = ManageMandatoryMembership(db=db, redis_client=redis) diff --git a/tests/moduls/test_manage_mandatory_membership.py b/tests/moduls/test_manage_mandatory_membership.py new file mode 100644 index 0000000..e5b57a6 --- /dev/null +++ b/tests/moduls/test_manage_mandatory_membership.py @@ -0,0 +1,57 @@ +import pytest +from bot.loader import MMM, db +from bot.data.config import ADMIN + +# Sample user IDs for testing +INITIATOR_ID = 123456789 # Replace with a valid user ID for testing +OTHER_USER_ID = 987654321 # A user who did not initiate the channel +CHANNEL_ID = -1001122334455 # Replace with a test Telegram channel ID + + +def test_manage_mandatory_membership_flow(): + # Initialize the ManageMandatoryMembership instance + mm = MMM + + # Ensure clean state in Redis and MySQL + redis_key = f"mandatory_membership:{CHANNEL_ID}" + mm.redis.delete(redis_key) + db.cursor.execute("DELETE FROM mandatory_membership WHERE channel_id = %s", (CHANNEL_ID,)) + db.connection.commit() + + # 1. Add a new channel (should succeed) + mm.update(channel_id=CHANNEL_ID, is_active=True, updater_user_id=INITIATOR_ID) + + # Verify channel is active in Redis + data_json = mm.redis.get(redis_key) + assert data_json is not None, "Channel data should exist in Redis after adding" + + # Verify channel is active in MySQL + db.cursor.execute( + "SELECT is_active, initiator_user_id, updater_user_id FROM mandatory_membership WHERE channel_id = %s", + (CHANNEL_ID,) + ) + row = db.cursor.fetchone() + assert row, "Channel row should exist in MySQL after adding" + assert row['is_active'] == 1, "Channel should be marked active in MySQL" + assert row['initiator_user_id'] == INITIATOR_ID, "Initiator ID should match in MySQL" + + # 2. Unauthorized update attempt (should raise PermissionError) + with pytest.raises(PermissionError): + mm.update(channel_id=CHANNEL_ID, is_active=False, updater_user_id=OTHER_USER_ID) + + # 3. Authorized update by super admin (should succeed) + mm.update(channel_id=CHANNEL_ID, is_active=False, updater_user_id=ADMIN) + # # Verify status updated in Redis + # data_json = mm.redis.get(redis_key) + # assert b"\"is_active\": false" in data_json, "Redis should reflect inactive status" + # Verify status updated in MySQL + db.cursor.execute( + "SELECT is_active FROM mandatory_membership WHERE channel_id = %s", + (CHANNEL_ID,) + ) + updated_row = db.cursor.fetchone() + assert updated_row['is_active'] == 0, "Channel should be marked inactive in MySQL" + + # 4. channels() should list only active channels (none in this case) + active_channels = mm.channels() + assert CHANNEL_ID not in active_channels, "Inactive channel should not be returned by channels()" From 7033600851a7b6a14e3558f9ab5043a10cd0d6de Mon Sep 17 00:00:00 2001 From: UZNetDev Date: Mon, 1 Sep 2025 16:10:44 +0500 Subject: [PATCH 71/71] . --- bot/core/manage_mandatory_membership.py | 471 +++++++++++++----- .../mandatory_membership.py | 88 ++-- bot/keyboards/inline/admin_btn.py | 41 -- 3 files changed, 384 insertions(+), 216 deletions(-) diff --git a/bot/core/manage_mandatory_membership.py b/bot/core/manage_mandatory_membership.py index 0d07e7c..b9b179d 100644 --- a/bot/core/manage_mandatory_membership.py +++ b/bot/core/manage_mandatory_membership.py @@ -1,169 +1,366 @@ import json -import datetime import logging -import mysql.connector +from datetime import datetime +from typing import Any, Dict, List, Optional + import redis +import mysql.connector + from bot.data.config import ADMIN from bot.db.database import Database class ManageMandatoryMembership: """ - Manages mandatory membership channels for a Telegram bot, synchronizing Redis cache and MySQL storage. + Manage mandatory membership channels for a Telegram bot. + + - Data model fields: + id, channel_id, initiator_user_id, updater_user_id, + is_active, created_at, updated_at, deleted_at + + - Redis key: + "mandatory_membership:{channel_id}" -> JSON-serialized channel row + + - Rules: + * Reads prefer Redis; if missing/stale, fall back to MySQL and refresh Redis. + * If channel doesn't exist on update(), it is created with initiator_user_id = updater_user_id. + * Only the original initiator or ADMIN can update an existing channel. + * channels(initiator_user_id) returns active channel IDs: + - If initiator_user_id is None or ADMIN -> all active channels. + - Else -> active channels added by that initiator_user_id. """ - def __init__(self, db: Database, redis_client: redis.Redis): + + TABLE = "mandatory_memberships" + REDIS_PREFIX = "mandatory_membership" + + def __init__( + self, + db: Database, + redis_client: redis.Redis, + root_logger: Optional[logging.Logger] = None, + ): self.db = db - self.redis = redis_client - self.logger = logging.getLogger(__name__) + self.r = redis_client + self.log = root_logger or logging.getLogger(__name__) self._create_table() - def _create_table(self): - """ - Ensures the `mandatory_membership` table exists in MySQL. - """ - sql = """ - CREATE TABLE IF NOT EXISTS mandatory_membership ( - id INT AUTO_INCREMENT PRIMARY KEY, - channel_id BIGINT NOT NULL UNIQUE, - initiator_user_id BIGINT NOT NULL, - updater_user_id BIGINT, - is_active TINYINT(1) NOT NULL DEFAULT 1, - created_at DATETIME NOT NULL, - updated_at DATETIME NOT NULL, - deleted_at DATETIME NULL - ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; - """ - self.db.cursor.execute(sql) + # ---------- Public API ---------- - def channels(self) -> list[int]: + def channels(self, initiator_user_id: Optional[int]) -> List[int]: """ - Returns a list of all active channel IDs. - Attempts to read from Redis first; if cache is empty, falls back to MySQL and repopulates cache. + Return list of ACTIVE channel_ids filtered by initiator_user_id. + - None or ADMIN -> all active channels + - Otherwise -> only active channels added by that initiator_user_id """ - pattern = "mandatory_membership:*" + # Try to build from Redis (best-effort) + redis_ids = self._channels_from_redis(initiator_user_id) + + # Always verify/correct with DB to guarantee completeness/consistency + if initiator_user_id is None or initiator_user_id == ADMIN: + sql = f""" + SELECT channel_id + FROM {self.TABLE} + WHERE is_active = 1 AND deleted_at IS NULL + """ + params = () + else: + sql = f""" + SELECT channel_id + FROM {self.TABLE} + WHERE is_active = 1 + AND initiator_user_id = %s + AND deleted_at IS NULL + """ + params = (initiator_user_id,) + try: - keys = self.redis.keys(pattern) - except Exception as e: - self.logger.error(f"Redis error on keys(): {e}") - keys = [] + self.db.cursor.execute(sql, params) + rows = self.db.cursor.fetchall() or [] + except mysql.connector.Error as err: + self.log.error(f"[channels] MySQL error: {err}") + # If DB fails, fall back to Redis result (possibly partial) + return sorted(redis_ids) - active_channels = [] - for key in keys: - try: - raw = self.redis.get(key) - if not raw: - continue - record = json.loads(raw) - if record.get("is_active"): - active_channels.append(int(record["channel_id"])) - except Exception: - continue - - if active_channels: - return active_channels - - # Cache miss: load from DB - sql = ( - "SELECT id, channel_id, initiator_user_id, updater_user_id, is_active, created_at, updated_at, deleted_at " - "FROM mandatory_membership WHERE is_active = 1 AND deleted_at IS NULL" - ) - self.db.cursor.execute(sql) - rows = self.db.cursor.fetchall() - - for row in rows: - key = f"mandatory_membership:{row['channel_id']}" - record = { - "id": row["id"], - "channel_id": row["channel_id"], - "initiator_user_id": row["initiator_user_id"], - "updater_user_id": row["updater_user_id"], - "is_active": bool(row["is_active"]), - "created_at": row["created_at"].isoformat(), - "updated_at": row["updated_at"].isoformat(), - "deleted_at": row["deleted_at"].isoformat() if row["deleted_at"] else None - } - try: - self.redis.set(key, json.dumps(record)) - except Exception as e: - self.logger.error(f"Redis error on set(): {e}") - active_channels.append(int(row["channel_id"])) + db_ids = [int(r["channel_id"]) for r in rows] + + # Write-through: ensure all DB rows are cached in Redis + if db_ids: + self._refresh_cache_for_ids(db_ids) - return active_channels + # DB is the source of truth; return DB-derived list + return sorted(db_ids) - def update(self, channel_id: int, is_active: bool, updater_user_id: int) -> dict: + def update(self, channel_id: int, is_active: bool, updater_user_id: int) -> Dict[str, Any]: """ - Adds a new channel or updates the active status of an existing one. + Create or update a channel record. + - If record doesn't exist -> insert with initiator_user_id = updater_user_id + - If exists -> only initiator_user_id or ADMIN may update + - Write-first to MySQL, then update Redis + Returns the up-to-date row as a dict. + """ + if channel_id is None: + raise ValueError("channel_id is required") + if updater_user_id is None: + raise ValueError("updater_user_id is required") - - If the channel does not exist, it is inserted (initiator_user_id = updater_user_id). - - If it exists, only the original initiator or super admin may update it. - - Synchronizes changes to both MySQL and Redis. + is_active_int = 1 if bool(is_active) else 0 - Returns the record dict after update. - """ - now = datetime.datetime.utcnow() - # Check for existing record - sql_select = ( - "SELECT * FROM mandatory_membership WHERE channel_id = %s AND deleted_at IS NULL" - ) - self.db.cursor.execute(sql_select, (channel_id,)) - row = self.db.cursor.fetchone() + # 1) Try Redis, then MySQL + row = self._get_from_cache(channel_id) + if row is None: + row = self._get_from_db_by_channel_id(channel_id) - deleted_at = None + # 2) Insert or Update with permission checks if row is None: - # Insert new record - sql_insert = ( - "INSERT INTO mandatory_membership " - "(channel_id, initiator_user_id, updater_user_id, is_active, created_at, updated_at) " - "VALUES (%s, %s, %s, %s, %s, %s)" + # Insert new + new_row_id = self._insert_row( + channel_id=channel_id, + initiator_user_id=updater_user_id, + updater_user_id=updater_user_id, + is_active=is_active_int, ) - self.db.cursor.execute(sql_insert, ( - channel_id, - updater_user_id, - updater_user_id, - int(is_active), - now, - now - )) - record_id = self.db.cursor.lastrowid - initiator_id = updater_user_id - created_at = now + row = self._get_from_db_by_id(new_row_id) + if row is None: + raise RuntimeError("Insert succeeded but failed to re-fetch the row") else: # Permission check - initiator_id = row["initiator_user_id"] - created_at = row["created_at"] - if updater_user_id not in (initiator_id, ADMIN): - raise PermissionError("Only the initiator or super admin can update this channel") - # Handle deactivation - if not is_active: - deleted_at = now - sql_update = ( - "UPDATE mandatory_membership SET is_active = %s, updater_user_id = %s, updated_at = %s, deleted_at = %s " - "WHERE channel_id = %s" + initiator_id = int(row["initiator_user_id"]) + if updater_user_id != initiator_id and updater_user_id != ADMIN: + raise PermissionError( + "Only the initiator of this channel or the ADMIN can update it." + ) + # Update existing + self._update_row( + row_id=int(row["id"]), + is_active=is_active_int, + updater_user_id=updater_user_id, ) - self.db.cursor.execute(sql_update, ( - int(is_active), - updater_user_id, - now, - deleted_at, - channel_id - )) - record_id = row["id"] - - # Build cache record - cache_key = f"mandatory_membership:{channel_id}" - cache_record = { - "id": record_id, - "channel_id": channel_id, - "initiator_user_id": initiator_id, - "updater_user_id": updater_user_id, - "is_active": is_active, - "created_at": created_at.isoformat(), - "updated_at": now.isoformat(), - "deleted_at": deleted_at.isoformat() if deleted_at else None - } + row = self._get_from_db_by_channel_id(channel_id) + if row is None: + raise RuntimeError("Update succeeded but failed to re-fetch the row") + + # 3) Sync Redis + self._set_cache_row(row) + return row + + # ---------- Private: Schema ---------- + + def _create_table(self) -> None: + sql = f""" + CREATE TABLE IF NOT EXISTS `{self.TABLE}` ( + `id` INT AUTO_INCREMENT PRIMARY KEY, + `channel_id` BIGINT NOT NULL UNIQUE, + `initiator_user_id` BIGINT NOT NULL, + `updater_user_id` BIGINT DEFAULT NULL, + `is_active` TINYINT(1) NOT NULL DEFAULT 1, + `created_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + `updated_at` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + `deleted_at` DATETIME DEFAULT NULL, + INDEX idx_active (is_active), + INDEX idx_initiator (initiator_user_id), + INDEX idx_deleted (deleted_at) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; + """ + try: + self.db.cursor.execute(sql) + # autocommit is True in your Database class, no need to commit explicitly + self.log.debug(f"Ensured table `{self.TABLE}` exists.") + except mysql.connector.Error as err: + self.log.error(f"[create_table] MySQL error: {err}") + raise + + # ---------- Private: Redis helpers ---------- + + def _key(self, channel_id: int) -> str: + return f"{self.REDIS_PREFIX}:{channel_id}" + + def _get_from_cache(self, channel_id: int) -> Optional[Dict[str, Any]]: + try: + raw = self.r.get(self._key(channel_id)) + if not raw: + return None + data = json.loads(raw) + # Ensure keys we rely on exist + if "channel_id" not in data or "id" not in data: + return None + return data + except Exception as e: + self.log.warning(f"[cache:get] Redis error for {channel_id}: {e}") + return None + + def _set_cache_row(self, row: Dict[str, Any]) -> None: try: - self.redis.set(cache_key, json.dumps(cache_record)) + # Make datetime fields JSON-serializable + serializable = row.copy() + for k in ("created_at", "updated_at", "deleted_at"): + if serializable.get(k) is not None and not isinstance(serializable[k], str): + # MySQL connector may return datetime objects; store as ISO8601 strings + serializable[k] = serializable[k].isoformat(sep=" ", timespec="seconds") + self.r.set(self._key(int(row["channel_id"])), json.dumps(serializable)) except Exception as e: - self.logger.error(f"Redis error on set(): {e}") + self.log.warning(f"[cache:set] Redis error for {row.get('channel_id')}: {e}") - return cache_record + def _channels_from_redis(self, initiator_user_id: Optional[int]) -> List[int]: + """ + Best-effort scan of Redis to collect active channel_ids (may be partial). + """ + try: + pattern = f"{self.REDIS_PREFIX}:*" + channel_ids: List[int] = [] + for key in self.r.scan_iter(match=pattern, count=1000): + try: + raw = self.r.get(key) + if not raw: + continue + data = json.loads(raw) + if int(data.get("is_active", 0)) != 1: + continue + if initiator_user_id is None or initiator_user_id == ADMIN: + channel_ids.append(int(data["channel_id"])) + else: + if int(data.get("initiator_user_id", -1)) == int(initiator_user_id): + channel_ids.append(int(data["channel_id"])) + except Exception: + continue + return sorted(set(channel_ids)) + except Exception as e: + self.log.debug(f"[channels_from_redis] scan failed: {e}") + return [] + + def _refresh_cache_for_ids(self, channel_ids: List[int]) -> None: + """ + Ensure Redis has up-to-date rows for the provided channel_ids (from DB). + """ + if not channel_ids: + return + fmt = ",".join(["%s"] * len(channel_ids)) + sql = f""" + SELECT * + FROM {self.TABLE} + WHERE channel_id IN ({fmt}) AND deleted_at IS NULL + """ + try: + self.db.cursor.execute(sql, tuple(channel_ids)) + rows = self.db.cursor.fetchall() or [] + for row in rows: + self._set_cache_row(row) + except mysql.connector.Error as err: + self.log.debug(f"[refresh_cache] MySQL error: {err}") + + # ---------- Private: DB ops ---------- + + def _get_from_db_by_channel_id(self, channel_id: int) -> Optional[Dict[str, Any]]: + sql = f""" + SELECT * + FROM {self.TABLE} + WHERE channel_id = %s AND deleted_at IS NULL + LIMIT 1 + """ + try: + self.db.cursor.execute(sql, (channel_id,)) + return self.db.cursor.fetchone() + except mysql.connector.Error as err: + self.log.error(f"[db:get_by_channel] MySQL error: {err}") + return None + + def _get_from_db_by_id(self, row_id: int) -> Optional[Dict[str, Any]]: + sql = f"SELECT * FROM {self.TABLE} WHERE id = %s LIMIT 1" + try: + self.db.cursor.execute(sql, (row_id,)) + return self.db.cursor.fetchone() + except mysql.connector.Error as err: + self.log.error(f"[db:get_by_id] MySQL error: {err}") + return None + + def _insert_row( + self, + channel_id: int, + initiator_user_id: int, + updater_user_id: int, + is_active: int, + ) -> int: + sql = f""" + INSERT INTO {self.TABLE} + (channel_id, initiator_user_id, updater_user_id, is_active, created_at, updated_at, deleted_at) + VALUES + (%s, %s, %s, %s, %s, %s, NULL) + """ + now = datetime.now().strftime("%Y-%m-%d %H:%M:%S") + try: + self.db.cursor.execute( + sql, + (channel_id, initiator_user_id, updater_user_id, is_active, now, now), + ) + # autocommit enabled + last_id = self.db.cursor.lastrowid + self.log.info(f"[insert] Added channel {channel_id} by {initiator_user_id} (id={last_id})") + return int(last_id) + except mysql.connector.errors.IntegrityError as err: + # Handle unique violation on channel_id -> convert to update + self.log.warning(f"[insert] IntegrityError (exists?) for channel {channel_id}: {err}") + existing = self._get_from_db_by_channel_id(channel_id) + if existing: + return int(existing["id"]) + raise + except mysql.connector.Error as err: + self.log.error(f"[insert] MySQL error: {err}") + raise + + def _update_row(self, row_id: int, is_active: int, updater_user_id: int) -> None: + sql = f""" + UPDATE {self.TABLE} + SET is_active = %s, + updater_user_id = %s, + updated_at = CURRENT_TIMESTAMP + WHERE id = %s AND deleted_at IS NULL + """ + try: + self.db.cursor.execute(sql, (is_active, updater_user_id, row_id)) + self.log.info(f"[update] Row id={row_id} set is_active={is_active} by {updater_user_id}") + except mysql.connector.Error as err: + self.log.error(f"[update] MySQL error: {err}") + raise + + # ---------- (Optional) Utilities ---------- + + def get(self, channel_id: int) -> Optional[Dict[str, Any]]: + """ + Fetch a single channel row (active or inactive, but not soft-deleted). + Redis first; if missing then DB, and refresh cache. + """ + row = self._get_from_cache(channel_id) + if row is None: + row = self._get_from_db_by_channel_id(channel_id) + if row: + self._set_cache_row(row) + return row + + def soft_delete(self, channel_id: int, deleter_user_id: int) -> bool: + """ + Soft delete (set deleted_at) — optional helper if you need it later. + Only initiator or ADMIN may delete. + """ + row = self._get_from_cache(channel_id) or self._get_from_db_by_channel_id(channel_id) + if not row: + return False + initiator_id = int(row["initiator_user_id"]) + if deleter_user_id != initiator_id and deleter_user_id != ADMIN: + raise PermissionError("Only the initiator or ADMIN can delete this channel.") + + sql = f""" + UPDATE {self.TABLE} + SET deleted_at = CURRENT_TIMESTAMP, + updater_user_id = %s + WHERE id = %s AND deleted_at IS NULL + """ + try: + self.db.cursor.execute(sql, (deleter_user_id, int(row["id"]))) + # Remove from cache so it won't be returned accidentally + try: + self.r.delete(self._key(channel_id)) + except Exception: + pass + return True + except mysql.connector.Error as err: + self.log.error(f"[soft_delete] MySQL error: {err}") + return False diff --git a/bot/handlers/admins/mandatory_membership/mandatory_membership.py b/bot/handlers/admins/mandatory_membership/mandatory_membership.py index 1912984..ad8a6ca 100755 --- a/bot/handlers/admins/mandatory_membership/mandatory_membership.py +++ b/bot/handlers/admins/mandatory_membership/mandatory_membership.py @@ -1,50 +1,62 @@ -import logging -from loader import dp, bot, db from aiogram import types, F -from keyboards.inline.button import AdminCallback -from keyboards.inline.admin_btn import channel_settings -from keyboards.inline.close_btn import close_btn -from filters.admin import IsAdmin, SelectAdmin from aiogram.fsm.context import FSMContext -from api.translator import translator + + +from bot.data.config import ADMIN +from bot.filters.admin import IsAdmin +from bot.loader import dp, bot, db, translator, root_logger, AM, MMM +from bot.keyboards.inline.close_btn import close_btn +from bot.keyboards.inline.button import AdminCallback +from bot.keyboards.inline.admin_btn import channel_settings @dp.callback_query(AdminCallback.filter(F.action == "mandatory_membership"), IsAdmin()) -async def mandatory_membership(call: types.CallbackQuery, state: FSMContext): +async def channel_setting(call: types.CallbackQuery, state: FSMContext): try: - user_id = call.from_user.id # The ID of the admin who initiated the action - mid = call.message.message_id # The ID of the message to be updated - language_code = call.from_user.language_code # The language_codeuage code for translation - data = SelectAdmin(user_id=user_id) # Check if the user has admin permissions - btn = close_btn() # Create a button for closing the message - - if data.channel_settings(): - # Read the current setting for mandatory membership from the database - mandatory_membership = db.select_setting('mandatory_membership') - if mandatory_membership == 'True': - # If mandatory membership is enabled, disable it - text = translator(text='☑️ Forced membership disabled!', dest=language_code) - nex_mandatory_membership = 'False' + user_id = call.from_user.id + mid = call.message.message_id + language_code = call.from_user.language_code + btn = close_btn() # Inline button to close the message + + if AM(user_id=user_id, feature='mandatory_membership'): + if user_id == ADMIN: + # Retrieve all channels if the admin is the main ADMIN + data = db.select_channels() else: - # If mandatory membership is disabled, enable it - text = translator(text='✅ Mandatory membership enabled!', dest=language_code) - nex_mandatory_membership = 'True' + # Retrieve channels added by the current admin + data = MMM.channels(initiator_user_id=user_id) - # Update the database with the new membership status - db.update_settings_key(updater_user_id=user_id, key='mandatory_membership', value=nex_mandatory_membership) - btn = channel_settings(language_code=language_code) # Update the button to reflect the new settings + if not data: + # If no channels are found, indicate that the list is empty + text = translator(text="❔ The channel list is empty!\n\n", dest=language_code) + else: + # Construct a message listing the channels + text = translator(text="🔰 List of channels:\n\n", dest=language_code) + count = 0 + for x in data: + try: + count += 1 + chat_id = str(-100) + str(x['channel_id']) # Telegram channel ID + channel = await bot.get_chat(chat_id=chat_id) # Get channel details + text += (f"{count}. Name: {channel.full_name}\n" + f"Username: @{channel.username}\n" + f"Added date: {x['created_at']}\n" + f"Added by user_id: {x['initiator_user_id']}\n\n") + except Exception as err: + root_logger.error(err) # Log any errors in retrieving channel details + btn = channel_settings(language_code=language_code) # Button for channel settings else: + # Inform the admin that they do not have the necessary permissions text = translator(text='❌ Unfortunately, you do not have this right!', dest=language_code) - # Edit the message with the new status and close button - await bot.edit_message_text(chat_id=user_id, - message_id=mid, - text=f'{text}', - reply_markup=btn) - # Update FSM state with the current message ID - await state.update_data({ - "message_id": call.message.message_id - }) + await bot.edit_message_text( + chat_id=user_id, + message_id=mid, + text=f'{text}', + reply_markup=btn # Update the message with a translated response and appropriate buttons + ) + + await state.update_data({"message_id": call.message.message_id}) # Save the message ID in the FSM context except Exception as err: - # Log any errors that occur during the execution - logging.error(err) + logging.error(err) # Log any exceptions that occur + diff --git a/bot/keyboards/inline/admin_btn.py b/bot/keyboards/inline/admin_btn.py index 813fd05..47cffb3 100644 --- a/bot/keyboards/inline/admin_btn.py +++ b/bot/keyboards/inline/admin_btn.py @@ -57,47 +57,6 @@ async def admin_setting(user_id, language_code): root_logger.error(err) return False -# def attach_admin(user_id, language_code): -# try: -# btn = InlineKeyboardBuilder() -# btn.attach(InlineKeyboardBuilder.from_markup(main_btn())) -# send_message_tx = x_or_y(AM('send_message', user_id)) -# wiew_statistika_tx = x_or_y(AM('view_statistika', user_id)) -# download_statistika_tx = x_or_y(AM('download_statistika', user_id)) -# block_user_tx = x_or_y(AM('block_user', user_id)) -# channel_settings_tx = x_or_y(AM('channel_settings', user_id)) -# add_admin_tx = x_or_y(AM('add_admin', user_id)) -# btn.button(text=translator(text=f"{send_message_tx} Send a message!", -# dest=language_code), -# callback_data=EditAdminSetting(action="edit", user_id=user_id, data='send_message').pack()) - -# btn.button(text=translator(text=f"{wiew_statistika_tx} Wiew statistics!", -# dest=language_code), -# callback_data=EditAdminSetting(action="edit", user_id=user_id, data='statistika').pack()) - -# btn.button(text=translator(text=f"{download_statistika_tx} Download statistics!", -# dest=language_code), -# callback_data=EditAdminSetting(action="edit", user_id=user_id, data='download_statistika').pack()) - -# btn.button(text=translator(text=f"{block_user_tx} Block user!", -# dest=language_code), -# callback_data=EditAdminSetting(action="edit", user_id=user_id, data='block_user').pack()) -# btn.button(text=translator(text=f"{channel_settings_tx} Channel settings!", -# dest=language_code), -# callback_data=EditAdminSetting(action="edit", user_id=user_id, data='channel_settings').pack()) -# btn.button(text=translator(text=f"{add_admin_tx} Add a admin!", -# dest=language_code), -# callback_data=EditAdminSetting(action="edit", user_id=user_id, data='add_admin').pack()) -# btn.button(text=translator(text=f"🔪Delete admin!", -# dest=language_code), -# callback_data=EditAdminSetting(action="edit", user_id=user_id, data='delete_admin').pack()) -# btn.adjust(1) -# btn.attach(InlineKeyboardBuilder.from_markup(close_btn())) -# return btn.as_markup() -# except Exception as err: -# root_logger.error(err) -# return False - def attach_admin_btn(user_id, language_code): try: btn = InlineKeyboardBuilder()