How to use translator method in autotest

Best Python code snippet using autotest_python

library.py

Source:library.py Github

copy

Full Screen

1from __future__ import unicode_literals2import logging3from mopidy import backend4from mopidy.models import Ref, SearchResult, Image5from mopidy_radiobrowser import translator6logger = logging.getLogger(__name__)7class RadioBrowserLibrary(backend.LibraryProvider):8 root_directory = Ref.directory(uri='radiobrowser:root', name='RadioBrowser')9 def __init__(self, backend):10 logger.debug('RadioBrowser: Start backend.RadioBrowserLibrary.__init__')11 super(RadioBrowserLibrary, self).__init__(backend)12 def browse(self, uri):13 logger.debug('RadioBrowser: Start backend.RadioBrowserLibrary.browse')14 result = []15 variant, identifier = translator.parse_uri(uri)16 logger.debug('RadioBrowser: Browsing %s' % uri)17 if variant == 'root':18 # root list: all categies19 for category in self.backend.radiobrowser.getCategories():20 result.append(translator.category_to_ref(category))21 elif "category" == variant:22 if "countries" == identifier:23 countries = self.backend.radiobrowser.browseCategory(identifier)24 for country in countries:25 translator.country_add_name(country)26 for country in sorted(countries, key = lambda i: i['translated_name']):27 ret = self.backend.radiobrowser.addCountry(country)28 if True == ret:29 result.append(translator.country_to_ref(country))30 elif "languages" == identifier:31 languages = self.backend.radiobrowser.browseCategory(identifier)32 for language in languages:33 ret = self.backend.radiobrowser.addLanguage(language)34 if True == ret:35 result.append(translator.language_to_ref(language))36 elif "tags" == identifier:37 tags = self.backend.radiobrowser.browseCategory(identifier)38 for tag in tags:39 ret = self.backend.radiobrowser.addTag(tag)40 if True == ret:41 result.append(translator.tag_to_ref(tag))42 elif "clicks" == identifier:43 stations = self.backend.radiobrowser.browseCategory(identifier)44 for station in stations:45 ret = self.backend.radiobrowser.addStation(station)46 if True == ret:47 result.append(translator.station_to_ref(station))48 elif "votes" == identifier:49 stations = self.backend.radiobrowser.browseCategory(identifier)50 for station in stations:51 ret = self.backend.radiobrowser.addStation(station)52 if True == ret:53 result.append(translator.station_to_ref(station))54 else:55 logger.debug('RadioBrowser: Unknown URI: %s', uri)56 elif variant == "tag" and identifier:57 tag = self.backend.radiobrowser.getTag(identifier)58 stations = self.backend.radiobrowser.stations(tag)59 for station in stations:60 self.backend.radiobrowser.addStation(station)61 result.append(translator.station_to_ref(station))62 elif variant == "language" and identifier:63 language = self.backend.radiobrowser.getLanguage(identifier)64 stations = self.backend.radiobrowser.stations(language)65 for station in stations:66 self.backend.radiobrowser.addStation(station)67 result.append(translator.station_to_ref(station))68 elif variant == "country" and identifier:69 country = self.backend.radiobrowser.getCountry(identifier)70 states = self.backend.radiobrowser.browseDirectory(country)71 emptyState = {72 'name': country['a2'],73 'country': country['a2'],74 'stationcount' : 175 }76 states.append(emptyState)77 for state in states:78 ret = self.backend.radiobrowser.addState(state)79 if True == ret:80 result.append(translator.state_to_ref(state))81 elif variant == "state" and identifier:82 state = self.backend.radiobrowser.getState(identifier)83 stations = self.backend.radiobrowser.stations(state)84 for station in stations:85 if (state['name'] == state['country']):86 if ('' == station['state']):87 continue88 self.backend.radiobrowser.addStation(station)89 result.append(translator.station_to_ref(station))90 else:91 logger.debug('RadioBrowser: Unknown URI: %s', uri)92 return result93 def refresh(self, uri=None):94 logger.debug('RadioBrowser: Start backend.RadioBrowserLibrary.refresh')95 self.backend.radiobrowser.reload()96 def lookup(self, uri):97 logger.debug('RadioBrowser: Start backend.RadioBrowserLibrary.lookup')98 variant, identifier = translator.parse_uri(uri)99 if variant != 'station':100 return []101 station = self.backend.radiobrowser.getStation(identifier)102 if not station:103 return []104 track = translator.station_to_track(station)105 return [track]106 def search(self, query=None, uris=None, exact=False):107 logger.debug('RadioBrowser: Start backend.RadioBrowserLibrary.search')108 if query is None or not query:109 return110 radiobrowser_query = translator.mopidy_to_radiobrowser_query(query)111 tracks = []112 stations = self.backend.radiobrowser.search(radiobrowser_query)113 for station in stations:114 self.backend.radiobrowser.addStation(station)115 track = translator.station_to_track(station)116 tracks.append(track)117 return SearchResult(uri='radiobrowser:search', tracks=tracks)118 119 def get_images(self, uris):120 logger.debug('RadioBrowser: Start backend.RadioBrowserLibrary.get_images')121 result = {}122 for uri in uris:123 variant, identifier = translator.parse_uri(uri)124 if variant != 'station':125 continue126 station = self.backend.radiobrowser.getStation(identifier)127 if not station:128 continue129 130 result[uri] = [Image(uri=station.get('favicon'))]131 return result132class RadioBrowserPlayback(backend.PlaybackProvider):133 def translate_uri(self, uri):134 logger.debug('RadioBrowser: Start backend.RadioBrowserPlayback.translate_uri')135 identifier = translator.parse_uri(uri)136 if identifier[0] == 'station':137 station = self.backend.radiobrowser.getStation(identifier[1])138 else:139 station = self.backend.radiobrowser.getStation(identifier[0])140 if not station:141 return None142 stream_uris = self.backend.radiobrowser.tune(station)143 while stream_uris:144 uri = stream_uris.pop(0)145 logger.debug('RadioBrowser: Looking up URI: %s.' % uri)146 if uri:147 return uri148 logger.debug('RadioBrowser: RadioBrowser lookup failed.')...

