Commit Graph

304 Commits

Author SHA1 Message Date
funilrys
aa4a0f7a46
Fix backslashes issue under Windows.
This patch fixes https://github.com/StevenBlack/hosts/pull/1165#issuecomment-590111613.

This patch simply, replace the `\` Windows directory separator, with the
universal `/` of the web convention.
2020-02-24 18:34:08 +01:00
XhmikosR
d2566110ff Fix GitHub capitalization 2020-02-22 16:21:26 +02:00
funilrys
0843d83d09
It's stupid that it should be at the very top but yeah I fixed it... ¯\_(ツ)_/¯ 2019-07-13 21:06:30 +02:00
funilrys
b93b427a6e
fix #744 #843 and disable E203 (flake8).
Indeed, before this patch, no `# Title: XYZ` was describing our generated
host file. This patch fixes that.

Indeed, we now do the following:

- If no extension is included we add:
    - `# Title: StevenBlack/hosts`
- If exactly one extension is included we add:
    - `# Title: StevenBlack/hosts with the extension_name extension`
- If more than one extension is included we add (in one line):
    - `# Title: StevenBlack/hosts with the extname1,
      extname2 and extname3 extensions`

Please also note that I disable E203 (whitespace before ':') for flake8
at line 773.

Since we use Black for code formatting let me redirect you to
the documentation of Black which explain what I did.

https://black.readthedocs.io/en/stable/the_black_code_style.html#slices :

> Since E203 is not PEP 8 compliant, you should tell
> Flake8 to ignore these warnings.
2019-07-13 13:41:36 +02:00
funilrys
05dad7e657
Introduction of Black: The uncompromising Python code formatter.
Please find more about it there:
* https://github.com/python/black
* https://black.readthedocs.io/en/stable/
2019-07-13 13:40:13 +02:00
funilrys
90420ae751
Fix issue when we meet something like 0.0.0.0
This patch fix StevenBlack/hosts#904
2019-01-30 01:08:59 +01:00
Duck
5c69826a98 Change "utf8" to "UTF-8" in params for encoding in updateHostFile.py 2019-01-05 23:08:46 +08:00
Duck
df29ed238f Specify encoding to UTF-8 when opening source file 2019-01-05 19:11:01 +08:00
spirillen
ddf5a72906
Replaced (UTC) with %Z
I've changed as suggested in https://github.com/StevenBlack/hosts/pull/836#issuecomment-440452979 by @funilrys

The reason I choose NOT to convert this into ISO-8601 is, that we read date.time in different ways depending on with side on the pond we live. By using the "%d %B %Y %H:%M:%S (%Z)" Full date/time this issue is eliminated  and any confusion on how to read the date is no longer existent. The ISO-8601 is good for active pages, as the date ordering is to be manipulated by interface.

Alternative to this is we should add extra lines/info about the date.time ordering, do to this i found this as the easiest way to give this information
2018-12-07 14:31:52 +01:00
spirillen
a2989eedc8
Changes to the time.strftime to make it more accurate
Since some host files might need to be updated more frequently it's more appropriate to show timezone and the exact time for last build, hince changed the order of month and date to %d %B
2018-11-20 23:19:19 +01:00
funilrys
c0d661f388
Review of the notion of keepdomaincomments
This patch fix StevenBlack/hosts#777

This patch:
  * Change the default state of keepdomaincomments.
    * Indeed, comments are now displayed by default.
    * But if you don't need comments, feel free to use the argument.
  * Delete the requirement input when calling the `-k` argument.
  * Update tests case regarding the new state of keepdomaincomments.
2018-09-14 00:15:56 +02:00
funilrys
ec362d81c5
Deletion of the extra \n after each (and especially commented) line.
This patch partially fix StevenBlack/hosts#777 .
2018-09-13 09:17:45 +02:00
StevenBlack
ed6f65d970 Issue #733: fix – more robust if the .example files are missing. 2018-09-08 21:19:51 -04:00
gfyoung
92442955bc
Minor house-cleaning
* No parentheses single-line string
* Remove builtins function, which was
really for Python 2.x compatibility
2018-09-06 21:12:48 -07:00
gfyoung
d8df5f1dc4
Use example files to allow proper git-ignoring
The following files:

