-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workarounds for bugs in pygments shell lexer and first steps in filet…
…ype guessing
- Loading branch information
1 parent
cb7f1a2
commit da84d62
Showing
7 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import json | ||
import tomllib | ||
from typing import Optional | ||
|
||
|
||
class FileTypeGuesser: | ||
|
||
def __init__(self) -> None: | ||
self.probes = { | ||
'json': self._is_json, | ||
'toml': self._is_toml, | ||
} | ||
|
||
def guess(self, content: str) -> Optional[str]: | ||
for ext, probe in self.probes.items(): | ||
if probe(content): | ||
return ext | ||
|
||
# TODO: Guesslang | ||
''' | ||
ml_guesser = Guess() | ||
guess = ml_guesser.language_name(content) | ||
if not guess: | ||
return None | ||
for ext, name in ml_guesser._extension_map.items(): | ||
if name == guess: | ||
return ext | ||
''' | ||
return None | ||
|
||
|
||
|
||
def _is_json(self, content: str): | ||
try: | ||
json.loads(content) | ||
except Exception as e: | ||
return False | ||
|
||
return True | ||
|
||
def _is_toml(self, content: str): | ||
try: | ||
tomllib.loads(content) | ||
except Exception as e: | ||
return False | ||
|
||
return True | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
#!/bin/bash | ||
|
||
curl -u 'login01:password01' -s "https://example.com/test" | ||
# should not be matched as a variable | ||
curl -u 'login01:$password_var' -s "https://example.com/test" | ||
curl -u "qauser:$password" $URL > $FILENAME |