How to use is_live method in hypothesis

Best Python code snippet using hypothesis

messagelistener.py

Source:messagelistener.py Github

copy

Full Screen

1# -*- coding: utf-8 -*-2##########################################################################3# OpenLP - Open Source Lyrics Projection #4# ---------------------------------------------------------------------- #5# Copyright (c) 2008-2020 OpenLP Developers #6# ---------------------------------------------------------------------- #7# This program is free software: you can redistribute it and/or modify #8# it under the terms of the GNU General Public License as published by #9# the Free Software Foundation, either version 3 of the License, or #10# (at your option) any later version. #11# #12# This program is distributed in the hope that it will be useful, #13# but WITHOUT ANY WARRANTY; without even the implied warranty of #14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #15# GNU General Public License for more details. #16# #17# You should have received a copy of the GNU General Public License #18# along with this program. If not, see <https://www.gnu.org/licenses/>. #19##########################################################################20import copy21import logging22from pathlib import Path23from PyQt5 import QtCore24from openlp.core.common.registry import Registry25from openlp.core.lib import ServiceItemContext26from openlp.core.ui import HideMode27from openlp.plugins.presentations.lib.pdfcontroller import PDF_CONTROLLER_FILETYPES28log = logging.getLogger(__name__)29class Controller(object):30 """31 This is the Presentation listener who acts on events from the slide controller and passes the messages on the the32 correct presentation handlers.33 """34 log.info('Controller loaded')35 def __init__(self, live):36 """37 Constructor38 """39 self.is_live = live40 self.doc = None41 self.hide_mode = None42 log.info('{name} controller loaded'.format(name=live))43 def add_handler(self, controller, file, hide_mode, slide_no):44 """45 Add a handler, which is an instance of a presentation and slidecontroller combination. If the slidecontroller46 has a display then load the presentation.47 """48 log.debug('Live = {live}, add_handler {handler}'.format(live=self.is_live, handler=file))49 self.controller = controller50 if self.doc is not None:51 self.shutdown()52 self.doc = self.controller.add_document(file)53 if not self.doc.load_presentation():54 # Display error message to user55 # Inform slidecontroller that the action failed?56 self.doc.slidenumber = 057 return58 self.doc.slidenumber = slide_no59 self.hide_mode = hide_mode60 log.debug('add_handler, slide_number: {slide:d}'.format(slide=slide_no))61 if self.is_live:62 if hide_mode == HideMode.Screen:63 Registry().execute('live_display_hide', HideMode.Screen)64 self.stop()65 elif hide_mode == HideMode.Theme:66 self.blank(hide_mode)67 elif hide_mode == HideMode.Blank:68 self.blank(hide_mode)69 else:70 self.doc.start_presentation()71 Registry().execute('live_display_hide', HideMode.Screen)72 self.doc.slidenumber = 173 if slide_no > 1:74 self.slide(slide_no)75 def activate(self):76 """77 Active the presentation, and show it on the screen. Use the last slide number.78 """79 log.debug('Live = {live}, activate'.format(live=self.is_live))80 if not self.doc:81 return False82 if self.doc.is_active():83 return True84 if not self.doc.is_loaded():85 if not self.doc.load_presentation():86 log.warning('Failed to activate {path}'.format(path=self.doc.file_path))87 return False88 if self.is_live:89 self.doc.start_presentation()90 if self.doc.slidenumber > 1:91 if self.doc.slidenumber > self.doc.get_slide_count():92 self.doc.slidenumber = self.doc.get_slide_count()93 self.doc.goto_slide(self.doc.slidenumber)94 if self.doc.is_active():95 return True96 else:97 log.warning('Failed to activate {path}'.format(path=self.doc.file_path))98 return False99 def slide(self, slide):100 """101 Go to a specific slide102 """103 log.debug('Live = {live}, slide'.format(live=self.is_live))104 if not self.doc:105 return106 if not self.is_live:107 return108 if self.hide_mode:109 self.doc.slidenumber = int(slide) + 1110 self.poll()111 return112 if not self.activate():113 return114 self.doc.goto_slide(int(slide) + 1)115 self.poll()116 def first(self):117 """118 Based on the handler passed at startup triggers the first slide.119 """120 log.debug('Live = {live}, first'.format(live=self.is_live))121 if not self.doc:122 return123 if not self.is_live:124 return125 if self.hide_mode:126 self.doc.slidenumber = 1127 self.poll()128 return129 if not self.activate():130 return131 self.doc.start_presentation()132 self.poll()133 def last(self):134 """135 Based on the handler passed at startup triggers the last slide.136 """137 log.debug('Live = {live}, last'.format(live=self.is_live))138 if not self.doc:139 return140 if not self.is_live:141 return142 if self.hide_mode:143 self.doc.slidenumber = self.doc.get_slide_count()144 self.poll()145 return146 if not self.activate():147 return148 self.doc.goto_slide(self.doc.get_slide_count())149 self.poll()150 def next(self):151 """152 Based on the handler passed at startup triggers the next slide event.153 """154 log.debug('Live = {live}, next'.format(live=self.is_live))155 if not self.doc:156 return False157 if not self.is_live:158 return False159 if self.hide_mode:160 if not self.doc.is_active():161 return False162 if self.doc.slidenumber < self.doc.get_slide_count():163 self.doc.slidenumber += 1164 self.poll()165 return False166 if not self.activate():167 return False168 ret = self.doc.next_step()169 self.poll()170 return ret171 def previous(self):172 """173 Based on the handler passed at startup triggers the previous slide event.174 """175 log.debug('Live = {live}, previous'.format(live=self.is_live))176 if not self.doc:177 return False178 if not self.is_live:179 return False180 if self.hide_mode:181 if not self.doc.is_active():182 return False183 if self.doc.slidenumber > 1:184 self.doc.slidenumber -= 1185 self.poll()186 return False187 if not self.activate():188 return False189 ret = self.doc.previous_step()190 self.poll()191 return ret192 def shutdown(self):193 """194 Based on the handler passed at startup triggers slide show to shut down.195 """196 log.debug('Live = {live}, shutdown'.format(live=self.is_live))197 if not self.doc:198 return199 self.doc.close_presentation()200 self.doc = None201 def blank(self, hide_mode):202 """203 Instruct the controller to blank the presentation.204 """205 log.debug('Live = {live}, blank'.format(live=self.is_live))206 self.hide_mode = hide_mode207 if not self.doc:208 return209 if not self.is_live:210 return211 if hide_mode == HideMode.Theme:212 if not self.doc.is_loaded():213 return214 if not self.doc.is_active():215 return216 Registry().execute('live_display_hide', HideMode.Theme)217 elif hide_mode == HideMode.Blank:218 if not self.activate():219 return220 self.doc.blank_screen()221 def stop(self):222 """223 Instruct the controller to stop and hide the presentation.224 """225 log.debug('Live = {live}, stop'.format(live=self.is_live))226 # The document has not been loaded yet, so don't do anything. This can happen when going live with a227 # presentation while blanked to desktop.228 if not self.doc:229 return230 # Save the current slide number to be able to return to this slide if the presentation is activated again.231 if self.doc.is_active():232 self.doc.slidenumber = self.doc.get_slide_number()233 self.hide_mode = HideMode.Screen234 if not self.doc:235 return236 if not self.is_live:237 return238 if not self.doc.is_loaded():239 return240 if not self.doc.is_active():241 return242 self.doc.stop_presentation()243 def unblank(self):244 """245 Instruct the controller to unblank the presentation.246 """247 log.debug('Live = {live}, unblank'.format(live=self.is_live))248 self.hide_mode = None249 if not self.doc:250 return251 if not self.is_live:252 return253 if not self.activate():254 return255 self.doc.unblank_screen()256 Registry().execute('live_display_hide', HideMode.Screen)257 def poll(self):258 if not self.doc:259 return260 self.doc.poll_slidenumber(self.is_live, self.hide_mode)261class MessageListener(object):262 """263 This is the Presentation listener who acts on events from the slide controller and passes the messages on the264 correct presentation handlers265 """266 log.info('Message Listener loaded')267 def __init__(self, media_item):268 self._setup(media_item)269 def _setup(self, media_item):270 """271 Start up code moved out to make mocking easier272 :param media_item: The plugin media item handing Presentations273 """274 self.controllers = media_item.controllers275 self.media_item = media_item276 self.preview_handler = Controller(False)277 self.live_handler = Controller(True)278 # messages are sent from core.ui.slidecontroller279 Registry().register_function('presentations_start', self.startup)280 Registry().register_function('presentations_stop', self.shutdown)281 Registry().register_function('presentations_hide', self.hide)282 Registry().register_function('presentations_first', self.first)283 Registry().register_function('presentations_previous', self.previous)284 Registry().register_function('presentations_next', self.next)285 Registry().register_function('presentations_last', self.last)286 Registry().register_function('presentations_slide', self.slide)287 Registry().register_function('presentations_blank', self.blank)288 Registry().register_function('presentations_unblank', self.unblank)289 self.timer = QtCore.QTimer()290 self.timer.setInterval(500)291 self.timer.timeout.connect(self.timeout)292 def startup(self, message):293 """294 Start of new presentation. Save the handler as any new presentations start here295 """296 log.debug('Startup called with message {text}'.format(text=message))297 is_live = message[1]298 item = message[0]299 hide_mode = message[2]300 file_path = Path(item.get_frame_path())301 self.handler = item.processor302 # When starting presentation from the servicemanager we convert303 # PDF/XPS/OXPS-serviceitems into image-serviceitems. When started from the mediamanager304 # the conversion has already been done at this point.305 file_type = file_path.suffix.lower()[1:]306 if file_type in PDF_CONTROLLER_FILETYPES:307 log.debug('Converting from pdf/xps/oxps/epub/cbz/fb2 to images for serviceitem with file {name}'308 .format(name=file_path))309 # Create a copy of the original item, and then clear the original item so it can be filled with images310 item_cpy = copy.copy(item)311 item.__init__(None)312 context = ServiceItemContext.Live if is_live else ServiceItemContext.Preview313 self.media_item.generate_slide_data(item, item=item_cpy, context=context, file_path=file_path)314 # Some of the original serviceitem attributes is needed in the new serviceitem315 item.footer = item_cpy.footer316 item.from_service = item_cpy.from_service317 item.iconic_representation = item_cpy.icon318 item.image_border = item_cpy.image_border319 item.main = item_cpy.main320 item.theme_data = item_cpy.theme_data321 # When presenting PDF/XPS/OXPS, we are using the image presentation code,322 # so handler & processor is set to None, and we skip adding the handler.323 self.handler = None324 else:325 if self.handler == self.media_item.automatic:326 self.handler = self.media_item.find_controller_by_type(file_path)327 if not self.handler:328 return329 else:330 # the saved handler is not present so need to use one based on file_path suffix.331 if not self.controllers[self.handler].available:332 self.handler = self.media_item.find_controller_by_type(file_path)333 if not self.handler:334 return335 if is_live:336 controller = self.live_handler337 else:338 controller = self.preview_handler339 # When presenting PDF/XPS/OXPS, we are using the image presentation code,340 # so handler & processor is set to None, and we skip adding the handler.341 if self.handler is None:342 self.controller = controller343 else:344 controller.add_handler(self.controllers[self.handler], file_path, hide_mode, message[3])345 self.timer.start()346 def slide(self, message):347 """348 React to the message to move to a specific slide.349 :param message: The message {1} is_live {2} slide350 """351 is_live = message[1]352 slide = message[2]353 if is_live:354 self.live_handler.slide(slide)355 else:356 self.preview_handler.slide(slide)357 def first(self, message):358 """359 React to the message to move to the first slide.360 :param message: The message {1} is_live361 """362 is_live = message[1]363 if is_live:364 self.live_handler.first()365 else:366 self.preview_handler.first()367 def last(self, message):368 """369 React to the message to move to the last slide.370 :param message: The message {1} is_live371 """372 is_live = message[1]373 if is_live:374 self.live_handler.last()375 else:376 self.preview_handler.last()377 def next(self, message):378 """379 React to the message to move to the next animation/slide.380 :param message: The message {1} is_live381 """382 is_live = message[1]383 if is_live:384 ret = self.live_handler.next()385 if Registry().get('settings').value('core/click live slide to unblank'):386 Registry().execute('slidecontroller_live_unblank')387 return ret388 else:389 return self.preview_handler.next()390 def previous(self, message):391 """392 React to the message to move to the previous animation/slide.393 :param message: The message {1} is_live394 """395 is_live = message[1]396 if is_live:397 ret = self.live_handler.previous()398 if Registry().get('settings').value('core/click live slide to unblank'):399 Registry().execute('slidecontroller_live_unblank')400 return ret401 else:402 return self.preview_handler.previous()403 def shutdown(self, message):404 """405 React to message to shutdown the presentation. I.e. end the show and close the file.406 :param message: The message {1} is_live407 """408 is_live = message[1]409 if is_live:410 self.live_handler.shutdown()411 self.timer.stop()412 else:413 self.preview_handler.shutdown()414 def hide(self, message):415 """416 React to the message to show the desktop.417 :param message: The message {1} is_live418 """419 is_live = message[1]420 if is_live:421 self.live_handler.stop()422 def blank(self, message):423 """424 React to the message to blank the display.425 :param message: The message {1} is_live {2} slide426 """427 is_live = message[1]428 hide_mode = message[2]429 if is_live:430 self.live_handler.blank(hide_mode)431 def unblank(self, message):432 """433 React to the message to unblank the display.434 :param message: The message {1} is_live435 """436 is_live = message[1]437 if is_live:438 self.live_handler.unblank()439 def timeout(self):440 """441 The presentation may be timed or might be controlled by the application directly, rather than through OpenLP.442 Poll occasionally to check which slide is currently displayed so the slidecontroller view can be updated.443 """...

