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
eee9498b
Commit
eee9498b
authored
Nov 12, 1991
by
Guido van Rossum
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial revision
parent
5478cc68
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
190 additions
and
0 deletions
+190
-0
Lib/lib-old/newdir.py
Lib/lib-old/newdir.py
+79
-0
Lib/newdir.py
Lib/newdir.py
+79
-0
Lib/tempfile.py
Lib/tempfile.py
+32
-0
No files found.
Lib/lib-old/newdir.py
0 → 100644
View file @
eee9498b
# New dir() function and other attribute-related goodies
# This should become a built-in function
#
def
getattr
(
x
,
name
):
return
eval
(
'x.'
+
name
)
# This should be the new dir(), except that it should still list
# the current local name space by default
#
def
listattrs
(
x
):
try
:
dictkeys
=
x
.
__dict__
.
keys
()
except
(
NameError
,
TypeError
):
dictkeys
=
[]
#
try
:
methods
=
x
.
__methods__
except
(
NameError
,
TypeError
):
methods
=
[]
#
try
:
members
=
x
.
__members__
except
(
NameError
,
TypeError
):
members
=
[]
#
try
:
the_class
=
x
.
__class__
except
(
NameError
,
TypeError
):
the_class
=
None
#
try
:
bases
=
x
.
__bases__
except
(
NameError
,
TypeError
):
bases
=
()
#
total
=
dictkeys
+
methods
+
members
if
the_class
:
# It's a class instace; add the class's attributes
# that are functions (methods)...
class_attrs
=
listattrs
(
the_class
)
class_methods
=
[]
for
name
in
class_attrs
:
if
is_function
(
getattr
(
the_class
,
name
)):
class_methods
.
append
(
name
)
total
=
total
+
class_methods
elif
bases
:
# It's a derived class; add the base class attributes
for
base
in
bases
:
base_attrs
=
listattrs
(
base
)
total
=
total
+
base_attrs
total
.
sort
()
return
total
i
=
0
while
i
+
1
<
len
(
total
):
if
total
[
i
]
=
total
[
i
+
1
]:
del
total
[
i
+
1
]
else
:
i
=
i
+
1
return
total
# Helper to recognize functions
#
def
is_function
(
x
):
return
type
(
x
)
=
type
(
is_function
)
# Approximation of builtin dir(); this lists the user's
# variables by default, not the current local name space.
# Use a class method to make a function that can be called
# with or without arguments.
#
class
_dirclass
():
def
dir
(
args
):
if
type
(
args
)
=
type
(()):
return
listattrs
(
args
[
1
])
else
:
import
__main__
return
listattrs
(
__main__
)
dir
=
_dirclass
().
dir
Lib/newdir.py
0 → 100644
View file @
eee9498b
# New dir() function and other attribute-related goodies
# This should become a built-in function
#
def
getattr
(
x
,
name
):
return
eval
(
'x.'
+
name
)
# This should be the new dir(), except that it should still list
# the current local name space by default
#
def
listattrs
(
x
):
try
:
dictkeys
=
x
.
__dict__
.
keys
()
except
(
NameError
,
TypeError
):
dictkeys
=
[]
#
try
:
methods
=
x
.
__methods__
except
(
NameError
,
TypeError
):
methods
=
[]
#
try
:
members
=
x
.
__members__
except
(
NameError
,
TypeError
):
members
=
[]
#
try
:
the_class
=
x
.
__class__
except
(
NameError
,
TypeError
):
the_class
=
None
#
try
:
bases
=
x
.
__bases__
except
(
NameError
,
TypeError
):
bases
=
()
#
total
=
dictkeys
+
methods
+
members
if
the_class
:
# It's a class instace; add the class's attributes
# that are functions (methods)...
class_attrs
=
listattrs
(
the_class
)
class_methods
=
[]
for
name
in
class_attrs
:
if
is_function
(
getattr
(
the_class
,
name
)):
class_methods
.
append
(
name
)
total
=
total
+
class_methods
elif
bases
:
# It's a derived class; add the base class attributes
for
base
in
bases
:
base_attrs
=
listattrs
(
base
)
total
=
total
+
base_attrs
total
.
sort
()
return
total
i
=
0
while
i
+
1
<
len
(
total
):
if
total
[
i
]
=
total
[
i
+
1
]:
del
total
[
i
+
1
]
else
:
i
=
i
+
1
return
total
# Helper to recognize functions
#
def
is_function
(
x
):
return
type
(
x
)
=
type
(
is_function
)
# Approximation of builtin dir(); this lists the user's
# variables by default, not the current local name space.
# Use a class method to make a function that can be called
# with or without arguments.
#
class
_dirclass
():
def
dir
(
args
):
if
type
(
args
)
=
type
(()):
return
listattrs
(
args
[
1
])
else
:
import
__main__
return
listattrs
(
__main__
)
dir
=
_dirclass
().
dir
Lib/tempfile.py
0 → 100644
View file @
eee9498b
# Temporary file name allocation
import
posix
import
path
# Changeable parameters (by clients!)...
# XXX Should the environment variable $TMPDIR override tempdir?
tempdir
=
'/usr/tmp'
template
=
'@'
# Kludge to hold mutable state
class
Struct
():
pass
G
=
Struct
()
G
.
i
=
0
# User-callable function
# XXX Should this have a parameter, like C's mktemp()?
# XXX Should we instead use the model of Standard C's tempnam()?
# XXX By all means, avoid a mess with four different functions like C...
def
mktemp
():
while
1
:
G
.
i
=
G
.
i
+
1
file
=
tempdir
+
'/'
+
template
+
`posix.getpid()`
+
'.'
+
`G.i`
if
not
path
.
exists
(
file
):
break
return
file
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