* myhosts
* blacklist
* whitelist

can be all be modified by the user for personal usage.
However, git is tracking these files since they exist
in the repository, which makes it difficult to do so
without accidentally pushing one's own customizations.

This commit converts those examples to ".example" files,
which serve as the defaults if one of the files listed
above does not exist.

Closes gh-144.
2018-09-06 12:20:37 -07:00
funilrys
e2be45842b
Deletion of unneeded comments 2018-09-05 23:53:58 -04:00
funilrys
f54a27103c
Exlicitly set the python interpreter to use 2018-09-05 23:53:58 -04:00
funilrys
9ef1e4a1fc
Deletion of unneeded comment 2018-09-05 23:53:58 -04:00
funilrys
f5ef7e02d7
Fixing flake8 issues 2018-09-05 23:53:57 -04:00
funilrys
58db5143ed
Deletion of future dependencies
Also:
  * deletion of raw_input
2018-09-05 23:53:35 -04:00
funilrys
bcb1434ecd
Introduction of an exception saying that we do not support Python 2 anymore.
This patch is the begining of https://github.com/StevenBlack/hosts/issues/729
2018-09-05 23:52:15 -04:00
funilrys
4d6f1d9065
Fixing flake8 issues 2018-09-05 23:51:29 -04:00
funilrys
928bb5201c
Deletion of future dependencies
Also:
  * deletion of raw_input
2018-09-05 23:51:28 -04:00
funilrys
943d0d732d
Introduction of an exception saying that we do not support Python 2 anymore.
This patch is the begining of https://github.com/StevenBlack/hosts/issues/729
2018-09-05 23:51:27 -04:00
gfyoung
8062b28490
Add docs for DNS cache for FreeBSD
Closes gh-157.
2018-08-03 10:43:37 -07:00
funilrys
6de96c5537
Introduction of Start xx and End xxx
This patch fix #644
2018-06-09 11:35:48 +02:00
gfyoung
e66c2cb37e
Doc / Check for Centos restart
Closes gh-622.
2018-05-22 21:53:56 -04:00
FadeMind
d7e29d9289
updateHostsFile.py: add new ipv6 variants
Based on someonewhocares.org hosts schema
2018-04-02 19:07:56 +02:00
StevenBlack
a5142db731 Our Flake8 linter's max-line-length constraint is now 120, so taking advantage of that. 2018-03-19 23:48:22 -04:00
StevenBlack
494c14f6e6 Add link to Releases on Github in our generated hosts. Closes #524 2018-03-19 23:47:25 -04:00
Steven Black
7c79fa7f2f Fixes for linting errors. 2018-03-17 23:33:44 -04:00
Steven Black
2526b76bea Accept IP followed by host IP address. 2018-03-14 00:09:38 -04:00
Ankit Pati
4b5dc8d920
Remove Superfluous Check for Zero-Length List
Checking for zero-length is not necessary here as iterating over a
zero-length list is perfectly valid, and produces exactly zero
iterations, matching the intended behaviour without an extra check.
2018-03-10 00:38:31 +05:30
funilrys
0166642e00 Merge remote-tracking branch 'upstream/master' into encoding-review 2018-03-04 11:19:36 +01:00
funilrys
8405f87edb
Review of domain_to_idna() to support more tests cases
Please note this patch comes after an issue reported by @FadeMind
which I could reproduce in 1/3 computer.
2018-03-04 11:17:38 +01:00
Mitch Weaver
1ff8f4b13d add OpenBSD support 2018-03-03 22:55:18 +01:00
Steven Black
2bd48fb7ba
Merge pull request #519 from FadeMind/cross-sudo
cross-compatible sudo FIXED CI
2018-03-03 15:13:16 -05:00
FadeMind
ee411d82c9
updateHostsFile.py: DEL whitespace after '['
https://travis-ci.org/StevenBlack/hosts/jobs/346915934#L606-L609
2018-03-03 15:30:49 +01:00
funilrys
50fde09ed7
Fix grammar.
This patch fix: d98b31fb92 (r171971716)