Full Screen

Full Screen

tvnet.py

Source:tvnet.py Github

copy

Full Screen

1# coding: utf-82from __future__ import unicode_literals3import re4from .common import InfoExtractor5from ..utils import (6 int_or_none,7 unescapeHTML,8 url_or_none,9)10class TVNetIE(InfoExtractor):11 _VALID_URL = r'https?://(?:[^/]+)\.tvnet\.gov\.vn/[^/]+/(?:\d+/)?(?P<id>\d+)(?:/|$)'12 _TESTS = [{13 # video14 'url': 'http://de.tvnet.gov.vn/video/109788/vtv1---bac-tuyet-tai-lao-cai-va-ha-giang/tin-nong-24h',15 'md5': 'b4d7abe0252c9b47774760b7519c7558',16 'info_dict': {17 'id': '109788',18 'ext': 'mp4',19 'title': 'VTV1 - Bắc tuyết tại Lào Cai và Hà Giang',20 'thumbnail': r're:(?i)https?://.*\.(?:jpg|png)',21 'is_live': False,22 'view_count': int,23 },24 }, {25 # audio26 'url': 'http://vn.tvnet.gov.vn/radio/27017/vov1---ban-tin-chieu-10062018/doi-song-va-xa-hoi',27 'md5': 'b5875ce9b0a2eecde029216d0e6db2ae',28 'info_dict': {29 'id': '27017',30 'ext': 'm4a',31 'title': 'VOV1 - Bản tin chiều (10/06/2018)',32 'thumbnail': r're:(?i)https?://.*\.(?:jpg|png)',33 'is_live': False,34 },35 }, {36 'url': 'http://us.tvnet.gov.vn/video/118023/129999/ngay-0705',37 'info_dict': {38 'id': '129999',39 'ext': 'mp4',40 'title': 'VTV1 - Quốc hội với cử tri (11/06/2018)',41 'thumbnail': r're:(?i)https?://.*\.(?:jpg|png)',42 'is_live': False,43 },44 'params': {45 'skip_download': True,46 },47 }, {48 # live stream49 'url': 'http://us.tvnet.gov.vn/kenh-truyen-hinh/1011/vtv1',50 'info_dict': {51 'id': '1011',52 'ext': 'mp4',53 'title': r're:^VTV1 \| LiveTV [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',54 'thumbnail': r're:(?i)https?://.*\.(?:jpg|png)',55 'is_live': True,56 },57 'params': {58 'skip_download': True,59 },60 }, {61 # radio live stream62 'url': 'http://vn.tvnet.gov.vn/kenh-truyen-hinh/1014',63 'info_dict': {64 'id': '1014',65 'ext': 'm4a',66 'title': r're:VOV1 \| LiveTV [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',67 'thumbnail': r're:(?i)https?://.*\.(?:jpg|png)',68 'is_live': True,69 },70 'params': {71 'skip_download': True,72 },73 }, {74 'url': 'http://us.tvnet.gov.vn/phim/6136/25510/vtv3---ca-mot-doi-an-oan-tap-1-50/phim-truyen-hinh',75 'only_matching': True,76 }]77 def _real_extract(self, url):78 video_id = self._match_id(url)79 webpage = self._download_webpage(url, video_id)80 title = self._og_search_title(81 webpage, default=None) or self._html_search_meta(82 'title', webpage, default=None) or self._search_regex(83 r'<title>([^<]+)<', webpage, 'title')84 title = re.sub(r'\s*-\s*TV Net\s*$', '', title)85 if '/video/' in url or '/radio/' in url:86 is_live = False87 elif '/kenh-truyen-hinh/' in url:88 is_live = True89 else:90 is_live = None91 data_file = unescapeHTML(self._search_regex(92 r'data-file=(["\'])(?P<url>(?:https?:)?//.+?)\1', webpage,93 'data file', group='url'))94 stream_urls = set()95 formats = []96 for stream in self._download_json(data_file, video_id):97 if not isinstance(stream, dict):98 continue99 stream_url = url_or_none(stream.get('url'))100 if stream_url in stream_urls or not stream_url:101 continue102 stream_urls.add(stream_url)103 formats.extend(self._extract_m3u8_formats(104 stream_url, video_id, 'mp4',105 entry_protocol='m3u8' if is_live else 'm3u8_native',106 m3u8_id='hls', fatal=False))107 self._sort_formats(formats)108 # better support for radio streams109 if title.startswith('VOV'):110 for f in formats:111 f.update({112 'ext': 'm4a',113 'vcodec': 'none',114 })115 thumbnail = self._og_search_thumbnail(116 webpage, default=None) or unescapeHTML(117 self._search_regex(118 r'data-image=(["\'])(?P<url>(?:https?:)?//.+?)\1', webpage,119 'thumbnail', default=None, group='url'))120 if is_live:121 title = self._live_title(title)122 view_count = int_or_none(self._search_regex(123 r'(?s)<div[^>]+\bclass=["\'].*?view-count[^>]+>.*?(\d+).*?</div>',124 webpage, 'view count', default=None))125 return {126 'id': video_id,127 'title': title,128 'thumbnail': thumbnail,129 'is_live': is_live,130 'view_count': view_count,131 'formats': formats,...

Full Screen

Full Screen

rest_set_live_req_body.py

Source:rest_set_live_req_body.py Github

copy

Full Screen

...28 self._is_live = None29 self.discriminator = None30 self.is_live = is_live31 @property32 def is_live(self):33 """Gets the is_live of this RestSetLiveReqBody.34 默认值为0。 - 0: 停止会议直播。 - 1: 启动会议直播。35 :return: The is_live of this RestSetLiveReqBody.36 :rtype: int37 """38 return self._is_live39 @is_live.setter40 def is_live(self, is_live):41 """Sets the is_live of this RestSetLiveReqBody.42 默认值为0。 - 0: 停止会议直播。 - 1: 启动会议直播。43 :param is_live: The is_live of this RestSetLiveReqBody.44 :type is_live: int45 """46 self._is_live = is_live47 def to_dict(self):48 """Returns the model properties as a dict"""49 result = {}50 for attr, _ in six.iteritems(self.openapi_types):51 value = getattr(self, attr)52 if isinstance(value, list):53 result[attr] = list(map(54 lambda x: x.to_dict() if hasattr(x, "to_dict") else x,...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run hypothesis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful