Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(431)

Side by Side Diff: client/libs/logdog/streamname.py

Issue 1961603002: Add LogDog Python client library. (Closed) Base URL: https://github.com/luci/luci-py@master
Patch Set: Remove "client." from package name, make pylint happy. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/libs/logdog/stream.py ('k') | client/libs/logdog/tests/bootstrap_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 # Copyright 2016 The LUCI Authors. All rights reserved.
2 # Use of this source code is governed by the Apache v2.0 license that can be
3 # found in the LICENSE file.
4
5 import re
6 import types
7
8 _SEGMENT_RE_BASE = r'[a-zA-Z0-9][a-zA-Z0-9:_\-.]*'
9 _STREAM_NAME_RE = re.compile('^(' + _SEGMENT_RE_BASE + ')(/' +
10 _SEGMENT_RE_BASE + ')*$')
11 _MAX_STREAM_NAME_LENGTH = 4096
12
13 _MAX_TAG_KEY_LENGTH = 64
14 _MAX_TAG_VALUE_LENGTH = 4096
15
16 def validate_stream_name(v, maxlen=None):
17 """Verifies that a given stream name is valid.
18
19 Args:
20 v (str): The stream name string.
21
22
23 Raises:
24 ValueError if the stream name is invalid.
25 """
26 maxlen = maxlen or _MAX_STREAM_NAME_LENGTH
27 if len(v) > maxlen:
28 raise ValueError('Maximum length exceeded (%d > %d)' % (len(v), maxlen))
29 if _STREAM_NAME_RE.match(v) is None:
30 raise ValueError('Invalid stream name')
31
32
33 def validate_tag(key, value):
34 """Verifies that a given tag key/value is valid.
35
36 Args:
37 k (str): The tag key.
38 v (str): The tag value.
39
40 Raises:
41 ValueError if the tag is not valid.
42 """
43 validate_stream_name(key, maxlen=_MAX_TAG_KEY_LENGTH)
44 validate_stream_name(value, maxlen=_MAX_TAG_VALUE_LENGTH)
OLDNEW
« no previous file with comments | « client/libs/logdog/stream.py ('k') | client/libs/logdog/tests/bootstrap_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698