How to use _get_text method in Robotframework-anywherelibrary

Best Python code snippet using robotframework-anywherelibrary

json_feed.py

Source:json_feed.py Github

copy

Full Screen

...60 return rv61def _get_item(item_dict: dict) -> JSONFeedItem:62 author, authors = _get_author(item_dict)63 return JSONFeedItem(64 id_=_get_text(item_dict, 'id', optional=False),65 url=_get_text(item_dict, 'url'),66 external_url=_get_text(item_dict, 'external_url'),67 title=_get_text(item_dict, 'title'),68 content_html=_get_text(item_dict, 'content_html'),69 content_text=_get_text(item_dict, 'content_text'),70 summary=_get_text(item_dict, 'summary'),71 image=_get_text(item_dict, 'image'),72 banner_image=_get_text(item_dict, 'banner_image'),73 date_published=_get_datetime(item_dict, 'date_published'),74 date_modified=_get_datetime(item_dict, 'date_modified'),75 author=author,76 authors=authors,77 language=_get_text(item_dict, 'language'),78 tags=_get_tags(item_dict, 'tags'),79 attachments=_get_attachments(item_dict, 'attachments')80 )81def _get_attachments(root, name) -> List[JSONFeedAttachment]:82 rv = list()83 for attachment_dict in root.get(name, []):84 rv.append(JSONFeedAttachment(85 _get_text(attachment_dict, 'url', optional=False),86 _get_text(attachment_dict, 'mime_type', optional=False),87 _get_text(attachment_dict, 'title'),88 _get_int(attachment_dict, 'size_in_bytes'),89 _get_duration(attachment_dict, 'duration_in_seconds')90 ))91 return rv92def _get_tags(root, name) -> List[str]:93 tags = root.get(name, [])94 return [tag for tag in tags if isinstance(tag, str)]95def _get_datetime(root: dict, name, optional: bool=True) -> Optional[datetime]:96 text = _get_text(root, name, optional)97 if text is None:98 return None99 return try_parse_date(text)100def _get_expired(root: dict) -> bool:101 if root.get('expired') is True:102 return True103 return False104def _get_author(root: dict) ->\105 Tuple[Optional[JSONFeedAuthor], List[JSONFeedAuthor]]:106 """Retrieve the author/authors of a JSON Feed.107 In JSON Feed version 1.0, only a single author was available and is108 superseded in version 1.1 by the authors key.109 """110 authors = root.get('authors', [])111 if not authors and root.get('author'):112 authors.append(root.get('author'))113 rv = [114 JSONFeedAuthor(115 name=_get_text(author_dict, 'name'),116 url=_get_text(author_dict, 'url'),117 avatar=_get_text(author_dict, 'avatar'),118 )119 for author_dict in authors120 ]121 try:122 return rv[0], rv123 except IndexError:124 return None, rv125def _get_int(root: dict, name: str, optional: bool=True) -> Optional[int]:126 rv = root.get(name)127 if not optional and rv is None:128 raise FeedParseError('Could not parse feed: "{}" int is required but '129 'is empty'.format(name))130 if optional and rv is None:131 return None132 if not isinstance(rv, int):133 raise FeedParseError('Could not parse feed: "{}" is not an int'134 .format(name))135 return rv136def _get_duration(root: dict, name: str,137 optional: bool=True) -> Optional[timedelta]:138 duration = _get_int(root, name, optional)139 if duration is None:140 return None141 return timedelta(seconds=duration)142def _get_text(root: dict, name: str, optional: bool=True) -> Optional[str]:143 rv = root.get(name)144 if not optional and rv is None:145 raise FeedParseError('Could not parse feed: "{}" text is required but '146 'is empty'.format(name))147 if optional and rv is None:148 return None149 if not isinstance(rv, str):150 raise FeedParseError('Could not parse feed: "{}" is not a string'151 .format(name))152 return rv153def parse_json_feed(root: dict) -> JSONFeed:154 author, authors = _get_author(root)155 return JSONFeed(156 version=_get_text(root, 'version', optional=False),157 title=_get_text(root, 'title', optional=False),158 home_page_url=_get_text(root, 'home_page_url'),159 feed_url=_get_text(root, 'feed_url'),160 description=_get_text(root, 'description'),161 user_comment=_get_text(root, 'user_comment'),162 next_url=_get_text(root, 'next_url'),163 icon=_get_text(root, 'icon'),164 favicon=_get_text(root, 'favicon'),165 author=author,166 authors=authors,167 language=_get_text(root, 'language'),168 expired=_get_expired(root),169 items=_get_items(root)170 )171def parse_json_feed_file(filename: str) -> JSONFeed:172 """Parse a JSON feed from a local json file."""173 with open(filename) as f:174 try:175 root = json.load(f)176 except (json.decoder.JSONDecodeError, UnicodeDecodeError):177 raise FeedJSONError('Not a valid JSON document')178 return parse_json_feed(root)179def parse_json_feed_bytes(data: bytes) -> JSONFeed:180 """Parse a JSON feed from a byte-string containing JSON data."""181 try:...

