Skip to content

Commit

Permalink
Applying dimensions fix as per issue (#10)
Browse files Browse the repository at this point in the history
- Image.open takes a full stream and is not reliant on the file path
- The image does not close stream (which causes problems upstream)
- seek(0) to return stream to the beginning
  • Loading branch information
rubicon9 authored Aug 16, 2020
1 parent 6d419dc commit cfdb5a3
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ docs/build
.DS_Store
dist/
build/
__pycache__/
venv/
4 changes: 2 additions & 2 deletions flask_sieve/rules_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ def validate_dimensions(self, value, params, **kwargs):
if not self.validate_file(value):
return False
try:
image = Image.open(value.filename)
image = Image.open(value)
w, h = image.size
image.close()
value.seek(0)
return ('%dx%d' % (w, h)) == params[0]
except Exception:
return False
Expand Down
4 changes: 2 additions & 2 deletions tests/test_rules_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class TestRulesProcessor(unittest.TestCase):
def setUp(self):
self.parser = Parser()
self.processor = RulesProcessor()
self.stream = open('tests/files/image.png')
self.stream = open('tests/files/image.png', 'rb')
self.image_file = FileStorage(
stream=self.stream,
filename='tests/files/image.png',
filename='image.png',
content_type='image/png',
name='image'
)
Expand Down

0 comments on commit cfdb5a3

Please sign in to comment.