Full Screen

Full Screen

extract.py

Source:extract.py Github

copy

Full Screen

1import re2from mako import compat3from mako import lexer4from mako import parsetree5class MessageExtractor(object):6 def process_file(self, fileobj):7 template_node = lexer.Lexer(8 fileobj.read(),9 input_encoding=self.config['encoding']).parse()10 for extracted in self.extract_nodes(template_node.get_children()):11 yield extracted12 def extract_nodes(self, nodes):13 translator_comments = []14 in_translator_comments = False15 comment_tags = list(16 filter(None, re.split(r'\s+', self.config['comment-tags'])))17 for node in nodes:18 child_nodes = None19 if in_translator_comments and \20 isinstance(node, parsetree.Text) and \21 not node.content.strip():22 # Ignore whitespace within translator comments23 continue24 if isinstance(node, parsetree.Comment):25 value = node.text.strip()26 if in_translator_comments:27 translator_comments.extend(28 self._split_comment(node.lineno, value))29 continue30 for comment_tag in comment_tags:31 if value.startswith(comment_tag):32 in_translator_comments = True33 translator_comments.extend(34 self._split_comment(node.lineno, value))35 continue36 if isinstance(node, parsetree.DefTag):37 code = node.function_decl.code38 child_nodes = node.nodes39 elif isinstance(node, parsetree.BlockTag):40 code = node.body_decl.code41 child_nodes = node.nodes42 elif isinstance(node, parsetree.CallTag):43 code = node.code.code44 child_nodes = node.nodes45 elif isinstance(node, parsetree.PageTag):46 code = node.body_decl.code47 elif isinstance(node, parsetree.CallNamespaceTag):48 code = node.expression49 child_nodes = node.nodes50 elif isinstance(node, parsetree.ControlLine):51 if node.isend:52 in_translator_comments = False53 continue54 code = node.text55 elif isinstance(node, parsetree.Code):56 in_translator_comments = False57 code = node.code.code58 elif isinstance(node, parsetree.Expression):59 code = node.code.code60 else:61 continue62 # Comments don't apply unless they immediately preceed the message63 if translator_comments and \64 translator_comments[-1][0] < node.lineno - 1:65 translator_comments = []66 translator_strings = [67 comment[1] for comment in translator_comments]68 if isinstance(code, compat.text_type):69 code = code.encode('ascii', 'backslashreplace')70 used_translator_comments = False71 code = compat.byte_buffer(code)72 for message in self.process_python(73 code, node.lineno, translator_strings):74 yield message75 used_translator_comments = True76 if used_translator_comments:77 translator_comments = []78 in_translator_comments = False79 if child_nodes:80 for extracted in self.extract_nodes(child_nodes):81 yield extracted82 @staticmethod83 def _split_comment(lineno, comment):84 """Return the multiline comment at lineno split into a list of85 comment line numbers and the accompanying comment line"""86 return [(lineno + index, line) for index, line in...

