Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/smanonr..../usr/lib64/python3....
File: uu.py
#! /usr/libexec/platform-python
[0] Fix | Delete
[1] Fix | Delete
# Copyright 1994 by Lance Ellinghouse
[2] Fix | Delete
# Cathedral City, California Republic, United States of America.
[3] Fix | Delete
# All Rights Reserved
[4] Fix | Delete
# Permission to use, copy, modify, and distribute this software and its
[5] Fix | Delete
# documentation for any purpose and without fee is hereby granted,
[6] Fix | Delete
# provided that the above copyright notice appear in all copies and that
[7] Fix | Delete
# both that copyright notice and this permission notice appear in
[8] Fix | Delete
# supporting documentation, and that the name of Lance Ellinghouse
[9] Fix | Delete
# not be used in advertising or publicity pertaining to distribution
[10] Fix | Delete
# of the software without specific, written prior permission.
[11] Fix | Delete
# LANCE ELLINGHOUSE DISCLAIMS ALL WARRANTIES WITH REGARD TO
[12] Fix | Delete
# THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
[13] Fix | Delete
# FITNESS, IN NO EVENT SHALL LANCE ELLINGHOUSE CENTRUM BE LIABLE
[14] Fix | Delete
# FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
[15] Fix | Delete
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
[16] Fix | Delete
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
[17] Fix | Delete
# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
[18] Fix | Delete
#
[19] Fix | Delete
# Modified by Jack Jansen, CWI, July 1995:
[20] Fix | Delete
# - Use binascii module to do the actual line-by-line conversion
[21] Fix | Delete
# between ascii and binary. This results in a 1000-fold speedup. The C
[22] Fix | Delete
# version is still 5 times faster, though.
[23] Fix | Delete
# - Arguments more compliant with python standard
[24] Fix | Delete
[25] Fix | Delete
"""Implementation of the UUencode and UUdecode functions.
[26] Fix | Delete
[27] Fix | Delete
encode(in_file, out_file [,name, mode])
[28] Fix | Delete
decode(in_file [, out_file, mode])
[29] Fix | Delete
"""
[30] Fix | Delete
[31] Fix | Delete
import binascii
[32] Fix | Delete
import os
[33] Fix | Delete
import sys
[34] Fix | Delete
[35] Fix | Delete
__all__ = ["Error", "encode", "decode"]
[36] Fix | Delete
[37] Fix | Delete
class Error(Exception):
[38] Fix | Delete
pass
[39] Fix | Delete
[40] Fix | Delete
def encode(in_file, out_file, name=None, mode=None):
[41] Fix | Delete
"""Uuencode file"""
[42] Fix | Delete
#
[43] Fix | Delete
# If in_file is a pathname open it and change defaults
[44] Fix | Delete
#
[45] Fix | Delete
opened_files = []
[46] Fix | Delete
try:
[47] Fix | Delete
if in_file == '-':
[48] Fix | Delete
in_file = sys.stdin.buffer
[49] Fix | Delete
elif isinstance(in_file, str):
[50] Fix | Delete
if name is None:
[51] Fix | Delete
name = os.path.basename(in_file)
[52] Fix | Delete
if mode is None:
[53] Fix | Delete
try:
[54] Fix | Delete
mode = os.stat(in_file).st_mode
[55] Fix | Delete
except AttributeError:
[56] Fix | Delete
pass
[57] Fix | Delete
in_file = open(in_file, 'rb')
[58] Fix | Delete
opened_files.append(in_file)
[59] Fix | Delete
#
[60] Fix | Delete
# Open out_file if it is a pathname
[61] Fix | Delete
#
[62] Fix | Delete
if out_file == '-':
[63] Fix | Delete
out_file = sys.stdout.buffer
[64] Fix | Delete
elif isinstance(out_file, str):
[65] Fix | Delete
out_file = open(out_file, 'wb')
[66] Fix | Delete
opened_files.append(out_file)
[67] Fix | Delete
#
[68] Fix | Delete
# Set defaults for name and mode
[69] Fix | Delete
#
[70] Fix | Delete
if name is None:
[71] Fix | Delete
name = '-'
[72] Fix | Delete
if mode is None:
[73] Fix | Delete
mode = 0o666
[74] Fix | Delete
#
[75] Fix | Delete
# Write the data
[76] Fix | Delete
#
[77] Fix | Delete
out_file.write(('begin %o %s\n' % ((mode & 0o777), name)).encode("ascii"))
[78] Fix | Delete
data = in_file.read(45)
[79] Fix | Delete
while len(data) > 0:
[80] Fix | Delete
out_file.write(binascii.b2a_uu(data))
[81] Fix | Delete
data = in_file.read(45)
[82] Fix | Delete
out_file.write(b' \nend\n')
[83] Fix | Delete
finally:
[84] Fix | Delete
for f in opened_files:
[85] Fix | Delete
f.close()
[86] Fix | Delete
[87] Fix | Delete
[88] Fix | Delete
def decode(in_file, out_file=None, mode=None, quiet=False):
[89] Fix | Delete
"""Decode uuencoded file"""
[90] Fix | Delete
#
[91] Fix | Delete
# Open the input file, if needed.
[92] Fix | Delete
#
[93] Fix | Delete
opened_files = []
[94] Fix | Delete
if in_file == '-':
[95] Fix | Delete
in_file = sys.stdin.buffer
[96] Fix | Delete
elif isinstance(in_file, str):
[97] Fix | Delete
in_file = open(in_file, 'rb')
[98] Fix | Delete
opened_files.append(in_file)
[99] Fix | Delete
[100] Fix | Delete
try:
[101] Fix | Delete
#
[102] Fix | Delete
# Read until a begin is encountered or we've exhausted the file
[103] Fix | Delete
#
[104] Fix | Delete
while True:
[105] Fix | Delete
hdr = in_file.readline()
[106] Fix | Delete
if not hdr:
[107] Fix | Delete
raise Error('No valid begin line found in input file')
[108] Fix | Delete
if not hdr.startswith(b'begin'):
[109] Fix | Delete
continue
[110] Fix | Delete
hdrfields = hdr.split(b' ', 2)
[111] Fix | Delete
if len(hdrfields) == 3 and hdrfields[0] == b'begin':
[112] Fix | Delete
try:
[113] Fix | Delete
int(hdrfields[1], 8)
[114] Fix | Delete
break
[115] Fix | Delete
except ValueError:
[116] Fix | Delete
pass
[117] Fix | Delete
if out_file is None:
[118] Fix | Delete
# If the filename isn't ASCII, what's up with that?!?
[119] Fix | Delete
out_file = hdrfields[2].rstrip(b' \t\r\n\f').decode("ascii")
[120] Fix | Delete
if os.path.exists(out_file):
[121] Fix | Delete
raise Error('Cannot overwrite existing file: %s' % out_file)
[122] Fix | Delete
if mode is None:
[123] Fix | Delete
mode = int(hdrfields[1], 8)
[124] Fix | Delete
#
[125] Fix | Delete
# Open the output file
[126] Fix | Delete
#
[127] Fix | Delete
if out_file == '-':
[128] Fix | Delete
out_file = sys.stdout.buffer
[129] Fix | Delete
elif isinstance(out_file, str):
[130] Fix | Delete
fp = open(out_file, 'wb')
[131] Fix | Delete
try:
[132] Fix | Delete
os.path.chmod(out_file, mode)
[133] Fix | Delete
except AttributeError:
[134] Fix | Delete
pass
[135] Fix | Delete
out_file = fp
[136] Fix | Delete
opened_files.append(out_file)
[137] Fix | Delete
#
[138] Fix | Delete
# Main decoding loop
[139] Fix | Delete
#
[140] Fix | Delete
s = in_file.readline()
[141] Fix | Delete
while s and s.strip(b' \t\r\n\f') != b'end':
[142] Fix | Delete
try:
[143] Fix | Delete
data = binascii.a2b_uu(s)
[144] Fix | Delete
except binascii.Error as v:
[145] Fix | Delete
# Workaround for broken uuencoders by /Fredrik Lundh
[146] Fix | Delete
nbytes = (((s[0]-32) & 63) * 4 + 5) // 3
[147] Fix | Delete
data = binascii.a2b_uu(s[:nbytes])
[148] Fix | Delete
if not quiet:
[149] Fix | Delete
sys.stderr.write("Warning: %s\n" % v)
[150] Fix | Delete
out_file.write(data)
[151] Fix | Delete
s = in_file.readline()
[152] Fix | Delete
if not s:
[153] Fix | Delete
raise Error('Truncated input file')
[154] Fix | Delete
finally:
[155] Fix | Delete
for f in opened_files:
[156] Fix | Delete
f.close()
[157] Fix | Delete
[158] Fix | Delete
def test():
[159] Fix | Delete
"""uuencode/uudecode main program"""
[160] Fix | Delete
[161] Fix | Delete
import optparse
[162] Fix | Delete
parser = optparse.OptionParser(usage='usage: %prog [-d] [-t] [input [output]]')
[163] Fix | Delete
parser.add_option('-d', '--decode', dest='decode', help='Decode (instead of encode)?', default=False, action='store_true')
[164] Fix | Delete
parser.add_option('-t', '--text', dest='text', help='data is text, encoded format unix-compatible text?', default=False, action='store_true')
[165] Fix | Delete
[166] Fix | Delete
(options, args) = parser.parse_args()
[167] Fix | Delete
if len(args) > 2:
[168] Fix | Delete
parser.error('incorrect number of arguments')
[169] Fix | Delete
sys.exit(1)
[170] Fix | Delete
[171] Fix | Delete
# Use the binary streams underlying stdin/stdout
[172] Fix | Delete
input = sys.stdin.buffer
[173] Fix | Delete
output = sys.stdout.buffer
[174] Fix | Delete
if len(args) > 0:
[175] Fix | Delete
input = args[0]
[176] Fix | Delete
if len(args) > 1:
[177] Fix | Delete
output = args[1]
[178] Fix | Delete
[179] Fix | Delete
if options.decode:
[180] Fix | Delete
if options.text:
[181] Fix | Delete
if isinstance(output, str):
[182] Fix | Delete
output = open(output, 'wb')
[183] Fix | Delete
else:
[184] Fix | Delete
print(sys.argv[0], ': cannot do -t to stdout')
[185] Fix | Delete
sys.exit(1)
[186] Fix | Delete
decode(input, output)
[187] Fix | Delete
else:
[188] Fix | Delete
if options.text:
[189] Fix | Delete
if isinstance(input, str):
[190] Fix | Delete
input = open(input, 'rb')
[191] Fix | Delete
else:
[192] Fix | Delete
print(sys.argv[0], ': cannot do -t from stdin')
[193] Fix | Delete
sys.exit(1)
[194] Fix | Delete
encode(input, output)
[195] Fix | Delete
[196] Fix | Delete
if __name__ == '__main__':
[197] Fix | Delete
test()
[198] Fix | Delete
[199] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function