Robot Framework Integrated Development Environment (RIDE)
stringcache.py
Go to the documentation of this file.
1
# Copyright 2008-2015 Nokia Networks
2
# Copyright 2016- Robot Framework Foundation
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
# http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
16
from
collections
import
OrderedDict
17
18
from
robotide.lib.robot.utils
import
compress_text
19
20
21
class
StringIndex
(
int
):
22
pass
23
24
25
class
StringCache
():
26
29
_compress_threshold = 80
30
33
_use_compressed_threshold = 1.1
34
37
_zero_index =
StringIndex
(0)
38
39
def
__init__
(self):
40
self.
_cache
_cache = OrderedDict({
'*'
: self.
_zero_index
_zero_index})
41
42
def
add
(self, text):
43
if
not
text:
44
return
self.
_zero_index
_zero_index
45
text = self.
_encode
_encode(text)
46
if
text
not
in
self.
_cache
_cache:
47
self.
_cache
_cache[text] =
StringIndex
(len(self.
_cache
_cache))
48
return
self.
_cache
_cache[text]
49
50
def
_encode
(self, text):
51
raw = self.
_raw
_raw(text)
52
if
raw
in
self.
_cache
_cache
or
len(raw) < self.
_compress_threshold
_compress_threshold:
53
return
raw
54
compressed =
compress_text
(text)
55
if
len(compressed) * self.
_use_compressed_threshold
_use_compressed_threshold < len(raw):
56
return
compressed
57
return
raw
58
59
def
_raw
(self, text):
60
return
'*'
+text
61
62
def
dump
(self):
63
return
tuple(self.
_cache
_cache)
robotide.lib.robot.reporting.stringcache.StringCache
Definition:
stringcache.py:25
robotide.lib.robot.reporting.stringcache.StringCache._zero_index
_zero_index
Definition:
stringcache.py:37
robotide.lib.robot.reporting.stringcache.StringCache._compress_threshold
int _compress_threshold
Definition:
stringcache.py:29
robotide.lib.robot.reporting.stringcache.StringCache._use_compressed_threshold
float _use_compressed_threshold
Definition:
stringcache.py:33
robotide.lib.robot.reporting.stringcache.StringCache._encode
def _encode(self, text)
Definition:
stringcache.py:50
robotide.lib.robot.reporting.stringcache.StringCache._raw
def _raw(self, text)
Definition:
stringcache.py:59
robotide.lib.robot.reporting.stringcache.StringCache.dump
def dump(self)
Definition:
stringcache.py:62
robotide.lib.robot.reporting.stringcache.StringCache.__init__
def __init__(self)
Definition:
stringcache.py:39
robotide.lib.robot.reporting.stringcache.StringCache.add
def add(self, text)
Definition:
stringcache.py:42
robotide.lib.robot.reporting.stringcache.StringCache._cache
_cache
Definition:
stringcache.py:40
robotide.lib.robot.reporting.stringcache.StringIndex
Definition:
stringcache.py:21
robotide.lib.robot.reporting.jsexecutionresult.int
int
Definition:
jsexecutionresult.py:25
robotide.lib.robot.utils.compress.compress_text
def compress_text(text)
Definition:
compress.py:21
robotide.lib.robot.utils
Definition:
__init__.py:1
src
robotide
lib
robot
reporting
stringcache.py
Generated by
1.9.1