Full Screen

Full Screen

nbxml.py

Source:nbxml.py Github

copy

Full Screen

...36 elem.tail = i37 else:38 if level and (not elem.tail or not elem.tail.strip()):39 elem.tail = i40def _get_text(e, tag):41 sub_e = e.find(tag)42 if sub_e is None:43 return None44 else:45 return sub_e.text46def _set_text(nbnode, attr, parent, tag):47 if attr in nbnode:48 e = ET.SubElement(parent, tag)49 e.text = nbnode[attr]50def _get_int(e, tag):51 sub_e = e.find(tag)52 if sub_e is None:53 return None54 else:55 return int(sub_e.text)56def _set_int(nbnode, attr, parent, tag):57 if attr in nbnode:58 e = ET.SubElement(parent, tag)59 e.text = unicode_type(nbnode[attr])60def _get_bool(e, tag):61 sub_e = e.find(tag)62 if sub_e is None:63 return None64 else:65 return bool(int(sub_e.text))66def _set_bool(nbnode, attr, parent, tag):67 if attr in nbnode:68 e = ET.SubElement(parent, tag)69 if nbnode[attr]:70 e.text = u'1'71 else:72 e.text = u'0'73def _get_binary(e, tag):74 sub_e = e.find(tag)75 if sub_e is None:76 return None77 else:78 return decodestring(sub_e.text)79def _set_binary(nbnode, attr, parent, tag):80 if attr in nbnode:81 e = ET.SubElement(parent, tag)82 e.text = encodestring(nbnode[attr])83class XMLReader(NotebookReader):84 def reads(self, s, **kwargs):85 root = ET.fromstring(s)86 return self.to_notebook(root, **kwargs)87 def to_notebook(self, root, **kwargs):88 warnings.warn('The XML notebook format is no longer supported, '89 'please convert your notebooks to JSON.', DeprecationWarning)90 nbname = _get_text(root,u'name')91 nbauthor = _get_text(root,u'author')92 nbemail = _get_text(root,u'email')93 nblicense = _get_text(root,u'license')94 nbcreated = _get_text(root,u'created')95 nbsaved = _get_text(root,u'saved')96 97 worksheets = []98 for ws_e in root.find(u'worksheets').getiterator(u'worksheet'):99 wsname = _get_text(ws_e,u'name')100 cells = []101 for cell_e in ws_e.find(u'cells').getiterator():102 if cell_e.tag == u'codecell':103 input = _get_text(cell_e,u'input')104 prompt_number = _get_int(cell_e,u'prompt_number')105 collapsed = _get_bool(cell_e,u'collapsed')106 language = _get_text(cell_e,u'language')107 outputs = []108 for output_e in cell_e.find(u'outputs').getiterator(u'output'):109 output_type = _get_text(output_e,u'output_type')110 output_text = _get_text(output_e,u'text')111 output_png = _get_binary(output_e,u'png')112 output_jpeg = _get_binary(output_e,u'jpeg')113 output_svg = _get_text(output_e,u'svg')114 output_html = _get_text(output_e,u'html')115 output_latex = _get_text(output_e,u'latex')116 output_json = _get_text(output_e,u'json')117 output_javascript = _get_text(output_e,u'javascript')118 out_prompt_number = _get_int(output_e,u'prompt_number')119 etype = _get_text(output_e,u'etype')120 evalue = _get_text(output_e,u'evalue')121 traceback = []122 traceback_e = output_e.find(u'traceback')123 if traceback_e is not None:124 for frame_e in traceback_e.getiterator(u'frame'):125 traceback.append(frame_e.text)126 if len(traceback) == 0:127 traceback = None128 output = new_output(output_type=output_type,output_png=output_png,129 output_text=output_text, output_svg=output_svg,130 output_html=output_html, output_latex=output_latex,131 output_json=output_json, output_javascript=output_javascript,132 output_jpeg=output_jpeg, prompt_number=out_prompt_number,133 etype=etype, evalue=evalue, traceback=traceback134 )135 outputs.append(output)136 cc = new_code_cell(input=input,prompt_number=prompt_number,137 language=language,outputs=outputs,collapsed=collapsed)138 cells.append(cc)139 if cell_e.tag == u'htmlcell':140 source = _get_text(cell_e,u'source')141 rendered = _get_text(cell_e,u'rendered')142 cells.append(new_text_cell(u'html', source=source, rendered=rendered))143 if cell_e.tag == u'markdowncell':144 source = _get_text(cell_e,u'source')145 rendered = _get_text(cell_e,u'rendered')146 cells.append(new_text_cell(u'markdown', source=source, rendered=rendered))147 ws = new_worksheet(name=wsname,cells=cells)148 worksheets.append(ws)149 md = new_metadata(name=nbname)150 nb = new_notebook(metadata=md,worksheets=worksheets)151 return nb152 153_reader = XMLReader()154reads = _reader.reads155read = _reader.read...

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 Robotframework-anywherelibrary 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