A luxury Mexican resort is taking a strange approach in defending itself against a lawsuit claiming its negligence caused a California woman to be sexually assaulted in one of its pricey villas: It’s blaming the victim.

The Esperanza Resort in Cabo San Lucas said in court papers the “conduct” of the California mother of two led to the horrific attack.

The woman, a doctor in her 30s on a girls getaway, was asleep in her bedroom in her $1,700-a-night villa — where President Obama and Jay Z and Beyoncé have stayed on separate occasions — when a hotel waiter entered her bedroom and put his fingers in her vagina, according to her lawsuit.

When she awoke and realized what was happening, the waiter “urged her to ‘be quiet’ and told her that his actions were ‘part of the service,’ ” according to the complaint.

The assailant then started to unbuckle his pants, but then left quickly when he heard her friends approaching, court papers allege.

The woman and her friends made a report to resort management and to the local police — and the Esperanza, owned by Auberge Resorts LLC, sent them home on a chartered plane after they missed their scheduled flight because of the time needed to file a police report.

Still, lawyers for the resort blame the woman’s “negligence” for the attack.

“The plaintiff voluntarily and knowingly assumed all of the risks” in staying at the five-star resort that overlooks the Sea of Cortez, its answer to the suit claims.

“Auberge and its attorneys should be ashamed of themselves,” said Paul Llewellyn, the woman’s lawyer. “This tired victim-blaming defense will not succeed.”

The woman is identified in the suit only as Jane Doe.

The case follows a series of high-profile reports involving vacationers that have said they were assaulted or drugged at Mexican resorts that they booked on TripAdvisor.

The online travel agency was publicly flogged for deleting posts on its website from the victims of these crimes.

The Needham, Mass., company has since apologized for deleting the alarming posts. It has begun to post warnings about properties that have been in the news for alleged crimes against their guests.

There were no warnings on TripAdvisor’s listing for the Auberge Esperanza as of Tuesday evening.

The California woman did not book her vacation through TripAdvisor, and the site wasn’t named in the suit.

Management of the resort should have known the attacker could be dangerous, the suit said.

“A cursory search of his social media presence would have alerted Auberge to highly disturbing and sexually violent images posted on his publicly available Facebook page,” the complaint states, “including a picture of a naked couple engaging in sexual intercourse with the female covering her face in pain” — as well as the cover photo of his Facebook page, showing him holding up his middle finger.

The resort’s management, through a spokesperson, said it does not comment on pending litigation.