MEXICO CITY (AP) — Swine flu has infected Mexico’s relations with China and other countries that have canceled airline flights and halted some trade. But its most prickly neighbor — the United States — now seems like the country’s most loyal friend.

Mexico is smarting from what it considers discriminatory actions by countries it had considered friendly, insisting the world should be grateful for its open and aggressive efforts to stem the spread of swine flu. The shutdown of public life cost Mexico $2.2 billion in the first 10 days after the epidemic was announced.

The government sent a plane to pick up 70 of its citizens quarantined in China. It rebuked Cuba, Ecuador, Argentina and Peru for banning flights to Mexico, saying they were acting “incongruously with our traditional ties of friendship.”

France tried — and failed — to win a European Union-wide ban on flights to Mexico.

All of that put the U.S. response in a very favorable light. Neither the United States nor Canada banned flights or restricted trade with Mexico. The three countries are partners in the North American Free Trade Agreement.

President Barack Obama forcefully rejected the idea of closing the border, despite arguments from conservative talk show hosts that swine flu showed immigration from Mexico was a threat.

The Obama administration cast the decision as a recognition of reality: Homeland Security Secretary Janet Napolitano said sealing the border would be extremely costly and pointless since the virus was already in the United States. Obama likened the idea to “closing the barn door after the horses are out.”

Even so, it was symbolically significant in Mexico, which protested when the U.S. began building a border fence under former President George W. Bush.

While Obama has also beefed up border security, he has pledged to renew efforts to push through immigration reforms that eluded the Bush administration, including extending a citizenship path for illegal immigrants. His emphasis on open borders during the swine flu outbreak could help set the tone.

“There was a very explicit recognition that the U.S. and Mexico cannot close their borders,” said Andrew Selee, director of the Mexico Institute at the Washington-based Wilson Center. “Maybe that tells you that Mexico is really more integrated with its neighbors to the north than the rest of Latin America.”

Mexico took note. The Foreign Relations Department held a special ceremony to thank the U.S. government both for keeping the border open and for providing aid and medical expertise.

“The way in which the border between Mexico and the United States stayed not only open but alive in the past days has been exemplary,” said Carlos Rico, Mexico’s deputy secretary for North American relations. “The open border is something that has not been recognized enough.”

Even members of the opposition leftist Democratic Revolution Party — long known for its nationalistic wariness of the United States — were impressed.

“I thought the reaction and response from the three countries — Mexico, the United States and Canada — was definitely laudable,” said Alfonso Suarez de Real, a lawmaker from the party. “It contrasted with the reaction that other countries have had.”

The experience added momentum to increasingly warming relations, coming on the heels of Obama’s April 16 visit to Mexico and his acknowledgment that Americans share the blame for violence south of border because of drug consumption and gun trafficking. Mexico, for its part, has set aside traditional sovereignty concerns in welcoming increased U.S. border security and even U.S. training for Mexico’s navy.

In contrast, relations with China have been frayed, threatening to undermine trade and investment between the two countries just as it has been picking up, said Hector Cuellar, president of the recently formed Mexico-China Chamber of Commerce.

Prominent Mexican companies have started opening operations in China in the last three years, while Mexican exports to China have jumped ninefold over the past decade to some $2 billion.

But Mexicans were angered when China banned the direct flights that leading Mexican airline Aeromexico started offering in October, and then quarantined Mexican travelers. Mexico canceled its participation at a Shanghai trade fair where it had meant to showcase its pork products — now banned in China and at least four other nations even though health experts say people can’t catch swine flu from meat.

The epidemic also set back Mexico’s efforts to improve ties with Cuba, which soured during the 2000-06 presidency of Vicente Fox, when Mexico voted at the U.N. in favor of monitoring human rights on the communist island.

Fox’s successor, Felipe Calderon, had planned a conciliatory trip to Cuba this year. That’s up in the air after Calderon said he may have to cancel because Cuba grounded flights to and from Mexico.

Mexican officials also didn’t take kindly to Fidel Castro lashing out after Cuba confirmed its first swine flu case, accusing Mexico of waiting to disclose the epidemic until after Obama visited, even though Canadian and U.S. scientists did not identify the virus in Mexican patients until a week later.

Deputy Health Secretary Mauricio Hernandez said Wednesday that Mexico would support a global compensation fund for countries that suffer from epidemics, and warned that the threat of trade and travel restrictions could provoke governments to hide future outbreaks.

“We were responsible, and we ended up with trade sanctions — we were discriminated against,” Hernandez said at an academic forum on swine flu. “So, the question is: What is the incentive (for countries to be open)?”