FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
pythonVSCode/pythonFiles/rope/base/utils.py at master · privat1/pythonVSCode · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
privat1
/
pythonVSCode
Public
forked from
DonJayamanne/pythonVSCode
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
pythonVSCode
/
pythonFiles
/
rope
/
base
/
utils.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
83 lines (64 loc) · 2.2 KB
Breadcrumbs
pythonVSCode
/
pythonFiles
/
rope
/
base
/
utils.py
Copy path
File metadata and controls
83 lines (64 loc) · 2.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import
warnings
def
saveit
(
func
):
"""A decorator that caches the return value of a function"""
name
=
'_'
+
func
.
__name__
def
_wrapper
(
self
,
*
args
,
**
kwds
):
if
not
hasattr
(
self
,
name
):
setattr
(
self
,
name
,
func
(
self
,
*
args
,
**
kwds
))
return
getattr
(
self
,
name
)
return
_wrapper
cacheit
=
saveit
def
prevent_recursion
(
default
):
"""A decorator that returns the return value of `default` in recursions"""
def
decorator
(
func
):
name
=
'_calling_%s_'
%
func
.
__name__
def
newfunc
(
self
,
*
args
,
**
kwds
):
if
getattr
(
self
,
name
,
False
):
return
default
()
setattr
(
self
,
name
,
True
)
try
:
return
func
(
self
,
*
args
,
**
kwds
)
finally
:
setattr
(
self
,
name
,
False
)
return
newfunc
return
decorator
def
ignore_exception
(
exception_class
):
"""A decorator that ignores `exception_class` exceptions"""
def
_decorator
(
func
):
def
newfunc
(
*
args
,
**
kwds
):
try
:
return
func
(
*
args
,
**
kwds
)
except
exception_class
:
pass
return
newfunc
return
_decorator
def
deprecated
(
message
=
None
):
"""A decorator for deprecated functions"""
def
_decorator
(
func
,
message
=
message
):
if
message
is
None
:
message
=
'%s is deprecated'
%
func
.
__name__
def
newfunc
(
*
args
,
**
kwds
):
warnings
.
warn
(
message
,
DeprecationWarning
,
stacklevel
=
2
)
return
func
(
*
args
,
**
kwds
)
return
newfunc
return
_decorator
def
cached
(
count
):
"""A caching decorator based on parameter objects"""
def
decorator
(
func
):
return
_Cached
(
func
,
count
)
return
decorator
class
_Cached
(
object
):
def
__init__
(
self
,
func
,
count
):
self
.
func
=
func
self
.
cache
=
[]
self
.
count
=
count
def
__call__
(
self
,
*
args
,
**
kwds
):
key
=
(
args
,
kwds
)
for
cached_key
,
cached_result
in
self
.
cache
:
if
cached_key
==
key
:
return
cached_result
result
=
self
.
func
(
*
args
,
**
kwds
)
self
.
cache
.
append
((
key
,
result
))
if
len
(
self
.
cache
)
>
self
.
count
:
del
self
.
cache
[
0
]
return
result
Back
|
FazBrowse Home
|
New Git URL