8000 Merge pull request #91 from hynek/decorators · yeahnoob/client_python@cba7100 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cba7100

Browse files
authored
Merge pull request prometheus#91 from hynek/decorators
Bundle decorator.py and fix decorators
2 parents 700ac29 + 6d5d72b commit cba7100

File tree

5 files changed

+452
-22
lines changed

5 files changed

+452
-22
lines changed

.coveragerc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[run]
22
branch = True
33
source = prometheus_client
4+
omit =
5+
prometheus_client/decorator.py
46

57
[paths]
68
source =
@@ -9,4 +11,4 @@ source =
911
.tox/pypy/site-packages/prometheus_client
1012

1113
[report]
12-
show_missing = True
14+
show_missing = True

NOTICE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
Prometheus instrumentation library for Python applications
22
Copyright 2015 The Prometheus Authors
3+
4+
This product bundles decorator 4.0.10 which is available under a "2-clause BSD"
5+
license. For details, see prometheus_client/decorator.py.

prometheus_client/core.py

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
# Python 3
1515
unicode = str
1616

17-
from functools import wraps
1817
from threading import Lock
1918

19+
from .decorator import decorate
20+
2021
_METRIC_NAME_RE = re.compile(r'^[a-zA-Z_:][a-zA-Z0-9_:]*$')
2122
_METRIC_LABEL_NAME_RE = re.compile(r'^[a-zA-Z_:][a-zA-Z0-9_:]*$')
2223
_RESERVED_METRIC_LABEL_NAME_RE = re.compile(r'^__.*$')
@@ -657,11 +658,10 @@ def __exit__(self, typ, value, traceback):
657658
self._histogram.observe(max(time.time() - self._start, 0))
658659

659660
def __call__(self, f):
660-
@wraps(f)
661-
def wrapped(*args, **kwargs):
661+
def wrapped(func, *args, **kwargs):
662662
with self:
663-
return f(*args, **kwargs)
664-
return wrapped
663+
return func(*args, **kwargs)
664+
return decorate(f, wrapped)
665665

666666

667667
class _ExceptionCounter(object):
@@ -677,11 +677,10 @@ def __exit__(self, typ, value, traceback):
677677
self._counter.inc()
678678

679679
def __call__(self, f):
680-
@wraps(f)
681-
def wrapped(*args, **kwargs):
680+
def wrapped(func, *args, **kwargs):
682681
with self:
683-
return f(*args, **kwargs)
684-
return wrapped
682+
return func(*args, **kwargs)
683+
return decorate(f, wrapped)
685684

686685

687686
class _InprogressTracker(object):
@@ -695,11 +694,10 @@ def __exit__(self, typ, value, traceback):
695694
self._gauge.dec()
696695

697696
def __call__(self, f):
698-
@wraps(f)
699-
def wrapped(*args, **kwargs):
697+
def wrapped(func, *args, **kwargs):
700698
with self:
701-
return f(*args, **kwargs)
702-
return wrapped
699+
return func(*args, **kwargs)
700+
return decorate(f, wrapped)
703701

704702

705703
class _SummaryTimer(object):
@@ -714,11 +712,10 @@ def __exit__(self, typ, value, traceback):
714712
self._summary.observe(max(time.time() - self._start, 0))
715713

716714
def __call__(self, f):
717-
@wraps(f)
718-
def wrapped(*args, **kwargs):
715+
def wrapped(func, *args, **kwargs):
719716
with self:
720-
return f(*args, **kwargs)
721-
return wrapped
717+
return func(*args, **kwargs)
718+
return decorate(f, wrapped)
722719

723720

724721
class _GaugeTimer(object):
@@ -733,8 +730,7 @@ def __exit__(self, typ, value, traceback):
733730
self._gauge.set(max(time.time() - self._start, 0))
734731

735732
def __call__(self, f):
736-
@wraps(f)
737-
def wrapped(*args, **kwargs):
733+
def wrapped(func, *args, **kwargs):
738734
with self:
739-
return f(*args, **kwargs)
740-
return wrapped
735+
return func(*args, **kwargs)
736+
return decorate(f, wrapped)

0 commit comments

Comments
 (0)
0