本文整理汇总了Python中uu.encode函数的典型用法代码示例。如果您正苦于以下问题:Python encode函数的具体用法?Python encode怎么用?Python encode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了encode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_payload
def get_payload(self, i=None):
# taken from http://hg.python.org/cpython/file/0926adcc335c/Lib/email/message.py
# Copyright (C) 2001-2006 Python Software Foundation
# See PY-LIC for licence
if i is None:
payload = self._payload
elif not isinstance(self._payload, list):
raise TypeError('Expected list, got %s' % type(self._payload))
else:
payload = self._payload[i]
if self.is_multipart():
return payload
cte = self.get('content-transfer-encoding', '').lower()
if cte == 'quoted-printable':
return encoders._qencode(payload)
elif cte == 'base64':
try:
return encoders._bencode(payload)
except binascii.Error:
# Incorrect padding
return payload
elif cte in ('x-uuencode', 'uuencode', 'uue', 'x-uue'):
sfp = StringIO()
try:
uu.encode(StringIO(payload+'\n'), sfp, quiet=True)
payload = sfp.getvalue()
except uu.Error:
# Some decoding problem
return payload
# Everything else, including encodings with 8bit or 7bit are returned
# unchanged.
return payload
示例2: test_encode
def test_encode(self):
fin = fout = None
try:
support.unlink(self.tmpin)
fin = open(self.tmpin, 'wb')
fin.write(plaintext)
fin.close()
fin = open(self.tmpin, 'rb')
fout = open(self.tmpout, 'wb')
uu.encode(fin, fout, self.tmpin, mode=0o644)
fin.close()
fout.close()
fout = open(self.tmpout, 'rb')
s = fout.read()
fout.close()
self.assertEqual(s, encodedtextwrapped(0o644, self.tmpin))
# in_file and out_file as filenames
uu.encode(self.tmpin, self.tmpout, self.tmpin, mode=0o644)
fout = open(self.tmpout, 'rb')
s = fout.read()
fout.close()
self.assertEqual(s, encodedtextwrapped(0o644, self.tmpin))
finally:
self._kill(fin)
self._kill(fout)
示例3: test_encode
def test_encode(self):
try:
fin = open(self.tmpin, "wb")
fin.write(plaintext)
fin.close()
fin = open(self.tmpin, "rb")
fout = open(self.tmpout, "w")
uu.encode(fin, fout, self.tmpin, mode=0644)
fin.close()
fout.close()
fout = open(self.tmpout, "r")
s = fout.read()
fout.close()
self.assertEqual(s, encodedtextwrapped % (0644, self.tmpin))
# in_file and out_file as filenames
uu.encode(self.tmpin, self.tmpout, mode=0644)
fout = open(self.tmpout, "r")
s = fout.read()
fout.close()
self.assertEqual(s, encodedtextwrapped % (0644, self.tmpin))
finally:
self._kill(fin)
self._kill(fout)
示例4: createAttachment
def createAttachment(workdir, srcdir, filename, accountid, description):
zip = "att.zip"
now = datetime.datetime.now()
dn = "%04d%02d%02d%02d%02d%02d"%(now.year, now.month, now.day, now.hour, now.minute, now.second)
sdir = os.path.join(workdir, dn)
os.mkdir(sdir)
fullpath = os.path.join(srcdir, filename)
cmd = "cp "+fullpath+" "+sdir
logger.debug(cmd)
(r,c) = commands.getstatusoutput(cmd)
if r:
msg = "Copy source %s to workdir failed "%(fullpath)+" "+str(c)
logger.error(msg)
mailError(msg)
raise PRException(msg)
csvname = os.path.join(sdir, "request.txt")
open(csvname, "w").write("Name,ParentId,Body,Description\n%s,%s,#%s,%s\n"%(filename, accountid, filename, description))
zipname = os.path.join(sdir, zip)
cmd = "(cd %s;zip %s request.txt %s)"%(sdir, zipname, filename)
(r,c) = commands.getstatusoutput(cmd)
if r:
msg = "Creating zip %s failed: %s"%(zipname, c)
raise PRException(msg)
uuname = os.path.join(sdir, "att.uue")
uu.encode(zipname, uuname, zip)
return sdir,zipname,uuname
示例5: encode_sample
def encode_sample(file_path):
enc_file_path = file_path + '.uu'
uu.encode(file_path, enc_file_path)
if os.path.exists(enc_file_path):
return True
return False
示例6: test_encode
def test_encode(self):
sys.stdin = cStringIO.StringIO(plaintext)
sys.stdout = cStringIO.StringIO()
uu.encode("-", "-", "t1", 0666)
self.assertEqual(
sys.stdout.getvalue(),
encodedtextwrapped % (0666, "t1")
)
示例7: comptest
def comptest(s):
print 'original length:', len(s),' ', s
print 'zlib compressed length:', len(zlib.compress(s)),' ', zlib.compress(s)
print 'bz2 compressed length:', len(bz2.compress(s)),' ', bz2.compress(s)
out = StringIO.StringIO()
infile = StringIO.StringIO(s)
uu.encode(infile, out)
print 'uu:', len(out.getvalue()), out.getvalue()
示例8: test_encode
def test_encode(self):
inp = io.BytesIO(plaintext)
out = io.BytesIO()
uu.encode(inp, out, "t1")
self.assertEqual(out.getvalue(), encodedtextwrapped(0o666, "t1"))
inp = io.BytesIO(plaintext)
out = io.BytesIO()
uu.encode(inp, out, "t1", 0o644)
self.assertEqual(out.getvalue(), encodedtextwrapped(0o644, "t1"))
示例9: convert_refs
def convert_refs(ref_file_orig):
content = open(ref_file_orig).read()
#buf=StringIO(content)
buf_out = StringIO()
#
zipped = gzip.GzipFile(filename=ref_file_orig, mode="w", fileobj=buf_out)
zipped.write(content)
zipped.close()
val = buf_out.getvalue()
out = open(ref_file_orig + ".gz.uu", "w")
#print val
uu.encode(out_file=out, in_file=StringIO(val))
out.close()
示例10: set_uuencode_payload
def set_uuencode_payload(msg, data):
"""Encodees the payload with uuencode"""
outfile = BytesIO()
ct = msg.get("Content-Type", "")
cd = msg.get("Content-Disposition", "")
params = dict(HEADER_PARAMS.findall(ct))
params.update(dict(HEADER_PARAMS.findall(cd)))
name = params.get("filename") or params.get("name")
uu.encode(BytesIO(data), outfile, name=name)
enc_data = outfile.getvalue()
msg.set_payload(enc_data)
示例11: img_to_xml
def img_to_xml(self, url):
url=url.replace("-small", "")
data=urllib.urlopen(url).read()
fh=open("/tmp/img.jpg", "w")
fh.write(data)
fh.close()
im = Image.open("/tmp/img.jpg")
uu.encode("/tmp/img.jpg" , "/tmp/img.xml")
fh=open("/tmp/img.xml", "r")
data=fh.read()
fh.close()
return([data, im.size])
示例12: gen_icon
def gen_icon(self,url):
data=urllib.urlopen(url).read()
fh=open("/tmp/thumb", "w")
fh.write(data)
fh.close()
size = 150,150
im = Image.open("/tmp/thumb")
im.thumbnail(size, Image.ANTIALIAS)
im.save("/tmp/thumb.png", "PNG")
uu.encode("/tmp/thumb.png" , "/tmp/thumb.xml")
fh=open("/tmp/thumb.xml", "r")
data=fh.read()
fh.close()
return([data,im.size])
示例13: test_encode
def test_encode(self):
with open(self.tmpin, 'wb') as fin:
fin.write(plaintext)
with open(self.tmpin, 'rb') as fin:
with open(self.tmpout, 'wb') as fout:
uu.encode(fin, fout, self.tmpin, mode=0o644)
with open(self.tmpout, 'rb') as fout:
s = fout.read()
self.assertEqual(s, encodedtextwrapped(0o644, self.tmpin))
# in_file and out_file as filenames
uu.encode(self.tmpin, self.tmpout, self.tmpin, mode=0o644)
with open(self.tmpout, 'rb') as fout:
s = fout.read()
self.assertEqual(s, encodedtextwrapped(0o644, self.tmpin))
示例14: uuencode_action
def uuencode_action(target, source, env):
if env['UUE_ELF']=='':
strUUEPre = env['UUE_PRE']
strUUEPost = env['UUE_POST']
else:
tElfFile = env['UUE_ELF']
if isinstance(tElfFile, ListType) or isinstance(tElfFile, SCons.Node.NodeList):
strElfFileName = tElfFile[0].get_path()
elif isinstance(tElfFile, SCons.Node.FS.Base):
strElfFileName = tElfFile.get_path()
else:
strElfFileName = tElfFile
# Extract the segments.
atSegments = elf_support.get_segment_table(env, strElfFileName)
# Get the load address.
ulLoadAddress = elf_support.get_load_address(atSegments)
# Get the estimated binary size from the segments.
ulEstimatedBinSize = elf_support.get_estimated_bin_size(atSegments)
# Get the execution address.
ulExecAddress = elf_support.get_exec_address(env, strElfFileName)
aSubst = dict({
'EXEC_DEZ': ulExecAddress,
'EXEC_HEX': '%x'%ulExecAddress,
'LOAD_DEZ': ulLoadAddress,
'LOAD_HEX': '%x'%ulLoadAddress,
'SIZE_DEZ': ulEstimatedBinSize,
'SIZE_HEX': '%x'%ulEstimatedBinSize
})
strUUEPre = Template(env['UUE_PRE']).safe_substitute(aSubst)
strUUEPost = Template(env['UUE_POST']).safe_substitute(aSubst)
file_source = open(source[0].get_path(), 'rb')
file_target = open(target[0].get_path(), 'wt')
file_target.write(strUUEPre)
uu.encode(file_source, file_target)
file_target.write(strUUEPost)
file_source.close()
file_target.close()
return 0
示例15: handle
def handle(self):
put = self.wfile.write
challenge = hexlify(os.urandom(3))######[:5]
put('\nWelcome to the Dr. Utonium computer! As he usually says, passwords are out-of-style nowadays. So I\'m going to test if you\'re my lovely boss through crypto challenges that only him can solve <3\n\nFirst of all, let\'s fight fire with fire. BLAKE2B(X) = %s. Let me know X. Hint: my $X =~ ^[0-9a-f]{6}$\nSolution: ' % miblake2.BLAKE2b(challenge).hexdigest().strip())
print "input: " + challenge
response = self.rfile.readline()[:-1]
if response != challenge:
put('You\'re a cheater! Get out of here, now.\n')
return
random.seed(datetime.now())
o_challenge = btc_addr[randint(0,len(btc_addr)-1)]
challenge = hexlify(base58.b58decode(o_challenge))
challenge = "Iep! Next! FINAL! " + challenge[::-1]
key = "ANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZANDYRLZ"
x_challenge = ''
for x in range (0,len(challenge)):
x_challenge += str(ord(challenge[x])^ord(key[x])) + ','
challenge = "Iep! Next! " + x_challenge.rstrip(',')
outf = StringIO.StringIO()
inf = StringIO.StringIO(challenge)
uu.encode(inf, outf)
challenge = "Iep! Next! " + outf.getvalue()
challenge = "Iep! Next! " + rot43(challenge)
challenge = base64.b16encode(challenge)
put(call_mojo())
put('\nHmmm...ok, here is your challenge. Hint: !yenom eht em wohS\n\n' + challenge + "\n\nSolution: ")
challenge = balance(o_challenge)
print " --- " + str(challenge*0.00000001)
sol = self.rfile.readline().strip()
if (len(sol)>15) or (not re.match('^[0-9]+\.[0-9]+$', sol)):
put('You\'re a cheater! Get out of here, now.\nHint: ^[0-9]+\\.[0-9]+$\n')
return
if float(sol) != float(challenge*0.00000001):
put('You\'re a cheater! Get out of here, now.\n')
return
put('%s\n' % FLAG)
print " ^^^ Right!"