Thanks to @gfyoung
2018-03-02 22:56:32 +01:00
funilrys
6e62383b28
Review of Notes indentation
This patch fix : https://github.com/StevenBlack/hosts/pull/520#discussion_r171971481
+ It also fix (forgoten coma) : https://github.com/StevenBlack/hosts/pull/520#discussion_r171971574
2018-03-02 22:53:15 +01:00
funilrys
bebf7744ca
Review of the domain_to_idna() notes.
This patch fix : https://github.com/StevenBlack/hosts/pull/520#discussion_r171971574
2018-03-02 22:51:10 +01:00
funilrys
d98b31fb92
Removing of condescending line.
This patch fix : 4798710029 (r171969863)
2018-03-02 22:43:24 +01:00
funilrys
780e47ffe5
Review of domain_to_idna()
This patch review the way we get the comment at the end of a line.
I also did an application of DRY (Do not Repeat Yourself)
and/or KISS (Keep It Simple, Stupid) by refactoring the 2 `else`
statements into one line.
2018-03-02 22:07:11 +01:00
funilrys
8f00cb4d76
Deletion of a trailing '#'.
Please note that I have added that '#' by mistake.
2018-03-02 21:43:52 +01:00
funilrys
1141823bc8
Fix tests issues.
This patch introduce the installation of dependencies needed my the main commit.

This patch fixes:
 * https://travis-ci.org/funilrys/hosts/jobs/347504195#L592
 * https://travis-ci.org/funilrys/hosts/jobs/347504195#L598
2018-02-28 23:29:18 +01:00
funilrys
3403b10e50
Fix tests issues.
This patch fixes:
 * https://travis-ci.org/funilrys/hosts/jobs/347500695#L400
 * https://travis-ci.org/funilrys/hosts/jobs/347500695#L401
2018-02-28 23:24:58 +01:00
funilrys
f5c8ac58b2
Fix tests issue.
This patch fix https://travis-ci.org/funilrys/hosts/jobs/347500695#L399
2018-02-28 23:23:30 +01:00
funilrys
079d5ddd7f
Fix tests issue
This patch fix https://travis-ci.org/funilrys/hosts/jobs/347500695#L397

Please also note that I introduced that patch because
we do not directly use lxml but it is required by
BeautifulSup() to parse the HTML.
2018-02-28 23:22:32 +01:00
funilrys
1fea720034
Fix tests issue
This patch fix https://travis-ci.org/funilrys/hosts/jobs/347500695#L398
2018-02-28 23:20:01 +01:00
funilrys
d3ef85df17
Review typo + fix test issue.
This patch fix https://travis-ci.org/funilrys/hosts/jobs/347497718#L749
2018-02-28 23:15:01 +01:00
funilrys
079ad6b674
Fix test issue.
This patch fix https://travis-ci.org/funilrys/hosts/jobs/347497718#L748
2018-02-28 23:13:13 +01:00
funilrys
c82f691952
Review of get_file_by_url()
Please note that this patch also introduce
which is in charge of converting a domain in a line into
IDNA and/or UTF-8 format.

Also note the introduction of BeautifulSoup() which helps
us to decode data from the downloaded URL.

Fixes (issue(s)/protocol(s) I was able to reproduce):
 * https://github.com/StevenBlack/hosts/issues/514#issuecomment-368932152

