Before us is Mishnah 10 in chapter 4 of Maseches Avodah Zarah. The Mishnah discusses a series of cases in which it is unclear how to treat a Jew's wine, because it came into questionable contact with a gentile.
The first case - a gentile standing beside the pit:
"Oved kochavim shenimtza omed b'tzad habor shel yayin" - a Jew has kosher wine sitting in a pit and fermenting there, and suddenly a gentile is discovered standing beside the pit. It does not appear that he touched the wine, but it is certainly possible that he did.
The Mishnah's answer rests on a basic assumption: a person is concerned for his good name and does not want to look like a thief or a swindler. Therefore, under ordinary circumstances we assume that a gentile standing beside a Jew's wine did not touch it at all, since he does not want to be caught doing something improper. But if he has an excuse to taste the wine or to touch it - for example, when he has a claim on it - then he is no longer concerned, and if he is caught he will say: "This wine is mine," or "I have a claim on this wine and I am merely inspecting it."
"Im yesh lo alav milveh" - if the gentile lent money to the Jew and the wine serves as collateral for that loan, then were he caught touching or sipping it he would answer: "This wine is going to be mine, the loan has come due and I am checking my collateral." Since he is not embarrassed, we must assume that he may well have touched the wine - and therefore the wine is forbidden, even to derive benefit from it.
"Ein lo alav milveh" - if the gentile has no monetary claim or future claim on the wine, he has no business touching it, and because of his concern for his good name we assume that he did not touch it - and therefore the wine is permitted even to drink.
The second case - four acts in which the contact is not for the sake of libation:
"Nafal labor v'alah" - a gentile who fell into the wine pit and drowned in it, and when he was brought up from there he was already dead. We do not assume that on his way to drowning he occupied himself with a libation, and therefore this is not yayin nesech and there is no prohibition of deriving benefit. This is on condition that he drowned; had he come up alive, he would certainly have given thanks to his idol on his way out and splashed a bit for the sake of a libation, and the wine would have become forbidden.
"Hayah modado b'kaneh" - a gentile working there who measures the wine with a reed that serves as a measuring stick. Even though he touched the Jew's wine, he did so only for the sake of his work - he is measuring, not making a libation.
"Hitiz es hatzira'ah b'kaneh" - he removed with a reed a wasp that was on the surface of the wine. Here too the contact is only indirect, and his action was intended to protect the wine, not to make a libation.
"Hayah metape'ach al pi chavis merutachas" - he patted with his hand on the surface of a barrel of fermenting wine. When wine ferments it bubbles, the carbon dioxide is released by the fermentation process, and the foam that rises is liable to overflow. The patting bursts the bubbles through the physical contact itself, and the oils on the hand also cause the bubbles to subside (as is done with the foam on beer as well). This is the most severe of the four cases, since the gentile actually touches the barrel of wine with his hand, and even so the wine is not forbidden for benefit, for it is clear that he acted in order to tend to the wine as a workman does, and not for the sake of a libation.
In all four cases the wine remains forbidden to drink because of 'stam yeinam' - an additional rabbinic decree, meant to prevent intermarriage with their daughters: one never drinks wine that a gentile touched. But it is not forbidden for benefit, and the Jew may sell it to another gentile.
Regarding the measuring, the Shulchan Aruch brings two views on the question of whether it matters that the measuring was done with a reed, that is, with indirect contact. Some understand that even if the gentile put his hands right into the wine pit, as long as he did so for the sake of measuring it makes no difference: since there is no reason to assume he touched it for the sake of a libation, the wine is forbidden only to drink and is permitted for benefit.
If so, why did the Mishnah specify "with a reed"? The answer is that these four cases were actual incidents that occurred and were brought before the beis din. It may be, then, that the incident as it happened was done with a reed, but this detail is not what determines the law.
And indeed the Mishnah explicitly testifies that all four scenarios occurred, and the beis din - the Sanhedrin and the Sages - ruled that it is permitted to sell it: one does not drink it, since it is forbidden to drink because of 'stam yeinam,' but it is not yayin nesech, and therefore it is permitted for benefit and may be sold to another gentile.
The view of Rabbi Shimon: In these four cases Rabbi Shimon is lenient and permits the wine even to drink. His reasoning: there is indeed a rabbinic law of 'stam yeinam,' that any wine a gentile touched becomes forbidden to a Jew to drink, but in his view this applies only to wine that belonged to a gentile. Wine belonging to a Jew that a gentile merely touched - such contact is not enough to forbid it on account of intermarriage. The halachah, however, does not follow his view.
The third case - "natal es hechavis uzrakah bachamaso labor":
A non-Jew is standing beside a pit of wine, and something makes him angry. He picks up an empty barrel and throws it into the pit, causing the wine in the pit to splash. It turns out that the non-Jew moved the wine, but certainly not for the purpose of a libation, rather to vent his frustration. Is that enough to forbid the wine? The answer: certainly not.
The Gemara explains that if he literally threw the barrel and it flew through the air and fell into the pit, there is no novelty here at all: the wine remains permitted quite simply, since there is no contact whatsoever between the non-Jew and the wine, neither direct nor indirect, but only his kocho - the energy he invested in the barrel while it was flying through the air, and that never suffices to forbid the wine.
Therefore the case in the Mishnah is that the non-Jew pushes the barrel, and for at least one moment his hand or his kicking foot is on one side of the barrel while the wine is already touching the other side. It turns out that for a brief moment he moved the wine indirectly, through the force of the barrel: a hand on the far side moves wine on the other side - that is indirect contact. But here another factor joins in: the absence of any intention to touch the wine, unlike the previous cases, where he inserted the reed on purpose in order to flick away the wasp or in order to measure. Here there is only indirect contact with no intention whatsoever to touch the wine, since his entire aim is to kick the barrel or throw it or push it - and therefore the wine remains permitted.
And this is how the words of the Mishnah are read: "natal es hechavis" - the non-Jew took hold of an empty barrel; "uzrakah bachamaso labor" - and in his anger he threw it into the pit; "zeh hayah hama'aseh" - this incident actually happened; "v'hichshiru" - and the beis din permitted the wine even for drinking, for although there was indirect contact here, it was not done for the sake of touching the wine at all, and therefore the wine remains completely permitted.