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
dcee3c0d
Kaydet (Commit)
dcee3c0d
authored
May 22, 2007
tarafından
Guido van Rossum
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Make test_binhex pass. (Do we really want to support it still?)
üst
4581ae5f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
31 deletions
+26
-31
binhex.py
Lib/binhex.py
+21
-23
test_binhex.py
Lib/test/test_binhex.py
+5
-8
No files found.
Lib/binhex.py
Dosyayı görüntüle @
dcee3c0d
...
...
@@ -21,8 +21,9 @@ hexbin(inputfilename, outputfilename)
# input. The resulting code (xx 90 90) would appear to be interpreted as an
# escaped *value* of 0x90. All coders I've seen appear to ignore this nicety...
#
import
sys
import
io
import
os
import
sys
import
struct
import
binascii
...
...
@@ -80,13 +81,10 @@ except ImportError:
def
getfileinfo
(
name
):
finfo
=
FInfo
()
fp
=
io
.
open
(
name
,
'rb'
)
# Quick check for textfile
fp
=
open
(
name
)
data
=
open
(
name
)
.
read
(
256
)
for
c
in
data
:
if
not
c
.
isspace
()
and
(
c
<
' '
or
ord
(
c
)
>
0x7f
):
break
else
:
data
=
fp
.
read
(
512
)
if
0
not
in
data
:
finfo
.
Type
=
'TEXT'
fp
.
seek
(
0
,
2
)
dsize
=
fp
.
tell
()
...
...
@@ -100,7 +98,7 @@ except ImportError:
pass
def
read
(
self
,
*
args
):
return
''
return
b
''
def
write
(
self
,
*
args
):
pass
...
...
@@ -113,8 +111,8 @@ class _Hqxcoderengine:
def
__init__
(
self
,
ofp
):
self
.
ofp
=
ofp
self
.
data
=
''
self
.
hqxdata
=
''
self
.
data
=
b
''
self
.
hqxdata
=
b
''
self
.
linelen
=
LINELEN
-
1
def
write
(
self
,
data
):
...
...
@@ -132,12 +130,12 @@ class _Hqxcoderengine:
first
=
0
while
first
<=
len
(
self
.
hqxdata
)
-
self
.
linelen
:
last
=
first
+
self
.
linelen
self
.
ofp
.
write
(
self
.
hqxdata
[
first
:
last
]
+
'
\n
'
)
self
.
ofp
.
write
(
self
.
hqxdata
[
first
:
last
]
+
b
'
\n
'
)
self
.
linelen
=
LINELEN
first
=
last
self
.
hqxdata
=
self
.
hqxdata
[
first
:]
if
force
:
self
.
ofp
.
write
(
self
.
hqxdata
+
':
\n
'
)
self
.
ofp
.
write
(
self
.
hqxdata
+
b
':
\n
'
)
def
close
(
self
):
if
self
.
data
:
...
...
@@ -152,7 +150,7 @@ class _Rlecoderengine:
def
__init__
(
self
,
ofp
):
self
.
ofp
=
ofp
self
.
data
=
''
self
.
data
=
b
''
def
write
(
self
,
data
):
self
.
data
=
self
.
data
+
data
...
...
@@ -160,7 +158,7 @@ class _Rlecoderengine:
return
rledata
=
binascii
.
rlecode_hqx
(
self
.
data
)
self
.
ofp
.
write
(
rledata
)
self
.
data
=
''
self
.
data
=
b
''
def
close
(
self
):
if
self
.
data
:
...
...
@@ -172,7 +170,7 @@ class _Rlecoderengine:
class
BinHex
:
def
__init__
(
self
,
name_finfo_dlen_rlen
,
ofp
):
name
,
finfo
,
dlen
,
rlen
=
name_finfo_dlen_rlen
if
type
(
ofp
)
==
type
(
''
):
if
isinstance
(
ofp
,
basestring
):
ofname
=
ofp
ofp
=
open
(
ofname
,
'w'
)
if
os
.
name
==
'mac'
:
...
...
@@ -193,8 +191,8 @@ class BinHex:
nl
=
len
(
name
)
if
nl
>
63
:
raise
Error
,
'Filename too long'
d
=
chr
(
nl
)
+
name
+
'
\0
'
d2
=
finfo
.
Type
+
finfo
.
Creator
d
=
bytes
(
chr
(
nl
))
+
bytes
(
name
)
+
b
'
\0
'
d2
=
bytes
(
finfo
.
Type
,
"latin-1"
)
+
bytes
(
finfo
.
Creator
,
"latin-1"
)
# Force all structs to be packed with big-endian
d3
=
struct
.
pack
(
'>h'
,
finfo
.
Flags
)
...
...
@@ -281,7 +279,7 @@ class _Hqxdecoderengine:
def
read
(
self
,
totalwtd
):
"""Read at least wtd bytes (or until EOF)"""
decdata
=
''
decdata
=
b
''
wtd
=
totalwtd
#
# The loop here is convoluted, since we don't really now how
...
...
@@ -321,8 +319,8 @@ class _Rledecoderengine:
def
__init__
(
self
,
ifp
):
self
.
ifp
=
ifp
self
.
pre_buffer
=
''
self
.
post_buffer
=
''
self
.
pre_buffer
=
b
''
self
.
post_buffer
=
b
''
self
.
eof
=
0
def
read
(
self
,
wtd
):
...
...
@@ -337,7 +335,7 @@ class _Rledecoderengine:
if
self
.
ifp
.
eof
:
self
.
post_buffer
=
self
.
post_buffer
+
\
binascii
.
rledecode_hqx
(
self
.
pre_buffer
)
self
.
pre_buffer
=
''
self
.
pre_buffer
=
b
''
return
#
...
...
@@ -372,7 +370,7 @@ class _Rledecoderengine:
class
HexBin
:
def
__init__
(
self
,
ifp
):
if
type
(
ifp
)
==
type
(
''
):
if
isinstance
(
ifp
,
basestring
):
ifp
=
open
(
ifp
)
#
# Find initial colon.
...
...
@@ -438,7 +436,7 @@ class HexBin:
n
=
min
(
n
,
self
.
dlen
)
else
:
n
=
self
.
dlen
rv
=
''
rv
=
b
''
while
len
(
rv
)
<
n
:
rv
=
rv
+
self
.
_read
(
n
-
len
(
rv
))
self
.
dlen
=
self
.
dlen
-
n
...
...
Lib/test/test_binhex.py
Dosyayı görüntüle @
dcee3c0d
...
...
@@ -17,16 +17,13 @@ class BinHexTestCase(unittest.TestCase):
self
.
fname2
=
test_support
.
TESTFN
+
"2"
def
tearDown
(
self
):
t
ry
:
os
.
unlink
(
self
.
fname1
)
except
OSError
:
pass
t
est_support
.
unlink
(
self
.
fname1
)
test_support
.
unlink
(
self
.
fname2
)
try
:
os
.
unlink
(
self
.
fname2
)
except
OSError
:
pass
DATA
=
'Jack is my hero'
DATA
=
b
'Jack is my hero'
def
test_binhex
(
self
):
f
=
open
(
self
.
fname1
,
'w'
)
f
=
open
(
self
.
fname1
,
'w
b
'
)
f
.
write
(
self
.
DATA
)
f
.
close
()
...
...
@@ -34,7 +31,7 @@ class BinHexTestCase(unittest.TestCase):
binhex
.
hexbin
(
self
.
fname2
,
self
.
fname1
)
f
=
open
(
self
.
fname1
,
'r'
)
f
=
open
(
self
.
fname1
,
'r
b
'
)
finish
=
f
.
readline
()
f
.
close
()
...
...
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