Skip to content

Commit 9554afb

Browse files
committed
55abb0c resgate do .htaccess em prod
1 parent ff62516 commit 9554afb

File tree

9 files changed

+27
-8738
lines changed

9 files changed

+27
-8738
lines changed

links/FPY.LI.htaccess

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,17 +1070,6 @@ RedirectTemp /24-27 https://docs.python.org/3/library/functools.html#functools.t
10701070
RedirectTemp /24-28 https://www.python.org/download/releases/2.2.3/descrintro/
10711071
RedirectTemp /24-29 https://github.com/lihaoyi/macropy
10721072
RedirectTemp /24-30 https://people.eecs.berkeley.edu/~bh/ss-toc2.html
1073-
# content of short.htaccess file created and managed by short.py
10741073

1075-
# appended: 2025-05-23 15:12:13
1076-
RedirectTemp /22 https://pythonfluente.com/2/#pattern_matching_case_study_sec
1077-
RedirectTemp /23 https://pythonfluente.com/2/#how_slicing_works
1078-
RedirectTemp /24 https://pythonfluente.com/2/#sliceable_sequence
1079-
RedirectTemp /25 https://pythonfluente.com/2/#virtual_subclass_sec
1080-
RedirectTemp /26 https://pythonfluente.com/2/#environment_class_ex
1081-
RedirectTemp /27 https://pythonfluente.com/2/#subclass_builtin_woes
1082-
RedirectTemp /28 https://pythonfluente.com/2/#slots_section
1083-
RedirectTemp /29 https://pythonfluente.com/2/#typeddict_sec
1084-
RedirectTemp /2a https://pythonfluente.com/2/#problems_annot_runtime_sec
1085-
RedirectTemp /2b https://pythonfluente.com/2/#legacy_deprecated_typing_box
1086-
RedirectTemp /2c https://pythonfluente.com/2/#positional_pattern_implement_sec
1074+
####################### end of custom URLs
1075+

links/FPY.LI.short.htaccess

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,3 @@ RedirectTemp /2c https://pythonfluente.com/2/#positional_pattern_implement_sec
1818
RedirectTemp /2d https://mitpress.mit.edu/9780262111584/the-art-of-the-metaobject-protocol/
1919
RedirectTemp /2e https://dabeaz.com/per.html
2020
RedirectTemp /2f https://pythonfluente.com/2/#iter_closer_look
21-
# appended: 2025-06-04 21:42:54
22-
RedirectTemp /2g https://docs.python.org/pt-br/3/reference/lexical_analysis.html#reserved-classes-of-identifiers
23-
RedirectTemp /2h https://docs.python.org/pt-br/3/library/doctest.html
24-
RedirectTemp /2j https://docs.python.org/pt-br/3.10/library/string.html#format-string-syntax
25-
RedirectTemp /2k https://docs.python.org/pt-br/3/library/stdtypes.html#truth
26-
RedirectTemp /2m https://docs.python.org/pt-br/3/tutorial/controlflow.html#unpacking-argument-lists
27-
RedirectTemp /2n https://docs.python.org/pt-br/3/reference/datamodel.html
28-
RedirectTemp /2p https://docs.python.org/pt-br/3/reference/datamodel.html
29-
RedirectTemp /2q https://dabeaz.com/per.html
30-
RedirectTemp /2r https://mitpress.mit.edu/books/art-metaobject-protocol
31-
RedirectTemp /2s https://docs.python.org/pt-br/3/reference/datamodel.html
32-
RedirectTemp /2t https://plone.org.br/

links/shorten.py

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,14 @@
1717
from collections.abc import Iterator
1818
from time import strftime
1919
from typing import NamedTuple
20-
from urllib.parse import urlparse, urlunparse
21-
from urllib.parse import ParseResult as Url
2220

23-
HTACCESS_CUSTOM = 'FPY.LI.custom.htaccess'
21+
HTACCESS_MAIN = 'FPY.LI.htaccess'
2422
HTACCESS_SHORT = 'FPY.LI.short.htaccess'
25-
HTACCESS_FILES = (HTACCESS_CUSTOM, HTACCESS_SHORT)
23+
HTACCESS_FILES = (HTACCESS_MAIN, HTACCESS_SHORT)
2624
BASE_DOMAIN = 'fpy.li'
2725

