mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-29 04:43:45 +03:00
Explicitly open files as 'r' instead of leaving it out
This commit is contained in:
parent
d64eb7ea2b
commit
dd0eb7a90e
|
@ -68,7 +68,7 @@ author = 'Lonami'
|
||||||
# built documents.
|
# built documents.
|
||||||
#
|
#
|
||||||
# The short X.Y version.
|
# The short X.Y version.
|
||||||
with open(os.path.join(root, 'telethon', 'version.py')) as f:
|
with open(os.path.join(root, 'telethon', 'version.py'), 'r') as f:
|
||||||
version = re.search(r"^__version__\s+=\s+'(.*)'$",
|
version = re.search(r"^__version__\s+=\s+'(.*)'$",
|
||||||
f.read(), flags=re.MULTILINE).group(1)
|
f.read(), flags=re.MULTILINE).group(1)
|
||||||
|
|
||||||
|
|
7
setup.py
7
setup.py
|
@ -60,7 +60,8 @@ def generate(which):
|
||||||
from telethon_generator.generators import\
|
from telethon_generator.generators import\
|
||||||
generate_errors, generate_tlobjects, generate_docs, clean_tlobjects
|
generate_errors, generate_tlobjects, generate_docs, clean_tlobjects
|
||||||
|
|
||||||
with open(INVALID_BM_IN) as f:
|
# Older Python versions open the file as bytes instead (3.4.2)
|
||||||
|
with open(INVALID_BM_IN, 'r') as f:
|
||||||
invalid_bot_methods = set(json.load(f))
|
invalid_bot_methods = set(json.load(f))
|
||||||
|
|
||||||
layer = find_layer(TLOBJECT_IN_TL)
|
layer = find_layer(TLOBJECT_IN_TL)
|
||||||
|
@ -176,10 +177,10 @@ def main():
|
||||||
generate(['tl', 'errors'])
|
generate(['tl', 'errors'])
|
||||||
|
|
||||||
# Get the long description from the README file
|
# Get the long description from the README file
|
||||||
with open('README.rst', encoding='utf-8') as f:
|
with open('README.rst', 'r', encoding='utf-8') as f:
|
||||||
long_description = f.read()
|
long_description = f.read()
|
||||||
|
|
||||||
with open('telethon/version.py', encoding='utf-8') as f:
|
with open('telethon/version.py', 'r', encoding='utf-8') as f:
|
||||||
version = re.search(r"^__version__\s*=\s*'(.*)'.*$",
|
version = re.search(r"^__version__\s*=\s*'(.*)'.*$",
|
||||||
f.read(), flags=re.MULTILINE).group(1)
|
f.read(), flags=re.MULTILINE).group(1)
|
||||||
setup(
|
setup(
|
||||||
|
|
|
@ -119,7 +119,7 @@ class SQLiteSession(MemorySession):
|
||||||
def _check_migrate_json(self):
|
def _check_migrate_json(self):
|
||||||
if file_exists(self.filename):
|
if file_exists(self.filename):
|
||||||
try:
|
try:
|
||||||
with open(self.filename, encoding='utf-8') as f:
|
with open(self.filename, 'r', encoding='utf-8') as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
self.delete() # Delete JSON file to create database
|
self.delete() # Delete JSON file to create database
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,7 @@ def _get_relative_path(destination, relative_to, folder=False):
|
||||||
|
|
||||||
def _find_title(html_file):
|
def _find_title(html_file):
|
||||||
"""Finds the <title> for the given HTML file, or (Unknown)."""
|
"""Finds the <title> for the given HTML file, or (Unknown)."""
|
||||||
with open(html_file) as fp:
|
with open(html_file, 'r') as fp:
|
||||||
for line in fp:
|
for line in fp:
|
||||||
if '<title>' in line:
|
if '<title>' in line:
|
||||||
# + 7 to skip len('<title>')
|
# + 7 to skip len('<title>')
|
||||||
|
@ -221,7 +221,7 @@ def _get_description(arg):
|
||||||
|
|
||||||
def _copy_replace(src, dst, replacements):
|
def _copy_replace(src, dst, replacements):
|
||||||
"""Copies the src file into dst applying the replacements dict"""
|
"""Copies the src file into dst applying the replacements dict"""
|
||||||
with open(src) as infile, open(dst, 'w') as outfile:
|
with open(src, 'r') as infile, open(dst, 'w') as outfile:
|
||||||
outfile.write(re.sub(
|
outfile.write(re.sub(
|
||||||
'|'.join(re.escape(k) for k in replacements),
|
'|'.join(re.escape(k) for k in replacements),
|
||||||
lambda m: str(replacements[m.group(0)]),
|
lambda m: str(replacements[m.group(0)]),
|
||||||
|
|
|
@ -90,7 +90,7 @@ def parse_errors(json_file, descriptions_file):
|
||||||
|
|
||||||
The method yields `Error` instances as a result.
|
The method yields `Error` instances as a result.
|
||||||
"""
|
"""
|
||||||
with open(json_file, encoding='utf-8') as f:
|
with open(json_file, 'r', encoding='utf-8') as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
|
|
||||||
errors = defaultdict(set)
|
errors = defaultdict(set)
|
||||||
|
@ -124,7 +124,7 @@ def parse_errors(json_file, descriptions_file):
|
||||||
# Prefer the descriptions that are related with Telethon way of coding
|
# Prefer the descriptions that are related with Telethon way of coding
|
||||||
# to those that PWRTelegram's API provides.
|
# to those that PWRTelegram's API provides.
|
||||||
telethon_descriptions = {}
|
telethon_descriptions = {}
|
||||||
with open(descriptions_file, encoding='utf-8') as f:
|
with open(descriptions_file, 'r', encoding='utf-8') as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line and not line.startswith('#'):
|
if line and not line.startswith('#'):
|
||||||
|
|
|
@ -278,7 +278,7 @@ def parse_tl(file_path, layer, invalid_bot_methods=None):
|
||||||
if invalid_bot_methods is None:
|
if invalid_bot_methods is None:
|
||||||
invalid_bot_methods = set()
|
invalid_bot_methods = set()
|
||||||
|
|
||||||
with open(file_path, encoding='utf-8') as file:
|
with open(file_path, 'r', encoding='utf-8') as file:
|
||||||
is_function = False
|
is_function = False
|
||||||
for line in file:
|
for line in file:
|
||||||
comment_index = line.find('//')
|
comment_index = line.find('//')
|
||||||
|
@ -307,7 +307,7 @@ def parse_tl(file_path, layer, invalid_bot_methods=None):
|
||||||
def find_layer(file_path):
|
def find_layer(file_path):
|
||||||
"""Finds the layer used on the specified scheme.tl file."""
|
"""Finds the layer used on the specified scheme.tl file."""
|
||||||
layer_regex = re.compile(r'^//\s*LAYER\s*(\d+)$')
|
layer_regex = re.compile(r'^//\s*LAYER\s*(\d+)$')
|
||||||
with open(file_path, encoding='utf-8') as file:
|
with open(file_path, 'r', encoding='utf-8') as file:
|
||||||
for line in file:
|
for line in file:
|
||||||
match = layer_regex.match(line)
|
match = layer_regex.match(line)
|
||||||
if match:
|
if match:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user