New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue2053: improve Image format validation and add html width,height #2178
Conversation
Test results for commit cb206f4 merged into master
Not available for testing: python3.2 |
self.format = unicode(format).lower() | ||
self.embed = embed if embed is not None else (url is None) | ||
|
||
print ('%s %s %s' % (self.format, self._ACCEPTABLE_EMBEDDINGS, 'T' if self.embed else 'F')) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a forgotten debug statement ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, whoops.
On Jul 20, 2012, at 5:17 PM, Bussonnier Matthias wrote:
self.format = unicode(format).lower() self.embed = embed if embed is not None else (url is None)
print ('%s %s %s' % (self.format, self._ACCEPTABLE_EMBEDDINGS, 'T' if self.embed else 'F'))
Is this a forgotten debug statement ?
Reply to this email directly or view it on GitHub:
https://github.com/ipython/ipython/pull/2178/files#r1209612
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you make another commit and push, it will be reflected in this PR, so you can address review like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that I should have commented in here, not outside! I am trying to clean up the thrash below so that I can present you with a clean, simple changeset. There are two small changes I would like to make other than simply deleting the debug statement, but I would rather not have you suffer with all the tripe below.
This seem to work fine for me. |
Hold this without further attention. My redundant code had a purpose, I foolishly reasoned without testing and broke my test, so I have some thinking to do. |
…eight Image now complains if it receives neither filename, url, nor data (param1) test now exhibits graceful behavior
Thanks for the long time trying to rebase :-) |
@@ -464,17 +471,27 @@ def __init__(self, data=None, url=None, filename=None, format=u'png', embed=None | |||
ext = self._find_ext(filename) | |||
elif url is not None: | |||
ext = self._find_ext(url) | |||
elif data is None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This forces the use of at least one argument. I believe this is a good, since otherwise, an errant automated process might manage to invoke Image(None)
Thanks, Matthias and Min! It was great fun to work with you both; thanks for all your patience. I'll spend some time gearing up on git and see if I can't find a few more ways to be helpful. |
Test results for commit 879b843 merged into master
Not available for testing: python3.2 |
Test results for commit 879b843 merged into master
Not available for testing: python2.6 |
I think those failures are unrelated to these changes. If so, I'll have a pull request ready shortly. |
Yep, those failures were something else - I've made PR #2189 for them. |
Anybody against merging ? |
width_by_height.extend(['width="%d"' % self.width]) | ||
if self.height: | ||
width_by_height.extend(['height="%d"' % self.height]) | ||
return u'<img src="%s" %s/>' % (self.url, ' '.join(width_by_height)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we not have any convenience functions for building an HTML tag out of a dictionary? I guess I would have expected us to have something like:
attr = {}
attr['src'] = str(self.url)
if self.width:
attr['width'] = int(self.width)
if self.height:
attr['height'] = int(self.height)
return render_html_tag('img', **attr)
Anyway, in the future this might be written more cleanly as:
width = height = ''
if self.width:
width = 'width="%d" ' % self.width
if self.height:
height = 'height="%d" ' % self.height
return u'<img src="%s" %s%s/>' % (self.url, width, height)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooh, lovely. I looked at the existing string % url code and simply expanded the same style.
I briefly discussed the code with Min, and he graciously ignored the pain in mine.
On Jul 23, 2012, at 10:38 AM, Bradley M. Froehle wrote:
@@ -484,7 +501,12 @@ def reload(self):
def _repr_html_(self): if not self.embed:
return u'<img src="%s" />' % self.url
width_by_height = []
if self.width:
width_by_height.extend(['width="%d"' % self.width])
if self.height:
width_by_height.extend(['height="%d"' % self.height])
return u'<img src="%s" %s/>' % (self.url, ' '.join(width_by_height))
Do we not have any convenience functions for building an HTML tag out of a dictionary? I guess I would have expected us to have something like:
attr = {} attr['src'] = str(self.url) if self.width: attr['width'] = int(self.width) if self.height: attr['height'] = int(self.height) return render_html_tag('img', **attr)Anyway, in the future this might be written more cleanly as:
width = height = '' if self.width: width = 'width="%d" ' % self.width if self.height: height = 'height="%d" ' % self.height return u'<img src="%s" %s%s/>' % (self.url, width, height)
Reply to this email directly or view it on GitHub:
https://github.com/ipython/ipython/pull/2178/files#r1216363
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well then it's fine with me... :)
|
||
def test_image_size(): | ||
"""Simple test for display.Image(args, width=x,height=y)""" | ||
thisurl = 'http://www.google.fr/images/srpr/logo3w.png' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does debian build machines have access to network during build/test time ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, but I don't think this test should actually fetch the image - it's just preparing an HTML <img>
tag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, I should have seen that.
looks great ! |
Test results for commit 879b843 merged into master
Not available for testing: |
@jerryatmda has not forced pushed yet. |
If we want to use https://github.com/ipython/ipython/blob/master/IPython/testing/nose_assert_methods.py |
I would be grateful if you did reopen 2219 and then close this one. 2219 is one clean copy. I won't be able to push --force for a day or two. |
Closing in favor of #2231. |
Merci, Mathieu, I am sorry my newbie-ness and infrequent access to the machine on which my local Thanks Bradley, for your efforts in dragging the code into line. I'll go off and understand git before I inflict any more pain on you all. |
Don't worry about not beeing a git master :) I don't think any of us is, we are just used to it. And the best way to learn is to practice, so don't hesitate to send us more PRs. |
This addresses the first two bullets of #2053
Validates first argument to constrain format to png, jpeg,
Lets user specify width, height, or both and emits appropriate html
I introduced a couple of class constants to minimize the number of times I saw 'jpeg' and 'png'
and document the _ACCEPTABLE_FORMATS.
I added one real jpeg image to the test directory and one zero-length gif file to survive the file not found
error in super()
Thanks, Min, for the coaching, I hope it looks adequate.
Closes #2053