File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Copyright 2009 10gen, Inc.
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ """Representation of binary data to be stored in or retrieved from Mongo.
16+
17+ This is necessary because we want to store normal strings as the Mongo string
18+ type. We need to wrap binary so we can tell the difference between what should
19+ be considered binary and what should be considered a string.
20+ """
21+
22+ def is_binary (data ):
23+ """Check if the given data is binary or not.
24+ """
25+ return isinstance (data , Binary )
26+
27+ class Binary (str ):
28+ """Binary data stored in or retrieved from Mongo.
29+ """
30+ pass
Original file line number Diff line number Diff line change 1+ # Copyright 2009 10gen, Inc.
2+ #
3+ # Licensed under the Apache License, Version 2.0 (the "License");
4+ # you may not use this file except in compliance with the License.
5+ # You may obtain a copy of the License at
6+ #
7+ # http://www.apache.org/licenses/LICENSE-2.0
8+ #
9+ # Unless required by applicable law or agreed to in writing, software
10+ # distributed under the License is distributed on an "AS IS" BASIS,
11+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+ # See the License for the specific language governing permissions and
13+ # limitations under the License.
14+
15+ """Tests for the Binary wrapper."""
16+
17+ import unittest
18+
19+ from pymongo import binary
20+
21+ class TestBinary (unittest .TestCase ):
22+ def setUp (self ):
23+ pass
24+
25+ def test_binary (self ):
26+ a_string = "hello world"
27+ a_binary = binary .Binary ("hello world" )
28+ self .assertTrue (a_binary .startswith ("hello" ))
29+ self .assertTrue (a_binary .endswith ("world" ))
30+ self .assertTrue (binary .is_binary (a_binary ))
31+ self .assertFalse (binary .is_binary (a_string ))
32+
33+ if __name__ == "__main__" :
34+ unittest .main ()
You can’t perform that action at this time.
0 commit comments