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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: client/libs/logdog/streamname.py
diff --git a/client/libs/logdog/streamname.py b/client/libs/logdog/streamname.py
new file mode 100644
index 0000000000000000000000000000000000000000..516226b93bf735eacfd324a756e517eee031e483
--- /dev/null
+++ b/client/libs/logdog/streamname.py
@@ -0,0 +1,44 @@
+# Copyright 2016 The LUCI Authors. All rights reserved.
+# Use of this source code is governed by the Apache v2.0 license that can be
+# found in the LICENSE file.
+
+import re
+import types
+
+_SEGMENT_RE_BASE = r'[a-zA-Z0-9][a-zA-Z0-9:_\-.]*'
+_STREAM_NAME_RE = re.compile('^(' + _SEGMENT_RE_BASE + ')(/' +
+ _SEGMENT_RE_BASE + ')*$')
+_MAX_STREAM_NAME_LENGTH = 4096
+
+_MAX_TAG_KEY_LENGTH = 64
+_MAX_TAG_VALUE_LENGTH = 4096
+
+def validate_stream_name(v, maxlen=None):
+ """Verifies that a given stream name is valid.
+
+ Args:
+ v (str): The stream name string.
+
+
+ Raises:
+ ValueError if the stream name is invalid.
+ """
+ maxlen = maxlen or _MAX_STREAM_NAME_LENGTH
+ if len(v) > maxlen:
+ raise ValueError('Maximum length exceeded (%d > %d)' % (len(v), maxlen))
+ if _STREAM_NAME_RE.match(v) is None:
+ raise ValueError('Invalid stream name')
+
+
+def validate_tag(key, value):
+ """Verifies that a given tag key/value is valid.
+
+ Args:
+ k (str): The tag key.
+ v (str): The tag value.
+
+ Raises:
+ ValueError if the tag is not valid.
+ """
+ validate_stream_name(key, maxlen=_MAX_TAG_KEY_LENGTH)
+ validate_stream_name(value, maxlen=_MAX_TAG_VALUE_LENGTH)
« 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