コード例 #1
0
ファイル: pexpect.py プロジェクト: mmgen/mmgen
	def expect(self,s,t='',delay=None,regex=False,nonl=False,silent=False):
		delay = delay or (0,0.3)[bool(opt.buf_keypress)]

		if not silent:
			if opt.verbose:
				msg_r('EXPECT ' + yellow(str(s)))
			elif not opt.exact_output: msg_r('+')

		try:
			if s == '':
				ret = 0
			else:
				f = (self.p.expect_exact,self.p.expect)[bool(regex)]
				ret = f(s,self.timeout)
		except pexpect.TIMEOUT:
			if opt.debug_pexpect: raise
			m1 = red('\nERROR.  Expect {!r} timed out.  Exiting\n'.format(s))
			m2 = 'before: [{}]\n'.format(self.p.before)
			m3 = 'sent value: [{}]'.format(self.sent_value) if self.sent_value != None else ''
			rdie(1,m1+m2+m3)

		debug_pexpect_msg(self.p)

		if opt.verbose and type(s) != str:
			msg_r(' ==> {} '.format(ret))

		if ret == -1:
			rdie(1,'Error.  Expect returned {}'.format(ret))
		else:
			if t == '':
				if not nonl and not silent: vmsg('')
			else:
				self.send(t,delay,s)
			return ret
コード例 #2
0
ファイル: pexpect.py プロジェクト: mmgen/mmgen
	def expect_getend(self,s,regex=False):
		ret = self.expect(s,regex=regex,nonl=True)
		debug_pexpect_msg(self.p)
		# readline() of partial lines doesn't work with PopenSpawn, so do this instead:
		self.expect(NL,nonl=True,silent=True)
		debug_pexpect_msg(self.p)
		end = self.p.before.rstrip()
		if not g.debug:
			vmsg(' ==> {}'.format(cyan(end)))
		return end
コード例 #3
0
ファイル: pexpect.py プロジェクト: cryptoprojectsforks/mmgen
 def expect_getend(self, s, regex=False):
     ret = self.expect(s, regex=regex, nonl=True)
     debug_pexpect_msg(self.p)
     # readline() of partial lines doesn't work with PopenSpawn, so do this instead:
     self.expect(NL, nonl=True, silent=True)
     debug_pexpect_msg(self.p)
     end = self.p.before.rstrip()
     if not g.debug:
         vmsg(' ==> {}'.format(cyan(end)))
     return end
コード例 #4
0
ファイル: pexpect.py プロジェクト: mmgen/mmgen
	def written_to_file(self,desc,overwrite_unlikely=False,query='Overwrite?  ',oo=False):
		s1 = '{} written to file '.format(desc)
		s2 = query + "Type uppercase 'YES' to confirm: "
		ret = self.expect(([s1,s2],s1)[overwrite_unlikely])
		if ret == 1:
			self.send('YES\n')
			return self.expect_getend("Overwriting file '").rstrip("'")
		self.expect(NL,nonl=True)
		outfile = self.p.before.strip().strip("'")
		if opt.debug_pexpect:
			rmsg('Outfile [{}]'.format(outfile))
		vmsg('{} file: {}'.format(desc,cyan(outfile.replace("'",''))))
		return outfile
コード例 #5
0
ファイル: pexpect.py プロジェクト: cryptoprojectsforks/mmgen
 def written_to_file(self,
                     desc,
                     overwrite_unlikely=False,
                     query='Overwrite?  ',
                     oo=False):
     s1 = '{} written to file '.format(desc)
     s2 = query + "Type uppercase 'YES' to confirm: "
     ret = self.expect(([s1, s2], s1)[overwrite_unlikely])
     if ret == 1:
         self.send('YES\n')
         return self.expect_getend("Overwriting file '").rstrip("'")
     self.expect(NL, nonl=True)
     outfile = self.p.before.strip().strip("'")
     if opt.debug_pexpect:
         rmsg('Outfile [{}]'.format(outfile))
     vmsg('{} file: {}'.format(desc, cyan(outfile.replace("'", ''))))
     return outfile
コード例 #6
0
ファイル: pexpect.py プロジェクト: cryptoprojectsforks/mmgen
    def expect(self,
               s,
               t='',
               delay=None,
               regex=False,
               nonl=False,
               silent=False):
        delay = delay or (0, 0.3)[bool(opt.buf_keypress)]

        if not silent:
            if opt.verbose:
                msg_r('EXPECT ' + yellow(str(s)))
            elif not opt.exact_output:
                msg_r('+')

        try:
            if s == '':
                ret = 0
            else:
                f = (self.p.expect_exact, self.p.expect)[bool(regex)]
                ret = f(s, self.timeout)
        except pexpect.TIMEOUT:
            if opt.debug_pexpect: raise
            m1 = red('\nERROR.  Expect {!r} timed out.  Exiting\n'.format(s))
            m2 = 'before: [{}]\n'.format(self.p.before)
            m3 = 'sent value: [{}]'.format(
                self.sent_value) if self.sent_value != None else ''
            rdie(1, m1 + m2 + m3)

        debug_pexpect_msg(self.p)

        if opt.verbose and type(s) != str:
            msg_r(' ==> {} '.format(ret))

        if ret == -1:
            rdie(1, 'Error.  Expect returned {}'.format(ret))
        else:
            if t == '':
                if not nonl and not silent: vmsg('')
            else:
                self.send(t, delay, s)
            return ret
コード例 #7
0
ファイル: gentest.py プロジェクト: etherume/mmgen
if opt.system: sys.path.pop(0)

from mmgen.addr import test_for_keyconv
if not test_for_keyconv(silent=True):
	msg(
"To run this test, you must install 'keyconv' from the vanitygen package.")
	sys.exit(1)

msg(green("Comparing {}'s internally generated addresses against output of 'keyconv'").format(g.proj_name))

from subprocess import check_output
for i in range(1,rounds+1):
	msg_r("\rRound %s/%s " % (i,rounds))
	sec = hexlify(os.urandom(32))
	wif = hextowif(sec)
	a = privnum2addr(int(sec,16))
	vmsg("\nkey:  %s\naddr: %s\n" % (wif,a))
	b = check_output(["keyconv", wif]).split()[1]
	if a != b:
		msg_r(red("\nERROR: Addresses do not match!"))
		msg("""
  sec key: {}
  WIF key: {}
  {pnm}:   {}
  keyconv: {}
""".format(sec,wif,a,b,pnm=g.proj_name).rstrip())
		sys.exit(3)

msg(green("%sOK" % ("" if opt.verbose else "\n")))