How to use getLocalizedName method in pyatom

Best Python code snippet using pyatom_python

webplugins.py

Source:webplugins.py Github

copy

Full Screen

1#!/usr/bin/env python2# Copyright 2011 Google Inc. All Rights Reserved.3"""Parser for Google chrome/chromium History files."""4import json5import os.path6import logging7from grr.lib import aff48from grr.lib import flow9from grr.lib import flow_utils10from grr.lib import rdfvalue11from grr.lib import utils12from grr.proto import flows_pb213class ChromePluginsArgs(rdfvalue.RDFProtoStruct):14 protobuf = flows_pb2.ChromePluginsArgs15class ChromePlugins(flow.GRRFlow):16 r"""Extract information about the installed Chrome extensions.17 Default directories as per:18 http://www.chromium.org/user-experience/user-data-directory19 Windows XP20 Google Chrome:21 c:\Documents and Settings\<username>\Local Settings\22 Application Data\Google\Chrome\User Data\Default\Extensions23 Windows 7 or Vista24 c:\Users\<username>\AppData\Local\Google\Chrome\User Data\Default\Extensions25 Mac OS X26 /Users/<user>/Library/Application Support/Google/Chrome/Default/Extensions27 Linux28 /home/<user>/.config/google-chrome/Default/Extensions29 """30 category = "/Browser/"31 args_type = ChromePluginsArgs32 behaviours = flow.GRRFlow.behaviours + "BASIC"33 @flow.StateHandler(next_state=["EnumerateExtensionDirs"])34 def Start(self):35 """Determine the Chrome directory."""36 self.state.Register("storage", {})37 if self.args.path:38 paths = [self.args.path]39 elif self.args.username:40 paths = self.GuessExtensionPaths(self.args.username)41 if not paths:42 raise flow.FlowError("No valid extension paths found.")43 for path in paths:44 rel_path = utils.JoinPath(path, "Extensions")45 pathspec = rdfvalue.PathSpec(path=rel_path,46 pathtype=self.args.pathtype)47 self.CallClient("ListDirectory", next_state="EnumerateExtensionDirs",48 pathspec=pathspec)49 @flow.StateHandler(next_state=["EnumerateVersions"])50 def EnumerateExtensionDirs(self, responses):51 """Enumerates all extension directories."""52 if responses.success:53 for response in responses:54 chromeid = os.path.basename(response.pathspec.last.path)55 self.state.storage[chromeid] = {}56 self.CallClient("ListDirectory", next_state="EnumerateVersions",57 pathspec=response.pathspec)58 @flow.StateHandler(next_state=["GetExtensionName"])59 def EnumerateVersions(self, responses):60 """Enumerates all extension version directories."""61 if responses.success:62 pathspecs = []63 for response in responses:64 # Get the json manifest.65 pathspec = response.pathspec66 pathspec.Append(pathtype=self.args.pathtype, path="manifest.json")67 pathspecs.append(pathspec)68 self.CallFlow("MultiGetFile", next_state="GetExtensionName",69 pathspecs=pathspecs)70 @flow.StateHandler(next_state=["GetLocalizedName", "Done"])71 def GetExtensionName(self, responses):72 """Gets the name of the extension from the manifest."""73 if responses.success:74 # The pathspec to the manifest file75 file_stat = responses.First()76 extension_directory = file_stat.pathspec.Dirname()77 # Read the manifest file which should be just json - already stored in78 fd = aff4.FACTORY.Open(file_stat.aff4path, token=self.token)79 try:80 manifest_data = fd.read(1000000)81 manifest = json.loads(manifest_data)82 except ValueError:83 self.Log("Unable to parse %s as json. Continuing.", fd.urn)84 return85 ext_name = manifest.get("name", "")86 if ext_name.startswith("__MSG_"):87 # Extension has a localized name88 if "default_locale" in manifest:89 msg_path = extension_directory.Copy().Append(90 pathtype=self.args.pathtype,91 path="_locales/" + manifest["default_locale"] + "/messages.json")92 request_data = dict(93 manifest_data=manifest_data,94 extension_directory=extension_directory)95 self.CallFlow("GetFile", next_state="GetLocalizedName",96 pathspec=msg_path, request_data=request_data)97 return98 else:99 logging.error("Malformed extension %s, missing default_locale.",100 extension_directory.CollapsePath())101 # Continue with __MSG_... extension name102 self.CreateAnalysisVFile(extension_directory, manifest)103 if self.args.download_files:104 self.CallFlow("FetchFiles", next_state="Done",105 findspec=rdfvalue.FindSpec(pathspec=extension_directory,106 max_depth=3, path_glob="*"))107 @flow.StateHandler(next_state="Done")108 def GetLocalizedName(self, responses):109 """Determines the name of the extension if the extension uses locales."""110 if responses.success:111 manifest = json.loads(responses.request_data["manifest_data"])112 extension_directory = responses.request_data["extension_directory"]113 # Parse the locale json.114 urn = aff4.AFF4Object.VFSGRRClient.PathspecToURN(115 responses.First().pathspec, self.client_id)116 fd = aff4.FACTORY.Open(urn, token=self.token)117 msg = manifest["name"][6:].rstrip("_")118 try:119 messages = json.loads(fd.read(1000000))120 # Update the extension name from the locale messages121 manifest["name"] = messages[msg]["message"]122 except (ValueError, KeyError):123 pass124 else:125 logging.error("Malformed extension: localization file not found (%s).",126 manifest["name"])127 self.CreateAnalysisVFile(extension_directory, manifest)128 if self.args.download_files:129 self.CallFlow("FetchFiles", next_state="Done",130 findspec=rdfvalue.FindSpec(pathspec=extension_directory,131 max_depth=3, path_glob="*"))132 def CreateAnalysisVFile(self, extension_directory, manifest):133 """Creates the analysis result object."""134 if not self.runner.output:135 return136 version = manifest.get("version", extension_directory.Basename())137 chromeid = extension_directory.Dirname().Basename()138 name = manifest.get("name", "unknown_" + chromeid)139 ext_urn = self.runner.output.urn.Add(name).Add(version)140 fd = aff4.FACTORY.Create(ext_urn, "VFSBrowserExtension",141 token=self.token)142 fd.Set(fd.Schema.NAME(name))143 fd.Set(fd.Schema.VERSION(version))144 fd.Set(fd.Schema.CHROMEID(chromeid))145 if "update_url" in manifest:146 fd.Set(fd.Schema.UPDATEURL(manifest["update_url"]))147 if "permissions" in manifest:148 fd.Set(fd.Schema.PERMISSIONS(";".join(manifest["permissions"])))149 fd.Set(fd.Schema.EXTENSIONDIR(extension_directory.last.path))150 fd.Close()151 @flow.StateHandler()152 def Done(self, responses):153 if not responses.success:154 logging.error("Error downloading directory recursively.")155 def GuessExtensionPaths(self, user):156 """Take a user and return guessed full paths to Extension files.157 Args:158 user: Username as string.159 Returns:160 A list of strings containing paths to look for extension files in.161 Raises:162 OSError: On invalid system in the Schema.163 """164 client = aff4.FACTORY.Open(self.client_id, token=self.token)165 system = client.Get(client.Schema.SYSTEM)166 paths = []167 profile_path = "Default"168 user_pb = flow_utils.GetUserInfo(client, user)169 if not user_pb:170 logging.error("User not found")171 return []172 if system == "Windows":173 path = ("%(local_app_data)s/%(sw)s/User Data/%(profile)s")174 for p in ["Google/Chrome", "Chromium"]:175 paths.append(path % {176 "local_app_data": user_pb.special_folders.local_app_data, "sw": p,177 "profile": profile_path})178 elif system == "Linux":179 path = "%(home_path)s/.config/%(sw)s/%(profile)s"180 for p in ["google-chrome", "chromium"]:181 paths.append(path % {"home_path": user_pb.homedir, "sw": p,182 "profile": profile_path})183 elif system == "Darwin":184 path = "%(home_path)s/Library/Application Support/%(sw)s/%(profile)s"185 for p in ["Google/Chrome", "Chromium"]:186 paths.append(path % {"home_path": user_pb.homedir, "sw": p,187 "profile": profile_path})188 else:189 logging.error("Invalid OS for Chrome extensions")190 raise OSError...

Full Screen

Full Screen

action.py

Source:action.py Github

copy

Full Screen

...78 rather than the result of invoking the action.79 @return : a string containing the name of the specified action.80 """81 return Atspi.Action.get_action_name(self.obj, index)82 def getLocalizedName(self, index):83 """84 getLocalizedName: 85 @param : index86 the index of the action whose name is requested.87 Get the localized name of the specified action. Action names88 generally describe the user action, i.e. "click" or "press",89 rather than the result of invoking the action.90 @return : a string containing the name of the specified action.91 """92 return Atspi.Action.get_localized_name(self.obj, index)93 def get_nActions(self):94 return Atspi.Action.get_n_actions(self.obj)95 _nActionsDoc = \96 """...

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