Full Screen

Full Screen

myapi.py

Source:myapi.py Github

copy

Full Screen

1#imports-----------------------2from fastapi import FastAPI3import inflect4from googletrans import *5from fastapi.middleware.cors import CORSMiddleware6#Translate Instance------------7translator = Translator()89#Instances---------------------10app = FastAPI()1112#CORS Handling13# origins = [14# "http://localhost.tiangolo.com",15# "https://localhost.tiangolo.com",16# "http://localhost",17# "http://localhost:8080",18# ]1920# The url you trying to get request from, if it _ _ _ _ _ _ _ _21app.add_middleware(22 CORSMiddleware,23 allow_origins=["https://sgapco.sowaanerp.com"],24 allow_credentials=True,25 allow_methods=["*"],26 allow_headers=["*"],27)2829x = inflect.engine()3031#Main -------------------------32@app.get("/")33def index():34 return 'Welcome to my A.P.I --UPDATED'3536@app.get("/test")37def test():38 return '<-----Endpoints Working Fine----->'3940@app.get('/get-result/{lang}/{value}')41def get_result(value: str, lang: str):4243 #input = value.split(".")44 #number, decimal = int(input[0]),int(input[1])4546 # [ Conditiion for values like: '5000' ]47 if value.isdecimal()==True:48 number= int(value)4950 op1= x.number_to_words(number)5152 if lang =='ar':53 ar_op = translator.translate(op1, dest='ar').text+" "+translator.translate('SAR', dest='ar').text54 return ar_op55 else:56 en_op = op1+' SAR'57 return en_op58 else:5960 input = value.split(".")61 number, decimal = int(input[0]),int(input[1])62 63 # [ Conditiion for values like: '50.9' ]64 if (len(input[1])==1):65 #print("This One working")66 decimal = str(decimal)+'0'67 decimal = int(decimal)68 op1,op2 = x.number_to_words(number),x.number_to_words(decimal)6970 if lang =='ar':71 ar_op = translator.translate(op1, dest='ar').text+" "+translator.translate('SAR', dest='ar').text+" "+translator.translate(op2, dest='ar').text+" هللة"72 return ar_op73 else:74 en_op = op1+' SAR and ' +op2+' halalah'#translator.translate(op1, dest='ar').text+" "+translator.translate('SAR', dest='ar').text+" "+translator.translate(op2, dest='ar').text+" هللة"75 return en_op7677 78 elif input[1][0]=='0':79 op1,op2 = x.number_to_words(number),x.number_to_words(decimal)8081 if lang =='ar':82 ar_op = translator.translate(op1, dest='ar').text+" "+translator.translate('SAR', dest='ar').text+" "+translator.translate(op2, dest='ar').text+" هللة"83 return ar_op84 else:85 en_op = op1+' SAR and ' +op2+' halalah'#translator.translate(op1, dest='ar').text+" "+translator.translate('SAR', dest='ar').text+" "+translator.translate(op2, dest='ar').text+" هللة"86 return en_op87 88 else:89 op1,op2 = x.number_to_words(number),x.number_to_words(decimal)9091 if lang =='ar':92 ar_op = translator.translate(op1, dest='ar').text+" "+translator.translate('SAR', dest='ar').text+" "+translator.translate(op2, dest='ar').text+" هللة"93 return ar_op94 else:95 en_op = op1+' SAR and ' +op2+' halalah'#translator.translate(op1, dest='ar').text+" "+translator.translate('SAR', dest='ar').text+" "+translator.translate(op2, dest='ar').text+" هللة"96 return en_op ...

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 autotest 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