Заметка начинающим, которые часто сталкиваются с подобной непоняткой.
Ситуация следующая, есть список файлов:
names = [
'image.bmp',
'second.txt.bkp',
'data.db',
'.config.cfg',
'file.ext.bkp'
]
И мы хотим убрать у них окончание ".bkp".
Не знаю зачем, пример довольно надуманный) Но суть он показывает, а это главное.
Те, кто еще не очень знаком с библиотекой os.path или pathlib, вероятно решат обработать имена как строки. И тут вполне подойдет метод строки strip().
Что делает этот метод? Он отрезает указанные символы по обеим сторонам строки. Если ничего не указать, то убирает невидимые символы (пробелы, табуляции и переносы строк).
В нашем случае будет выглядеть вот так:
>>> name.strip('.bkp')
То есть просим удалить строку '.bkp' по краям имени файла, если таковая есть.
Можно применить аналогичный метод rstrip(), чтобы отрезать только справа, но для этого примера используем обычный.
>>> for name in names:
>>> print(name.strip('.bkp'))
image.bm
second.txt
data.d
config.cfg
file.ext
Хм, что-то не то с нашими именами! Что случилось??? Видим нежелательное переименование в именах, где и близко не было указанной строки '.bkp'
А дело всё в том, что данный метод ищет не указанную строку, а указанные символы, и не важно в каком порядке.
Для метода strip() строка '.bkp' это не паттерн для поискаа список символов. Потому он отрезал симовол 'p' от '.bmp' и удалил точку из файла '.config.cfg'.
Как тогда правильно заменить именно паттерн? Для начинающего можно посоветовать метод строки replace(), который как раз использует для замены указанную строку целиком. В нашем примере заменим её на пустую строку.
>>> for name in names:
>>> print(name.replace('.bkp', ''))
image.bmp
second.txt
data.db
.config.cfg
file.ext
Уже лучше, но помните, это лишь пример про strip(). Для работы с именами файлов есть способы и более "правильные", дающие однозначно верный результат. Я взял файлы только в качестве примера. Даже replase() тут может сделать не то что ожидаем.
Просто впредь будьте внимательны с этим strip().
#basic
📰 Nginx 1.31 Released with HTTP Forward Proxy Support
Nginx 1.31 introduces HTTP forward proxy support and addresses security vulnerabilities in HTTP/2, HTTP/3, OCSP, and core modules.
🔗 Source: https://linuxiac.com/nginx-1-31-released-with-http-forward-proxy-support/
#nginx
📰 Kubernetes sets a new standard for release notes, also kills Ingress NGINX
Release team explains links between Version 1.36 and classic print The Great Wave off Kanagawa Kubernetes issued a new release called “Haru” on Wednesday, and the release notes and logo might be more interesting than the software.…
🔗 Source: https://go.theregister.com/feed/www.theregister.com/2026/04/23/kubernetes_1_36_haru/
#nginx
📰 I don't use Tailscale or Nginx to access my home lab remotely, here's what I use instead
One of the most useful services to any home labber is a VPN, so that you can access your home network from anywhere and browse as if you're at home. That not only lets you use any self-hosted services you have on your NAS without having to open ports to the wider internet, but it also circumvents any geo-blocked services and nicely encrypts your data, so nobody can snoop in.
🔗 Source: https://www.xda-developers.com/i-dont-use-tailscale-or-nginx-to-access-my-home-lab-remotely-heres-what-i-use-instead/
#nginx
📰 Nginx 1.30 Released With Multipath TCP, ECH & More
Nginx 1.30 was just released as the newest stable version of this popular web server. Nginx 1.30 incorporates all of the changes from the Nginx 1.29.x mainline branch to provide a lot of new functionality like Multipath TCP (MPTCP)...
🔗 Source: https://www.phoronix.com/news/Nginx-1.30-Released
#nginx
📰 Nginx 1.29.7 Delivers Multipath TCP Support
Released this week was Nginx 1.29.7 as the newest mainline version of this HTTP(S) web server. Releasing alongside Nginx 1.28.3 stable, it fixed buffer overflow vulnerabilities and some other vulnerabilities. Making Nginx 1.29.7 more exciting though is that it landed Multipath TCP support...
🔗 Source: https://www.phoronix.com/news/Nginx-1.29.7-Multipath-TCP
#nginx
http://blog.povilasb.com/posts/python-asyncio-vs-nginx-performance/
While I was playing with Python #asyncio I got interested in how well it performs serving data over TLS compared to #Nginx. So I implemented a small HTTPS server with asyncio:
👩💻 Nginx Path Configuration Pitfalls.
• Nginx — это веб-сервер, на котором работает треть всех сайтов в мире. Но если забыть или проигнорировать некоторые ошибки в настройках, можно стать отличной мишенью для атакующих. Благодаря этому материалу, можно понять какие ошибки в конфигурациях встречаются чаще всего и как их исправить.
Attacks:
• Nginx Configuration Vulnerability;
• Exploiting Trailing Slash Misconfiguration;
• Exploiting Parent Directory Access;
• Impact Without Trailing Slash on Alias;
• Combined Impact.
Defend Against Attacks:
• Update Nginx;
• Configuration Check;
• Use Configuration Management;
• Security Headers;
• Access Control;
• Directory Listing;
• Alias Traversal Protection;
• HTTP to HTTPS Redirect;
• SSL Configuration;
• Rate Limiting;
• Connection Limits;
• Custom Error Pages;
• Gzip Compression;
• Client-Side Caching;
• HTTP2 Protocol;
• Secure File Permissions;
• Web Application Firewall (WAF);
• Monitoring and Logging;
• SSH Hardening;
• Firewall Configuration;
• Two-Factor Authentication;
• Regular Backups;
• Deny Hidden Files;
• IP Whitelisting;
• Disable Unused Modules;
• Use Trailing Slash in Alias Directives;
• Regular Expression Matching;
• Implement Strict Location Paths.
#Nginx#devsecops