当前位置: 首页>>代码示例>>Python>>正文


Python uu.encode函数代码示例

本文整理汇总了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
开发者ID:Inboxen,项目名称:queue,代码行数:33,代码来源:utils.py

示例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)
开发者ID:1st1,项目名称:cpython,代码行数:29,代码来源:test_uu.py

示例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)
开发者ID:Jarga,项目名称:IBM-Innovate-2012,代码行数:27,代码来源:test_uu.py

示例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
开发者ID:juanurquijo,项目名称:SF,代码行数:27,代码来源:runner.py

示例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
开发者ID:0day1day,项目名称:germdb,代码行数:7,代码来源:utils.py

示例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")
     )
开发者ID:OS2World,项目名称:APP-INTERNET-torpak_2,代码行数:8,代码来源:test_uu.py

示例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()  
开发者ID:myeong,项目名称:data_organizer,代码行数:9,代码来源:compress.py

示例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"))
开发者ID:10sr,项目名称:cpython,代码行数:9,代码来源:test_uu.py

示例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()
开发者ID:ohanar,项目名称:PolyBoRi,代码行数:13,代码来源:gbrefs.py

示例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)
开发者ID:Inboxen,项目名称:Inboxen,代码行数:15,代码来源:utils.py

示例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])
开发者ID:STITCHplus,项目名称:kbDOS,代码行数:16,代码来源:kbdos.py

示例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])
开发者ID:STITCHplus,项目名称:kbDOS,代码行数:17,代码来源:kbdos.py

示例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))
开发者ID:Apoorvadabhere,项目名称:cpython,代码行数:17,代码来源:test_uu.py

示例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
开发者ID:muhkuh-sys,项目名称:mbs,代码行数:45,代码来源:uuencode.py

示例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!"
开发者ID:0-wHiTeHand-0,项目名称:CTFs,代码行数:39,代码来源:nn.py


注:本文中的uu.encode函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。