Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
4dfcb1a0
Commit
4dfcb1a0
authored
Jun 03, 2011
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Plain Diff
merge heads
parents
48deae12
ab5fcc00
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
85 additions
and
54 deletions
+85
-54
Lib/test/test_multibytecodec_support.py
Lib/test/test_multibytecodec_support.py
+33
-3
Modules/cjkcodecs/_codecs_hk.c
Modules/cjkcodecs/_codecs_hk.c
+47
-46
Modules/cjkcodecs/_codecs_jp.c
Modules/cjkcodecs/_codecs_jp.c
+5
-5
No files found.
Lib/test/test_multibytecodec_support.py
View file @
4dfcb1a0
...
@@ -58,11 +58,16 @@ class TestBase:
...
@@ -58,11 +58,16 @@ class TestBase:
result
=
func
(
source
,
scheme
)[
0
]
result
=
func
(
source
,
scheme
)[
0
]
if
func
is
self
.
decode
:
if
func
is
self
.
decode
:
self
.
assertTrue
(
type
(
result
)
is
str
,
type
(
result
))
self
.
assertTrue
(
type
(
result
)
is
str
,
type
(
result
))
self
.
assertEqual
(
result
,
expected
,
'%a.decode(%r, %r)=%a != %a'
%
(
source
,
self
.
encoding
,
scheme
,
result
,
expected
))
else
:
else
:
self
.
assertTrue
(
type
(
result
)
is
bytes
,
type
(
result
))
self
.
assertTrue
(
type
(
result
)
is
bytes
,
type
(
result
))
self
.
assertEqual
(
result
,
expected
,
self
.
assertEqual
(
result
,
expected
,
'%a.decode(%r)=%a != %a'
'%a.encode(%r, %r)=%a != %a'
%
(
source
,
self
.
encoding
,
result
,
expected
))
%
(
source
,
self
.
encoding
,
scheme
,
result
,
expected
))
else
:
else
:
self
.
assertRaises
(
UnicodeError
,
func
,
source
,
scheme
)
self
.
assertRaises
(
UnicodeError
,
func
,
source
,
scheme
)
...
@@ -279,6 +284,7 @@ class TestBase_Mapping(unittest.TestCase):
...
@@ -279,6 +284,7 @@ class TestBase_Mapping(unittest.TestCase):
pass_enctest
=
[]
pass_enctest
=
[]
pass_dectest
=
[]
pass_dectest
=
[]
supmaps
=
[]
supmaps
=
[]
codectests
=
[]
def
__init__
(
self
,
*
args
,
**
kw
):
def
__init__
(
self
,
*
args
,
**
kw
):
unittest
.
TestCase
.
__init__
(
self
,
*
args
,
**
kw
)
unittest
.
TestCase
.
__init__
(
self
,
*
args
,
**
kw
)
...
@@ -348,6 +354,30 @@ class TestBase_Mapping(unittest.TestCase):
...
@@ -348,6 +354,30 @@ class TestBase_Mapping(unittest.TestCase):
if
(
csetch
,
unich
)
not
in
self
.
pass_dectest
:
if
(
csetch
,
unich
)
not
in
self
.
pass_dectest
:
self
.
assertEqual
(
str
(
csetch
,
self
.
encoding
),
unich
)
self
.
assertEqual
(
str
(
csetch
,
self
.
encoding
),
unich
)
def
test_errorhandle
(
self
):
for
source
,
scheme
,
expected
in
self
.
codectests
:
if
isinstance
(
source
,
bytes
):
func
=
source
.
decode
else
:
func
=
source
.
encode
if
expected
:
if
isinstance
(
source
,
bytes
):
result
=
func
(
self
.
encoding
,
scheme
)
self
.
assertTrue
(
type
(
result
)
is
str
,
type
(
result
))
self
.
assertEqual
(
result
,
expected
,
'%a.decode(%r, %r)=%a != %a'
%
(
source
,
self
.
encoding
,
scheme
,
result
,
expected
))
else
:
result
=
func
(
self
.
encoding
,
scheme
)
self
.
assertTrue
(
type
(
result
)
is
bytes
,
type
(
result
))
self
.
assertEqual
(
result
,
expected
,
'%a.encode(%r, %r)=%a != %a'
%
(
source
,
self
.
encoding
,
scheme
,
result
,
expected
))
else
:
self
.
assertRaises
(
UnicodeError
,
func
,
self
.
encoding
,
scheme
)
def
load_teststring
(
name
):
def
load_teststring
(
name
):
dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'cjkencodings'
)
dir
=
os
.
path
.
join
(
os
.
path
.
dirname
(
__file__
),
'cjkencodings'
)
with
open
(
os
.
path
.
join
(
dir
,
name
+
'.txt'
),
'rb'
)
as
f
:
with
open
(
os
.
path
.
join
(
dir
,
name
+
'.txt'
),
'rb'
)
as
f
:
...
...
Modules/cjkcodecs/_codecs_hk.c
View file @
4dfcb1a0
...
@@ -115,55 +115,56 @@ DECODER(big5hkscs)
...
@@ -115,55 +115,56 @@ DECODER(big5hkscs)
REQUIRE_INBUF
(
2
)
REQUIRE_INBUF
(
2
)
if
(
0xc6
<=
c
&&
c
<=
0xc8
&&
(
c
>=
0xc7
||
IN2
>=
0xa1
))
if
(
0xc6
>
c
||
c
>
0xc8
||
(
c
<
0xc7
&&
IN2
<
0xa1
))
{
goto
hkscsdec
;
TRYMAP_DEC
(
big5
,
**
outbuf
,
c
,
IN2
)
{
NEXT
(
2
,
1
)
continue
;
}
}
TRYMAP_DEC
(
big5hkscs
,
decoded
,
c
,
IN2
)
{
int
s
=
BH2S
(
c
,
IN2
);
const
unsigned
char
*
hintbase
;
assert
(
0x87
<=
c
&&
c
<=
0xfe
);
assert
(
0x40
<=
IN2
&&
IN2
<=
0xfe
);
if
(
BH2S
(
0x87
,
0x40
)
<=
s
&&
s
<=
BH2S
(
0xa0
,
0xfe
))
{
hintbase
=
big5hkscs_phint_0
;
s
-=
BH2S
(
0x87
,
0x40
);
}
else
if
(
BH2S
(
0xc6
,
0xa1
)
<=
s
&&
s
<=
BH2S
(
0xc8
,
0xfe
)){
hintbase
=
big5hkscs_phint_12130
;
s
-=
BH2S
(
0xc6
,
0xa1
);
}
else
if
(
BH2S
(
0xf9
,
0xd6
)
<=
s
&&
s
<=
BH2S
(
0xfe
,
0xfe
)){
hintbase
=
big5hkscs_phint_21924
;
s
-=
BH2S
(
0xf9
,
0xd6
);
}
else
return
MBERR_INTERNAL
;
TRYMAP_DEC
(
big5
,
**
outbuf
,
c
,
IN2
)
{
if
(
hintbase
[
s
>>
3
]
&
(
1
<<
(
s
&
7
)))
{
NEXT
(
2
,
1
)
WRITEUCS4
(
decoded
|
0x20000
)
NEXT_IN
(
2
)
}
else
{
OUT1
(
decoded
)
NEXT
(
2
,
1
)
}
continue
;
}
}
else
hkscsdec:
TRYMAP_DEC
(
big5hkscs
,
decoded
,
c
,
IN2
)
{
switch
((
c
<<
8
)
|
IN2
)
{
int
s
=
BH2S
(
c
,
IN2
);
case
0x8862
:
WRITE2
(
0x00ca
,
0x0304
);
break
;
const
unsigned
char
*
hintbase
;
case
0x8864
:
WRITE2
(
0x00ca
,
0x030c
);
break
;
case
0x88a3
:
WRITE2
(
0x00ea
,
0x0304
);
break
;
assert
(
0x87
<=
c
&&
c
<=
0xfe
);
case
0x88a5
:
WRITE2
(
0x00ea
,
0x030c
);
break
;
assert
(
0x40
<=
IN2
&&
IN2
<=
0xfe
);
default:
return
2
;
if
(
BH2S
(
0x87
,
0x40
)
<=
s
&&
s
<=
BH2S
(
0xa0
,
0xfe
))
{
hintbase
=
big5hkscs_phint_0
;
s
-=
BH2S
(
0x87
,
0x40
);
}
else
if
(
BH2S
(
0xc6
,
0xa1
)
<=
s
&&
s
<=
BH2S
(
0xc8
,
0xfe
)){
hintbase
=
big5hkscs_phint_12130
;
s
-=
BH2S
(
0xc6
,
0xa1
);
}
else
if
(
BH2S
(
0xf9
,
0xd6
)
<=
s
&&
s
<=
BH2S
(
0xfe
,
0xfe
)){
hintbase
=
big5hkscs_phint_21924
;
s
-=
BH2S
(
0xf9
,
0xd6
);
}
else
return
MBERR_INTERNAL
;
if
(
hintbase
[
s
>>
3
]
&
(
1
<<
(
s
&
7
)))
{
WRITEUCS4
(
decoded
|
0x20000
)
NEXT_IN
(
2
)
}
else
{
OUT1
(
decoded
)
NEXT
(
2
,
1
)
}
}
else
{
switch
((
c
<<
8
)
|
IN2
)
{
case
0x8862
:
WRITE2
(
0x00ca
,
0x0304
);
break
;
case
0x8864
:
WRITE2
(
0x00ca
,
0x030c
);
break
;
case
0x88a3
:
WRITE2
(
0x00ea
,
0x0304
);
break
;
case
0x88a5
:
WRITE2
(
0x00ea
,
0x030c
);
break
;
default:
return
2
;
}
NEXT
(
2
,
2
)
/* all decoded codepoints are pairs, above. */
}
}
NEXT
(
2
,
2
)
/* all decoded codepoints are pairs, above. */
}
}
return
0
;
return
0
;
...
...
Modules/cjkcodecs/_codecs_jp.c
View file @
4dfcb1a0
...
@@ -371,11 +371,11 @@ DECODER(euc_jp)
...
@@ -371,11 +371,11 @@ DECODER(euc_jp)
REQUIRE_OUTBUF
(
1
)
REQUIRE_OUTBUF
(
1
)
if
(
c
<
0x80
)
{
if
(
c
<
0x80
)
{
OUT1
(
c
)
OUT1
(
c
)
NEXT
(
1
,
1
)
NEXT
(
1
,
1
)
continue
;
continue
;
}
}
if
(
c
==
0x8e
)
{
if
(
c
==
0x8e
)
{
/* JIS X 0201 half-width katakana */
/* JIS X 0201 half-width katakana */
...
...
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