Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
951213e8
Kaydet (Commit)
951213e8
authored
Eki 04, 1995
tarafından
Jack Jansen
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Use binascii module (resulting in a 60-fold speedup:-)
üst
84bbc2e3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
76 deletions
+14
-76
base64.py
Lib/base64.py
+14
-76
No files found.
Lib/base64.py
Dosyayı görüntüle @
951213e8
...
@@ -2,95 +2,33 @@
...
@@ -2,95 +2,33 @@
# version).
# version).
# Parameters set by RFX-XXXX.
# Parameters set by RFX-XXXX.
MAXLINESIZE
=
76
# Excluding the CRLF
#
INVAR
=
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/'
# Modified 04-Oct-95 by Jack to use binascii module
PAD
=
'='
# Check that I typed that string correctly...
import
binascii
if
len
(
INVAR
)
<>
64
:
raise
RuntimeError
,
'wrong INVAR string!?!?'
# Compute the inverse table, for decode().
MAXLINESIZE
=
76
# Excluding the CRLF
inverse
=
{}
MAXBINSIZE
=
(
MAXLINESIZE
/
4
)
*
3
for
i
in
range
(
64
):
inverse
[
INVAR
[
i
]]
=
i
del
i
inverse
[
PAD
]
=
0
# Encode a file.
# Encode a file.
def
encode
(
input
,
output
):
def
encode
(
input
,
output
):
line
=
''
BUFSIZE
=
8192
leftover
=
''
while
1
:
while
1
:
s
=
input
.
read
(
BUF
SIZE
)
s
=
input
.
read
(
MAXBIN
SIZE
)
if
not
s
:
break
if
not
s
:
break
s
=
leftover
+
s
while
len
(
s
)
<
MAXBINSIZE
:
i
=
0
ns
=
input
.
read
(
MAXBINSIZE
-
len
(
s
))
while
i
+
3
<=
len
(
s
):
if
not
ns
:
break
quad
=
makequad
(
s
[
i
:
i
+
3
])
s
=
s
+
ns
i
=
i
+
3
line
=
binascii
.
b2a_base64
(
s
)
if
len
(
line
)
+
4
>
MAXLINESIZE
:
output
.
write
(
line
)
output
.
write
(
line
+
'
\n
'
)
line
=
''
line
=
line
+
quad
leftover
=
s
[
i
:]
if
leftover
:
quad
=
makeshortquad
(
leftover
)
if
len
(
line
)
+
4
>
MAXLINESIZE
:
output
.
write
(
line
+
'
\n
'
)
line
=
''
line
=
line
+
quad
if
line
:
output
.
write
(
line
+
'
\n
'
)
def
makequad
(
s
):
# Return the quad for a 3 character string
x
=
ord
(
s
[
0
])
*
0x10000
+
ord
(
s
[
1
])
*
0x100
+
ord
(
s
[
2
])
x
,
c4
=
divmod
(
x
,
64
)
x
,
c3
=
divmod
(
x
,
64
)
c1
,
c2
=
divmod
(
x
,
64
)
return
INVAR
[
c1
]
+
INVAR
[
c2
]
+
INVAR
[
c3
]
+
INVAR
[
c4
]
def
makeshortquad
(
s
):
# Return the quad value for a 1 or 2 character string
n
=
len
(
s
)
while
len
(
s
)
<
3
:
s
=
s
+
'
\0
'
quad
=
makequad
(
s
)
if
n
==
2
:
quad
=
quad
[:
3
]
+
PAD
elif
n
==
1
:
quad
=
quad
[:
2
]
+
2
*
PAD
return
quad
# Decode a file.
# Decode a file.
def
decode
(
input
,
output
):
def
decode
(
input
,
output
):
BUFSIZE
=
8192
bits
,
n
,
bytes
,
prev
=
0
,
0
,
''
,
''
while
1
:
while
1
:
line
=
input
.
readline
()
line
=
input
.
readline
()
if
not
line
:
break
if
not
line
:
break
for
c
in
line
:
s
=
binascii
.
a2b_base64
(
line
)
if
inverse
.
has_key
(
c
):
output
.
write
(
s
)
bits
=
bits
*
64
+
inverse
[
c
]
n
=
n
+
6
if
n
==
24
:
triplet
=
decodequad
(
bits
)
if
c
==
PAD
:
if
prev
==
PAD
:
triplet
=
triplet
[:
1
]
else
:
triplet
=
triplet
[:
2
]
bits
,
n
=
0
,
0
bytes
=
bytes
+
triplet
if
len
(
bytes
)
>
BUFSIZE
:
output
.
write
(
bytes
[:
BUFSIZE
])
bytes
=
bytes
[
BUFSIZE
:]
prev
=
c
if
bytes
:
output
.
write
(
bytes
)
def
decodequad
(
bits
):
# Turn 24 bits into 3 characters
bits
,
c3
=
divmod
(
bits
,
256
)
c1
,
c2
=
divmod
(
bits
,
256
)
return
chr
(
c1
)
+
chr
(
c2
)
+
chr
(
c3
)
def
encodestring
(
s
):
def
encodestring
(
s
):
import
StringIO
import
StringIO
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment