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
a73fbe79
Commit
a73fbe79
authored
Feb 23, 2008
by
Eric Smith
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added future_builtins, which contains PEP 3127 compatible versions of hex() and oct().
parent
73d79632
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
113 additions
and
0 deletions
+113
-0
Lib/test/test_future_builtins.py
Lib/test/test_future_builtins.py
+27
-0
Misc/NEWS
Misc/NEWS
+8
-0
Modules/future_builtins.c
Modules/future_builtins.c
+69
-0
PC/config.c
PC/config.c
+2
-0
PCbuild/pythoncore.vcproj
PCbuild/pythoncore.vcproj
+4
-0
setup.py
setup.py
+3
-0
No files found.
Lib/test/test_future_builtins.py
0 → 100644
View file @
a73fbe79
import
test.test_support
,
unittest
# we're testing the behavior of these future builtins:
from
future_builtins
import
hex
,
oct
class
BuiltinTest
(
unittest
.
TestCase
):
def
test_hex
(
self
):
self
.
assertEqual
(
hex
(
0
),
'0x0'
)
self
.
assertEqual
(
hex
(
16
),
'0x10'
)
self
.
assertEqual
(
hex
(
16L
),
'0x10'
)
self
.
assertEqual
(
hex
(
-
16
),
'-0x10'
)
self
.
assertEqual
(
hex
(
-
16L
),
'-0x10'
)
self
.
assertRaises
(
TypeError
,
hex
,
{})
def
test_oct
(
self
):
self
.
assertEqual
(
oct
(
0
),
'0o0'
)
self
.
assertEqual
(
oct
(
100
),
'0o144'
)
self
.
assertEqual
(
oct
(
100L
),
'0o144'
)
self
.
assertEqual
(
oct
(
-
100
),
'-0o144'
)
self
.
assertEqual
(
oct
(
-
100L
),
'-0o144'
)
self
.
assertRaises
(
TypeError
,
oct
,
())
def
test_main
(
verbose
=
None
):
test
.
test_support
.
run_unittest
(
BuiltinTest
)
if
__name__
==
"__main__"
:
test_main
(
verbose
=
True
)
Misc/NEWS
View file @
a73fbe79
...
@@ -12,6 +12,14 @@ What's New in Python 2.6 alpha 1?
...
@@ -12,6 +12,14 @@ What's New in Python 2.6 alpha 1?
Core and builtins
Core and builtins
-----------------
-----------------
- Added the future_builtins module, which contains hex() and oct().
These are the PEP 3127 version of these functions, designed to be
compatible with the hex() and oct() builtins from Python 3.0. They
differ slightly in their output formats from the existing, unchanged
Python 2.6 builtins. The expected usage of the future_builtins
module is:
from future_builtins import hex, oct
- Issue #1600: Modifed PyOS_ascii_formatd to use at most 2 digit
- Issue #1600: Modifed PyOS_ascii_formatd to use at most 2 digit
exponents for exponents with absolute value < 100. Follows C99
exponents for exponents with absolute value < 100. Follows C99
standard. This is a change on Windows, which would use 3 digits.
standard. This is a change on Windows, which would use 3 digits.
...
...
Modules/future_builtins.c
0 → 100644
View file @
a73fbe79
/* future_builtins module */
/* This module provides functions that will be builtins in Python 3.0,
but that conflict with builtins that already exist in Python
2.x. */
#include "Python.h"
PyDoc_STRVAR
(
module_doc
,
"This module provides functions that will be builtins in Python 3.0,
\n
\
but that conflict with builtins that already exist in Python 2.x.
\n
\
\n
\
Functions:
\n
\
\n
\
hex(arg) -- Returns the hexidecimal representation of an integer
\n
\
oct(arg) -- Returns the octal representation of an integer
\n
\
\n
\
The typical usage of this module is to replace existing builtins in a
\n
\
module's namespace:
\n
\n
\
from future_builtins import hex, oct
\n
"
);
static
PyObject
*
builtin_hex
(
PyObject
*
self
,
PyObject
*
v
)
{
return
PyNumber_ToBase
(
v
,
16
);
}
PyDoc_STRVAR
(
hex_doc
,
"hex(number) -> string
\n
\
\n
\
Return the hexadecimal representation of an integer or long integer."
);
static
PyObject
*
builtin_oct
(
PyObject
*
self
,
PyObject
*
v
)
{
return
PyNumber_ToBase
(
v
,
8
);
}
PyDoc_STRVAR
(
oct_doc
,
"oct(number) -> string
\n
\
\n
\
Return the octal representation of an integer or long integer."
);
/* List of functions exported by this module */
static
PyMethodDef
module_functions
[]
=
{
{
"hex"
,
builtin_hex
,
METH_O
,
hex_doc
},
{
"oct"
,
builtin_oct
,
METH_O
,
oct_doc
},
{
NULL
,
NULL
}
/* Sentinel */
};
/* Initialize this module. */
PyMODINIT_FUNC
initfuture_builtins
(
void
)
{
PyObject
*
m
;
m
=
Py_InitModule3
(
"future_builtins"
,
module_functions
,
module_doc
);
if
(
m
==
NULL
)
return
;
/* any other initialization needed */
}
PC/config.c
View file @
a73fbe79
...
@@ -12,6 +12,7 @@ extern void initaudioop(void);
...
@@ -12,6 +12,7 @@ extern void initaudioop(void);
extern
void
initbinascii
(
void
);
extern
void
initbinascii
(
void
);
extern
void
initcmath
(
void
);
extern
void
initcmath
(
void
);
extern
void
initerrno
(
void
);
extern
void
initerrno
(
void
);
extern
void
initfuture_builtins
(
void
);
extern
void
initgc
(
void
);
extern
void
initgc
(
void
);
#ifndef MS_WINI64
#ifndef MS_WINI64
extern
void
initimageop
(
void
);
extern
void
initimageop
(
void
);
...
@@ -84,6 +85,7 @@ struct _inittab _PyImport_Inittab[] = {
...
@@ -84,6 +85,7 @@ struct _inittab _PyImport_Inittab[] = {
{
"binascii"
,
initbinascii
},
{
"binascii"
,
initbinascii
},
{
"cmath"
,
initcmath
},
{
"cmath"
,
initcmath
},
{
"errno"
,
initerrno
},
{
"errno"
,
initerrno
},
{
"future_builtins"
,
initfuture_builtins
},
{
"gc"
,
initgc
},
{
"gc"
,
initgc
},
#ifndef MS_WINI64
#ifndef MS_WINI64
{
"imageop"
,
initimageop
},
{
"imageop"
,
initimageop
},
...
...
PCbuild/pythoncore.vcproj
View file @
a73fbe79
...
@@ -1050,6 +1050,10 @@
...
@@ -1050,6 +1050,10 @@
RelativePath=
"..\Modules\errnomodule.c"
RelativePath=
"..\Modules\errnomodule.c"
>
>
</File>
</File>
<File
RelativePath=
"..\Modules\future_builtins.c"
>
</File>
<File
<File
RelativePath=
"..\Modules\gcmodule.c"
RelativePath=
"..\Modules\gcmodule.c"
>
>
...
...
setup.py
View file @
a73fbe79
...
@@ -417,6 +417,9 @@ class PyBuildExt(build_ext):
...
@@ -417,6 +417,9 @@ class PyBuildExt(build_ext):
libraries
=
math_libs
)
)
libraries
=
math_libs
)
)
exts
.
append
(
Extension
(
'datetime'
,
[
'datetimemodule.c'
,
'timemodule.c'
],
exts
.
append
(
Extension
(
'datetime'
,
[
'datetimemodule.c'
,
'timemodule.c'
],
libraries
=
math_libs
)
)
libraries
=
math_libs
)
)
# code that will be builtins in the future, but conflict with the
# current builtins
exts
.
append
(
Extension
(
'future_builtins'
,
[
'future_builtins.c'
])
)
# random number generator implemented in C
# random number generator implemented in C
exts
.
append
(
Extension
(
"_random"
,
[
"_randommodule.c"
])
)
exts
.
append
(
Extension
(
"_random"
,
[
"_randommodule.c"
])
)
# fast iterator tools implemented in C
# fast iterator tools implemented in C
...
...
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