I made that stock a while ago and never posted it's code.
But since people on this forum asked and continue asking for the code with similar functionality i decided to post that function.
EDIT
Uses fakemeta module and better technique now. See fm_strip_user_gun from the
Fakemeta Utilities.