Skip to content

Commit

Permalink
Merge pull request #970 from rusko124/fixes_webpage_title_unicode
Browse files Browse the repository at this point in the history
Support unicode for title of webpage asset
  • Loading branch information
vpetersson committed Nov 28, 2018
2 parents a0c512d + dcd5bb7 commit cec9c38
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions tests/viewer_test.py
Expand Up @@ -67,6 +67,9 @@ def test_send(self):
self.u.browser_send('test_cmd')
m_put.assert_called_once_with('test_cmd\n')

self.u.browser_send('event TITLE 标题')
m_put.assert_called_with('event TITLE \xe6\xa0\x87\xe9\xa2\x98\n')

def test_dead(self):
self.p_loadb.start()
self.u.browser_send(None)
Expand Down
12 changes: 8 additions & 4 deletions viewer.py
Expand Up @@ -243,7 +243,7 @@ def load_browser(url=None):

def browser_send(command, cb=lambda _: True):
global browser_focus_lost
fl = lambda e: 'FOCUS_LOST' in unicode(e)
fl = lambda e: 'FOCUS_LOST' in unicode(e.decode('utf-8'))
if not (browser is None) and browser.process.alive:
while not browser.process._pipe_queue.empty(): # flush stdout
browser.next()
Expand All @@ -266,7 +266,9 @@ def browser_send(command, cb=lambda _: True):

def browser_clear(force=False):
"""Load a black page. Default cb waits for the page to load."""
browser_url('file://' + BLACK_PAGE, force=force, cb=lambda buf: 'LOAD_FINISH' in buf and BLACK_PAGE in buf)
browser_url('file://' + BLACK_PAGE, force=force,
cb=lambda buf: 'LOAD_FINISH' in unicode(buf.decode('utf-8')) and
BLACK_PAGE in unicode(buf.decode('utf-8')))


def browser_url(url, cb=lambda _: True, force=False):
Expand All @@ -287,7 +289,9 @@ def browser_url(url, cb=lambda _: True, force=False):

def view_image(uri):
browser_clear()
browser_send('js window.setimg("{0}")'.format(uri), cb=lambda b: 'COMMAND_EXECUTED' in b and 'setimg' in b)
browser_send('js window.setimg("{0}")'.format(uri),
cb=lambda b: 'COMMAND_EXECUTED' in unicode(b.decode('utf-8')) and
'setimg' in unicode(b.decode('utf-8')))


def view_video(uri, duration):
Expand Down Expand Up @@ -408,7 +412,7 @@ def asset_loop(scheduler):
elif 'web' in mime:
# FIXME If we want to force periodic reloads of repeated web assets, force=True could be used here.
# See e38e6fef3a70906e7f8739294ffd523af6ce66be.
browser_url(uri, cb=lambda b: 'LOAD_FINISH' in b)
browser_url(uri, cb=lambda b: 'LOAD_FINISH' in unicode(b.decode('utf-8')))
elif 'video' or 'streaming' in mime:
view_video(uri, asset['duration'])
else:
Expand Down

0 comments on commit cec9c38

Please sign in to comment.