Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def processCheckPidAndName(uPid, sName):
"""
Checks if a process PID and NAME matches.
"""
if sys.platform == 'win32':
fRc = winbase.processCheckPidAndName(uPid, sName);
else:
sOs = utils.getHostOs();
if sOs == 'linux':
asPsCmd = ['/bin/ps', '-p', '%u' % (uPid,), '-o', 'fname='];
elif sOs == 'solaris':
asPsCmd = ['/usr/bin/ps', '-p', '%u' % (uPid,), '-o', 'fname='];
elif sOs == 'darwin':
asPsCmd = ['/bin/ps', '-p', '%u' % (uPid,), '-o', 'ucomm='];
else:
asPsCmd = None;
if asPsCmd is not None:
try:
oPs = subprocess.Popen(asPsCmd, stdout=subprocess.PIPE);
sCurName = oPs.communicate()[0];
iExitCode = oPs.wait();
except:
reporter.logXcpt();
# Options.
self.fNoWipeClean = False;
# Tasks - only accessed by one thread atm, so no need for locking.
self.aoTasks = [];
# Host info.
self.sHost = utils.getHostOs();
self.sHostArch = utils.getHostArch();
#
# Get our bearings and adjust the environment.
#
if not utils.isRunningFromCheckout():
self.sBinPath = os.path.join(g_ksValidationKitDir, utils.getHostOs(), utils.getHostArch());
else:
self.sBinPath = os.path.join(g_ksValidationKitDir, os.pardir, os.pardir, os.pardir, 'out', utils.getHostOsDotArch(),
os.environ.get('KBUILD_TYPE', os.environ.get('BUILD_TYPE', 'debug')),
'validationkit', utils.getHostOs(), utils.getHostArch());
self.sOrgShell = os.environ.get('SHELL');
self.sOurShell = os.path.join(self.sBinPath, 'vts_shell' + exeSuff()); # No shell yet.
os.environ['SHELL'] = self.sOurShell;
self.sScriptPath = getDirEnv('TESTBOX_PATH_SCRIPTS');
if self.sScriptPath is None:
self.sScriptPath = os.path.abspath(os.path.join(os.getcwd(), '..'));
os.environ['TESTBOX_PATH_SCRIPTS'] = self.sScriptPath;
self.sScratchPath = getDirEnv('TESTBOX_PATH_SCRATCH', fTryCreate = True);
if self.sScratchPath is None:
sTmpDir = tempfile.gettempdir();
self.fInterrupted = False;
# Actions.
self.asSpecialActions = ['extract', 'abort'];
self.asNormalActions = ['cleanup-before', 'verify', 'config', 'execute', 'cleanup-after' ];
self.asActions = [];
self.sExtractDstPath = None;
# Options.
self.fNoWipeClean = False;
# Tasks - only accessed by one thread atm, so no need for locking.
self.aoTasks = [];
# Host info.
self.sHost = utils.getHostOs();
self.sHostArch = utils.getHostArch();
#
# Get our bearings and adjust the environment.
#
if not utils.isRunningFromCheckout():
self.sBinPath = os.path.join(g_ksValidationKitDir, utils.getHostOs(), utils.getHostArch());
else:
self.sBinPath = os.path.join(g_ksValidationKitDir, os.pardir, os.pardir, os.pardir, 'out', utils.getHostOsDotArch(),
os.environ.get('KBUILD_TYPE', os.environ.get('BUILD_TYPE', 'debug')),
'validationkit', utils.getHostOs(), utils.getHostArch());
self.sOrgShell = os.environ.get('SHELL');
self.sOurShell = os.path.join(self.sBinPath, 'vts_shell' + exeSuff()); # No shell yet.
os.environ['SHELL'] = self.sOurShell;
self.sScriptPath = getDirEnv('TESTBOX_PATH_SCRIPTS');
def __init__(self, sName, asArgs, uPid, hWin = None, uTid = None):
TdTaskBase.__init__(self, utils.getCallerName());
self.sName = sName;
self.asArgs = asArgs;
self.uExitCode = -127;
self.uPid = uPid;
self.hWin = hWin;
self.uTid = uTid;
self.sKindCrashReport = None;
self.sKindCrashDump = None;
def save_buf(self, buf):
path = utils.get_full_path(buf['path'])
utils.mkdir(os.path.split(path)[0])
with open(path, 'wb') as fd:
if buf['encoding'] == 'utf8':
fd.write(buf['buf'].encode('utf-8'))
else:
fd.write(buf['buf'])
return path
def on_delete_buf(self, data):
buf_id = int(data['id'])
del self.FLOO_BUFS[buf_id]
del self.FLOO_PATHS_TO_BUFS[data['path']]
path = utils.get_full_path(data['path'])
utils.rm(path)
msg.warn('deleted %s because %s told me too.' % (path, data.get('username', 'the internet')))
def query(self):
"""
向接口查询子域并做子域匹配
"""
self.header = self.get_header()
self.proxy = self.get_proxy(self.source)
# 绕过主页前端JS验证
self.cookie = {'pa_id': str(random.randint(0, 1000000000))}
params = {'label': self.domain, 'date': 'ALL'}
resp = self.get(self.addr, params)
if not resp:
return
if resp.status_code == 200:
subdomains_find = utils.match_subdomain(self.domain, resp.text)
if subdomains_find:
# 合并搜索子域名搜索结果
self.subdomains = self.subdomains.union(subdomains_find)
try:
self.sock.close()
except Exception:
pass
self.workspace_info = {}
self.bufs_to_stomp = set()
self.net_buf = ''
self.sock = None
self.authed = False
G.JOINED_WORKSPACE = False
self.reconnect_delay *= 1.5
if self.reconnect_delay > 10000:
self.reconnect_delay = 10000
if self.retries > 0:
msg.log('Floobits: Reconnecting in %sms' % self.reconnect_delay)
self.reconnect_timeout = utils.set_timeout(self.connect, int(self.reconnect_delay))
elif self.retries == 0:
msg.error('Floobits Error! Too many reconnect failures. Giving up.')
self.retries -= 1
# insert question tags for the assessment content
for quid in question_ids:
html_content.append(
str(safe_dom.Element(
'question',
quid=str(quid),
instanceid=common_utils.generate_instance_id())))
dst_unit.html_content = '\n'.join(html_content)
# insert question tags for the review questionnaire
for quid in review_ids:
html_review_form.append(
str(safe_dom.Element(
'question',
quid=str(quid),
instanceid=common_utils.generate_instance_id())))
dst_unit.html_review_form = '\n'.join(html_review_form)
return True
question_dict = cls.import_multiple_choice(
question, description, task)
qid = QuestionDAO.create_question(
question_dict, QuestionDAO.DTO.MULTIPLE_CHOICE)
elif question_type == 'freetext':
question_dict = cls.import_freetext(question, description, task)
qid = QuestionDAO.create_question(
question_dict, QuestionDTO.SHORT_ANSWER)
elif question_type == 'multiple choice group':
question_group_dict = cls.import_multiple_choice_group(
question, description, unit, lesson_title, question_number,
task)
qid = QuestionGroupDAO.create_question_group(question_group_dict)
else:
raise ValueError('Unknown question type: %s' % question_type)
return (qid, common_utils.generate_instance_id())