i was reading the bson documentation and came across this part :
class bson.binary.Binary(data[, subtype=OLD_BINARY_SUBTYPE])¶
Bases: str
Representation of BSON binary data.
This is necessary because we want to represent Python strings as
the BSON string type. We need to wrap binary data so we can tell the
difference between what should be considered binary data and what
should be considered a string when we encode to BSON.
reference :
http://api.mongodb.org/python/current/api/bson/binary.html#module-bson.binary
my question is what does Bases represent here
Also what kind of an object wud this be.. will this be a
bson.binary.Binary object or bson.BSON object
Can i check my data representation with
bson.is_valid(bson)¶
Check that the given string represents valid BSON data.
Raises TypeError if bson is not an instance of str. Returns True
if bson is valid BSON, False otherwise.
I tried it on my own and i get a false for binary.Binary(data)
but a true for
bson_string = BSON.from_dict({ 'data': binary.Binary( data ) })
the entire program is as follows:
from bson import is_valid,binary,BSON
f = open("/home/roshini/Downloads/bsoneg.pdf", "rb")
data = f.read();
bson_string = BSON.from_dict({ 'data': binary.Binary( data ) })
bson_string1 = binary.Binary( data )
stringdata= is_valid(bson_string)
bindata = is_valid(bson_string1)
print boo
print path
new_f = open('decoded.pdf','w')
new_f.write(binary.Binary( data ))
new_f.close()