28-
type ShortCode = str
26+
type ShortCode = bytes
27+
type Url = str
2928
type RedirMap = dict[ShortCode, Url]
3029
type TargetMap = dict[Url, ShortCode]
3130

@@ -40,32 +39,33 @@ def load_redirects() -> tuple[RedirMap, TargetMap]:
4039
with open(filename) as fp:
4140
for line in fp:
4241
if line.startswith('RedirectTemp'):
43-
_, short, field2, *_ = line.split()
44-
short = short[1:] # Remove leading slash
45-
long = urlparse(field2)
42+
_, field1, long, *_ = line.split()
43+
short = field1.encode('ascii')[1:] # Remove leading slash
4644
assert short not in redirects, f'{filename}: duplicate redirect from {short}'
4745
# htaccess.custom is live since 2022, I can't change it to remove duplicate targets
48-
if filename != HTACCESS_CUSTOM:
49-
assert long not in targets, f'{filename}: duplicate redirect to {long}'
46+
#if filename != HTACCESS_MAIN:
47+
#assert long not in targets, f'{filename}: duplicate redirect to {long}'
48+
if long in targets:
49+
print(f'{filename}: duplicate redirect to {long}')
5050
redirects[short] = long
5151
targets[long] = short
5252

5353
return redirects, targets
5454

5555

56-
SDIGITS = '23456789abcdefghjkmnpqrstvwxyz'
56+
SDIGITS = b'23456789abcdefghjkmnpqrstvwxyz'
5757

5858

59-
def gen_short(start_len=1) -> Iterator[str]:
59+
def gen_short(start_len=1) -> Iterator[ShortCode]:
6060
"""Generate every possible sequence of SDIGITS, starting with start_len"""
6161
length = start_len
6262
while True:
6363
for short in itertools.product(SDIGITS, repeat=length):
64-
yield ''.join(short)
64+
yield bytes(short)
6565
length += 1
6666

6767

68-
def gen_unused_short(redirects: dict) -> Iterator[str]:
68+
def gen_unused_short(redirects: dict) -> Iterator[ShortCode]:
6969
"""Generate next available short URL of len >= 2."""
7070
for short in gen_short(2):
7171
if short not in redirects:
@@ -80,29 +80,30 @@ def shorten(urls: list[str]) -> list[ShortPair]:
8080
timestamp = strftime('%Y-%m-%d %H:%M:%S')
8181
with open(HTACCESS_SHORT, 'a') as fp:
8282
for long in urls:
83-
url = urlparse(long)
8483
assert BASE_DOMAIN not in long, f'{long} is a {BASE_DOMAIN} URL'
85-
if url in targets:
86-
short = targets[url]
84+
if long in targets:
85+
short = targets[long]
8786
else:
8887
short = next(iter_short)
89-
redirects[short] = url
90-
targets[url] = short
88+
redirects[short] = long
89+
targets[long] = short
9190
if timestamp:
9291
fp.write(f'\n# appended: {timestamp}\n')
9392
timestamp = None
94-
fp.write(f'RedirectTemp /{short} {urlunparse(url)}\n')
95-
pairs.append((short, url))
93+
fp.write(f'RedirectTemp /{short.decode('ascii')} {long}\n')
94+
pairs.append((short, long))
9695

9796
return pairs
9897

9998

10099
def main() -> None:
101100
"""read URLS from filename arguments or stdin"""
102101
urls = [line.strip() for line in fileinput.input(encoding='utf-8')]
103-
for short, long in shorten(urls):
104-
print(f'{BASE_DOMAIN}/{short}\t{urlunparse(long)}')
102+
for pair in shorten(urls):
103+
short = pair.code.decode('ascii')
104+
print(f'{BASE_DOMAIN}/{short}\t{pair.url}')
105105

106106

107107
if __name__ == '__main__':
108-
main()
108+
#main()
109+
load_redirects()

0 commit comments

Comments
 (0)