How pivot orientation is calculated when set to 'normal' transform orientation

Here is image with two selected vertices.
http://i.imgur.com/wZZE6CK.jpg

I marked by arrows, each vertex normal, and middle arrow is just average of both vertices.
But middle arrow do not match pivot orientation (it is set to normal). Do you know how pivot calculates its orientation when multiple vertices are selected (as mentioned above it is not just average of vertices normals)? What I really want to get is pivot Z axis orientation (vector). Any ideas?

I fixed it by ‘hack’. What I did was:
calculate vector from Vert1-vert2
perpendicularVec = Vect(V1-V2).cross(oldNormal) #if you reference image above it will give vector pointing out of monitor
newNormal = perpendicularVec .cross( Vect(V1-V2)) # this reverts above line, but now NewNormal is aligned to pivot Z axis.

Not beautiful but it works. It would be interesting anyway, how, where do I get gizmo data (loc, rot, scale) ?
And what it was for- trim based on selection:
https://dl.dropboxusercontent.com/u/26878362/AnimNodes/TrimSelection.gif

Custom transform orientations got a .matrix property, but built-in orientations do not expose something like that. You could add a transform orientation and read the matrix to get the orientation of the built-in local. But for all other types, own code is required to calculate the matrices.

Related source code:

initTransformOrientation
---- ED_getTransformOrientation
-------- getTransformOrientation
-------- createSpaceNormalTangent

Ok, thanks. So I will stick to manual calculation of normal in python.