Skip to content

Commit 703b8d1

Browse files
committed
Adding more pre-commit hooks and testing InputFile python-telegram-bot#259
1 parent 46993d5 commit 703b8d1

File tree

4 files changed

+24
-25
lines changed

4 files changed

+24
-25
lines changed

.pre-commit-config.yaml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,16 @@
22
sha: 'v0.7.1'
33
hooks:
44
- id: yapf
5-
args: [-i, -r tests telegram]
5+
args: ['-i', '-r']
6+
7+
- repo: git://github.com/pre-commit/pre-commit-hooks
8+
sha: 'v0.5.0'
9+
hooks:
10+
- id: flake8
11+
args: ['telegram']
12+
13+
- repo: git://github.com/pre-commit/mirrors-pylint
14+
sha: 'v1.5.5'
15+
hooks:
16+
- id: pylint
17+
args: ['--errors-only', '--disable=no-name-in-module,import-error']

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ test:
2828
$(NOSETESTS) -v
2929

3030
install:
31-
$(PIP) install -r requirements.txt
31+
$(PIP) install -r requirements.txt -r requirements-dev.txt
3232

3333
help:
3434
@echo "Available targets:"

requirements-dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ unittest2
66
flaky
77
yapf
88
pre-commit
9+
pre-commit-hooks

telegram/inputfile.py

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#
1818
# You should have received a copy of the GNU Lesser Public License
1919
# along with this program. If not, see [http://www.gnu.org/licenses/].
20-
2120
"""This module contains a object that represents a Telegram InputFile."""
2221

2322
try:
@@ -44,8 +43,7 @@
4443
class InputFile(object):
4544
"""This object represents a Telegram InputFile."""
4645

47-
def __init__(self,
48-
data):
46+
def __init__(self, data):
4947
self.data = data
5048
self.boundary = choose_boundary()
5149

@@ -87,25 +85,22 @@ def __init__(self,
8785
# pylint: disable=E1101
8886
self.filename = os.path.basename(self.input_file.name)
8987
elif from_url:
90-
self.filename = os.path.basename(self.input_file.url) \
91-
.split('?')[0].split('&')[0]
88+
self.filename = os.path.basename(self.input_file.url).split('?')[0].split('&')[0]
9289

9390
try:
9491
self.mimetype = InputFile.is_image(self.input_file_content)
9592
if not self.filename or '.' not in self.filename:
9693
self.filename = self.mimetype.replace('/', '.')
9794
except TelegramError:
98-
self.mimetype = mimetypes.guess_type(self.filename)[0] or \
99-
DEFAULT_MIME_TYPE
95+
self.mimetype = mimetypes.guess_type(self.filename)[0] or DEFAULT_MIME_TYPE
10096

10197
@property
10298
def headers(self):
10399
"""
104100
Returns:
105101
str:
106102
"""
107-
return {'User-agent': USER_AGENT,
108-
'Content-type': self.content_type}
103+
return {'User-agent': USER_AGENT, 'Content-type': self.content_type}
109104

110105
@property
111106
def content_type(self):
@@ -126,21 +121,14 @@ def to_form(self):
126121
# Add data fields
127122
for name, value in self.data.items():
128123
form.extend([
129-
form_boundary,
130-
'Content-Disposition: form-data; name="%s"' % name,
131-
'',
132-
str(value)
124+
form_boundary, 'Content-Disposition: form-data; name="%s"' % name, '', str(value)
133125
])
134126

135127
# Add input_file to upload
136128
form.extend([
137-
form_boundary,
138-
'Content-Disposition: form-data; name="%s"; filename="%s"' % (
129+
form_boundary, 'Content-Disposition: form-data; name="%s"; filename="%s"' % (
139130
self.input_name, self.filename
140-
),
141-
'Content-Type: %s' % self.mimetype,
142-
'',
143-
self.input_file_content
131+
), 'Content-Type: %s' % self.mimetype, '', self.input_file_content
144132
])
145133

146134
form.append('--' + self.boundary + '--')
@@ -193,14 +181,12 @@ def is_inputfile(data):
193181
bool
194182
"""
195183
if data:
196-
file_types = ['audio', 'document', 'photo', 'sticker', 'video',
197-
'voice', 'certificate']
184+
file_types = ['audio', 'document', 'photo', 'sticker', 'video', 'voice', 'certificate']
198185
file_type = [i for i in list(data.keys()) if i in file_types]
199186

200187
if file_type:
201188
file_content = data[file_type[0]]
202189

203-
return hasattr(file_content, 'read') or str(
204-
file_content).startswith('http')
190+
return hasattr(file_content, 'read') or str(file_content).startswith('http')
205191

206192
return False

0 commit comments

Comments
 (0)