Possible fix of (issue(s)/protocol(s) I wasn't able to reproduce):
 * https://github.com/StevenBlack/hosts/issues/514#issue-300048106
 * https://github.com/StevenBlack/hosts/issues/494#issue-296166492
 * https://github.com/StevenBlack/hosts/issues/420#issue-267453114
 * https://github.com/StevenBlack/hosts/issues/372#issue-246927047
 * https://github.com/StevenBlack/hosts/issues/382#issuecomment-322010562
2018-02-28 23:06:58 +01:00
FadeMind
33ba41bbea
updateHostsFile.py: cross-compatible sudo 2018-02-27 19:26:40 +01:00
Steven Black
007254e10f
Merge pull request #503 from ankitpati/minimise-hosts-file
Add Option to Minimise hosts File
2018-02-16 22:07:47 -05:00
Ankit Pati
01db326459
Add Option to Minimise hosts File
This option (--minimise, -m) differs from compress (--compress, -c) in
that it keeps each host on a different line, while still removing
unnecessary newlines and comments.

This is necessary because many implementations of URL blockers that rely
on hosts files do not conform to the standard which allows multiple
hosts on a single line.
2018-02-17 00:22:25 +05:30
Ankit Pati
db29acda65
FIX: Remove Hardcoded Offset in Compression
An offset of 7 was hardcoded in the function compress_file, presumably
to skip over the default target IP address of 0.0.0.0 in a hosts file.
However, this causes problems when the default is overridden using the
--ip or -i flag, causing visibly garbled output in the generated hosts
file.

Fix is to calculate the length of target IP at runtime.
2018-02-16 23:45:10 +05:30
FadeMind
5b5e854c7f
updateHostsFile.py: add ipv6 additionals
@StevenBlack.
DEFAULT hosts file in Linux

127.0.0.1       localhost
127.0.1.1       mydevicename
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
2018-02-09 19:18:54 +01:00
Stefano
d4dadf6ca3 Fixed the number of domains in each line.
Fixed the number of domains in each line and added the support to
inline comments (they will be ignored as the comment lines).
Code refactoring.
2018-01-02 22:35:27 +01:00
Stefano
510109d6d4 Updated the documentation with the new compress option.
Removed a redundant skipstatichosts option.
2018-01-02 10:51:26 +01:00
Stefano
ff9e05ffec Added an option to compress the created hosts file.
In particular, the compression option removes non-necessary lines (empty lines and comments) and puts multiple domains in each line.
This option should solve the issue #411 regarding the DNS client service of Windows.
2017-12-30 20:55:12 +01:00
Stefano
ce8d3abf7e Added an option to compress the created host file.
In particular, the compression option removes non-necessary lines (empty lines and comments) and puts multiple domains in each line.
This option should solve the issue #411 regarding the DNS client service of Windows.
2017-12-30 17:12:04 +01:00
Steven Black
bb5d174866 Fix linter complaint. 2017-12-18 23:57:02 -05:00
Steven Black
04a9a712b3 Issue #180: fix - support JSON array transformation for hosts sources. 2017-12-17 22:06:05 -05:00
gfyoung
24ab22e139
Refactor out source data updating 2017-08-20 11:52:28 -07:00
Steven Black
68dcf5c125 Remove references to .zip files in the generator programs. 2017-08-20 12:00:19 -04:00
gfyoung
f83a56d317 Refactor out global settings usage in update logic 2017-08-09 08:13:22 -07:00
gfyoung
942069db81 Refactor out global settings usage in exclusions 2017-08-07 08:43:47 -07:00
gfyoung
4b96f3f34a Refactor out global settings usage in user prompt 2017-07-13 08:20:03 -07:00
Steven Black
d945d7bcc0 Merge pull request #341 from indrajitr/hostmatch-fix
Honor whitelist exclusion only for domain or subdomain match
2017-07-09 13:13:57 -04:00
Dylan Armstrong
02a28cd05b Fix the number of unique entries. 2017-07-08 20:20:03 -05:00
gfyoung
415b89a022 Reduce dependency on global settings variable
Global variables make code less modular
and therefore more difficult to test.
2017-07-03 18:42:15 -07:00
gfyoung
dce24af399 Add unittests for updateHostsFile.py 2017-06-28 20:13:01 -07:00
Indrajit Raychaudhuri
fd046bc460 Honor whitelist exclusion only for domain or subdomain match
* Whitelisting `s.youtube.com` should not whitelist `ads.youtube.com`; but
  can whitelist `a.s.youtube.com`
* Whitelisting `twitter.com` should not whitelist `ttwitter.com` or
  `twitter.com.au`; but can whitelist `a.twitter.com`
2017-06-22 01:43:56 -05:00
Indrajit Raychaudhuri
7e1b06ecf9 Tighten regex rule to discard IP address as hostname 2017-06-20 02:06:31 -05:00
Steven Black
96ac61c119 Merge pull request #325 from gfyoung/terminal-color-support
Check if terminal supports color
2017-05-29 23:00:35 -04:00
gfyoung
2d6a8676a4 Check if terminal supports color
Closes gh-151.
2017-05-28 12:40:32 -04:00
gfyoung
3b581ce782 Refactor DNS cache flushing for Linux 2017-05-28 12:40:25 -04:00
gfyoung
51a0ec21bd Document all functions in Python scripts 2017-05-23 21:58:22 -04:00
Steven Black
526a457a38 Merge pull request #322 from gfyoung/kde-neon-dns-cache
Check /usr/lib and /lib for systemd
2017-05-23 10:03:22 -04:00
gfyoung
2aecbf9707 Concatenate str only in os.path.join
Closes gh-316.
2017-05-22 23:31:35 -04:00
gfyoung
8806131c74 Check /usr/lib and /lib for systemd
Closes gh-321.
2017-05-22 21:19:31 -04:00
gfyoung
8f3e71e327 Wrap os.path.join to handle LOCALE issues
Closes gh-81.
Closes gh-318.
2017-05-21 21:51:13 -04:00
Steven Black
d343798ed1 Ref: Issue #312 undo commit 2ff5dc2
cc @gfyoung

Commit 2ff5dc2 is generating errors on macOS.

See Issue #318.
2017-05-21 21:34:54 -04:00
gfyoung
c8e8ddee6c Wrap os.path.join to handle LOCALE issues
Closes gh-81.
2017-05-19 16:27:12 -04:00
Steven Black
f87290eff8 Merge pull request #310 from gfyoung/ubuntu-mint-dns-cache
Add DNS cache flushing calls for Linux
2017-05-19 07:30:54 -04:00
gfyoung
b3838ef2d2 Add DNS cache flushing calls for Linux
1) Add command for Linux Mint
2) Add additional command for NCSD cache

