http://pet-snakes.com/why-snake-bite/comment-page-1
This is where you can learn about pet ownership, etc as it wasn't touched on as part of the topic and would be relevant.
That being said, there's a teeny tiny way around that illegal-to-own-poisonous-snakes law lvre brought up and it's that the character constantly tends to a snake outside of domestication. To disagree with her, not all snakes just run away from a fight. Black racers attack their foe (or really anything or anyone they feel has threatened them) though you have to consider environment. They're most prominent in the south via the U.S. With that little loophole, it's very possible to have a snake somewhat protective as they go on smell when striking at a target and if it smells you, would not attack you (if you aren't being threatening to it). On the other hand, it's like aiming a gun at two people fighting. If you shoot, one of them is going to die and it's a fifty fifty shot it might be the wrong guy. So you might want to step back if it's between a snake and a predator.
If it's a fictional story, it's more than possible to have a snake aware of loyalty (though it's
wrongfully known for disloyalty and cowardice) because a lot of snakes DO run from fights. If you're aiming at a realistic fictional story, it's still possible that a snake and a human get along so well that it makes a distinction, but I suggest you do a lot of studying on the instincts of snakes and find out what you could do to make a distinction. It would be stretch but so was this story about a boy who was sort of adopted by a bear who protected him from drowning in a river and getting mauled by a bobcat before returning him to society after him being lost in the woods.