2 Komitmen 924c38b74d ... 053e596769

Pembuat SHA1 Pesan Tanggal
  khuxkm fbexl 053e596769 Add Python gitignore 4 tahun lalu
  khuxkm fbexl 214b78592b Fix GeminiClient class 4 tahun lalu
2 mengubah file dengan 151 tambahan dan 6 penghapusan
  1. 145 0
      .gitignore
  2. 6 6
      geminilib.py

+ 145 - 0
.gitignore

@@ -0,0 +1,145 @@
+
+# Created by https://www.toptal.com/developers/gitignore/api/python
+# Edit at https://www.toptal.com/developers/gitignore?templates=python
+
+### Python ###
+# Byte-compiled / optimized / DLL files
+__pycache__/
+*.py[cod]
+*$py.class
+
+# C extensions
+*.so
+
+# Distribution / packaging
+.Python
+build/
+develop-eggs/
+dist/
+downloads/
+eggs/
+.eggs/
+lib/
+lib64/
+parts/
+sdist/
+var/
+wheels/
+pip-wheel-metadata/
+share/python-wheels/
+*.egg-info/
+.installed.cfg
+*.egg
+MANIFEST
+
+# PyInstaller
+#  Usually these files are written by a python script from a template
+#  before PyInstaller builds the exe, so as to inject date/other infos into it.
+*.manifest
+*.spec
+
+# Installer logs
+pip-log.txt
+pip-delete-this-directory.txt
+
+# Unit test / coverage reports
+htmlcov/
+.tox/
+.nox/
+.coverage
+.coverage.*
+.cache
+nosetests.xml
+coverage.xml
+*.cover
+*.py,cover
+.hypothesis/
+.pytest_cache/
+pytestdebug.log
+
+# Translations
+*.mo
+*.pot
+
+# Django stuff:
+*.log
+local_settings.py
+db.sqlite3
+db.sqlite3-journal
+
+# Flask stuff:
+instance/
+.webassets-cache
+
+# Scrapy stuff:
+.scrapy
+
+# Sphinx documentation
+docs/_build/
+doc/_build/
+
+# PyBuilder
+target/
+
+# Jupyter Notebook
+.ipynb_checkpoints
+
+# IPython
+profile_default/
+ipython_config.py
+
+# pyenv
+.python-version
+
+# pipenv
+#   According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
+#   However, in case of collaboration, if having platform-specific dependencies or dependencies
+#   having no cross-platform support, pipenv may install dependencies that don't work, or not
+#   install all needed dependencies.
+#Pipfile.lock
+
+# PEP 582; used by e.g. github.com/David-OConnor/pyflow
+__pypackages__/
+
+# Celery stuff
+celerybeat-schedule
+celerybeat.pid
+
+# SageMath parsed files
+*.sage.py
+
+# Environments
+.env
+.venv
+env/
+venv/
+ENV/
+env.bak/
+venv.bak/
+pythonenv*
+
+# Spyder project settings
+.spyderproject
+.spyproject
+
+# Rope project settings
+.ropeproject
+
+# mkdocs documentation
+/site
+
+# mypy
+.mypy_cache/
+.dmypy.json
+dmypy.json
+
+# Pyre type checker
+.pyre/
+
+# pytype static type analyzer
+.pytype/
+
+# profiling data
+.prof
+
+# End of https://www.toptal.com/developers/gitignore/api/python

+ 6 - 6
geminilib.py

@@ -10,15 +10,15 @@ urllib.parse.uses_netloc.append("gemini")
 
 class GeminiClient():
     def __init__(self):
-        self.name = "geminiclient"
+        pass # later, TOFU tracking can be added via instantiation of the GeminiClient object
 
-    def request(url):
-        # This works for gemini://domain.tld/path for now; not gemini://domain.tld:port/path
+    def request(self,url):
         parsed = urllib.parse.urlparse(url)
-        addresses = socket.getaddrinfo(parsed.netloc, port, family=0, type=socket.SOCK_STREAM)
+        addresses = socket.getaddrinfo(parsed.hostname, parsed.port or 1965, family=0, type=socket.SOCK_STREAM)
 
         # We don't do the CA cert verification
-        context = ssl.SSLContext(ssl.PROTOCOL_TLSv1_2)
+        # We could implement it later but for now we won't
+        context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
         context.check_hostname = False
         context.verify_mode = ssl.CERT_NONE
         context.minimum_version = ssl.TLSVersion.TLSv1_2
@@ -38,6 +38,6 @@ class GeminiClient():
             # knowledge of earlier failures.
             raise err
 
-        s.sendall((parsed.netloc+parsed.path+parsed.params+parsed.query+"\r\n").encode("UTF-8"))
+        s.sendall((url+"\r\n").encode("UTF-8"))
         return s.makefile(mode = "rb")