Closes gh-128.
2017-05-18 11:30:23 -04:00
gfyoung
8cb610a757 Don't crash if data source unreachable
Closes gh-26.
2017-05-18 00:17:11 -04:00
gfyoung
26cac85ca3 Patch all style errors in updateHostsFile.py 2017-05-15 15:00:16 -04:00
gfyoung
21dd1d9d56 Standardize underscore names in updateHostsFile.py 2017-05-15 13:32:39 -04:00
gfyoung
0015363385 Condense Python 2-3 compatibility code 2017-05-14 22:30:36 -04:00
gfyoung
190592577d Condense exclusion customization logic 2017-05-14 22:10:19 -04:00
gfyoung
ceb3765d24 Flush DNS cache on Windows 2017-05-14 22:07:43 -04:00
gfyoung
118a8e78a5 Remove unnecessary space between print and parenthesis 2017-05-14 14:54:24 -04:00
Steven Black
83af37862c Merge pull request #292 from gfyoung/remove-unused-imports
Remove unnecessary imports in updateHostsFile.py
2017-05-14 11:03:22 -04:00
gfyoung
5830bb8db0 Have query_yes_no return boolean
Bugs have been found where we assumed
that query_yes_no returned True/False.
Not only is it easier to check booleans
instead of strings, but it also looks
a lot cleaner in the code.
2017-05-14 00:15:58 -04:00
gfyoung
de2e45e8b2 Remove unnecessary imports in updateHostsFile.py 2017-05-13 23:43:00 -04:00
gfyoung
bdce1217bb Patch response checking in promptForFlushDnsCache
Previously, it was checking if query_yes_no returned
False, which does not happen, as the function only
returns "yes" or "no". As a result, the check was
always returning True, even when the user did not
want to flush the DNS cache.
2017-05-08 01:10:40 -04:00
DPTJKKVH
f9e8910ba0 Include 127.0.0.53 <hostname> to fix DNS issues from Ubuntu 17.04 onwards
Ubuntu 17.04 replaces dnsmasq with systemd-resolve which uses a different local IP address for domain name resolution.
By including this simple line of code we basically do the same what Issue #110 requested to fix Issue #109 but this time for systemd-resolve.
2017-04-23 11:20:29 +02:00
Tomasz Przybył
71f2b8ee3f [FIX] traceroute and netstat display anomaly
Based on hosts file generated by Uncheky app
@StevenBlack
2017-04-13 19:21:10 +02:00
Steven Black
590b62111e Trim periods in addition to whitespace. Closes #271. 2017-03-30 12:08:50 -04:00