Since it seems like the berkdb USE flag of Python is suppoesd to be deprecated, you probably should see to migrate this to whatever the python team wants to keep up to date. have fun!
Jesus Cea rather no longer maintains bsddb, but he still maintains bsddb3, so you should use bsddb3. Please apply the attached patch and replace dependency on >=dev-lang/python-2.5[berkdb] with >=dev-lang/python-2.5 and dev-python/bsddb3.
Created attachment 205292 [details, diff] gramps-3.1.2-use_bsddb3.patch
This is fixed in gramps 3.1.2-r1, thanks for the patch and patience. I reported it upstream, too.