diff --git a/clients/nntp_client.py b/clients/nntp_client.py index 6cd4883..612e9f1 100644 --- a/clients/nntp_client.py +++ b/clients/nntp_client.py @@ -1,7 +1,8 @@ from urllib.error import URLError import urllib.request as url +import nntplib from hashlib import sha256 -from time import time +import time import json @@ -49,7 +50,7 @@ class BBJ(object): See the offical API error documentation for more details. """ - def __init__(self, host="127.0.0.1", port=7099, https=False): + def __init__(self, host="127.0.0.1", port=119, https=False): """ Optionally takes port and host as kwargs. It will immediately try to resolve a connection to the server, if its down, it @@ -193,6 +194,7 @@ class BBJ(object): self.instance_info = response["data"] + # unsupported def validate(self, key, value, exception=AssertionError): """ Uses the server's db_validate method to verify the validty @@ -212,21 +214,6 @@ class BBJ(object): # or you can handle it as a boolean like this: is_okay = bbj.validate("title", "teacups and roses <3", exception=None) """ - response = self( - "db_validate", - no_auth=True, - key=key, - value=value - ) - - if not response["data"]["bool"]: - if not exception: - return False - description = response["data"]["description"] - error = exception(description) - error.description = description - raise error - return True @@ -313,6 +300,7 @@ class BBJ(object): return True + # AUTHINFO? def validate_credentials(self, user_name, user_auth, exception=True): """ Pings the server to check that user_name can be authenticated with @@ -352,6 +340,7 @@ class BBJ(object): return False + # unsupported def user_is_registered(self, user_name): """ Returns True or False whether user_name is registered @@ -366,6 +355,7 @@ class BBJ(object): return response["data"] + # unsupported def user_register(self, user_name, user_auth, hash_auth=True, set_as_user=True): """ Register user_name into the system with user_auth. Unless hash_auth @@ -414,15 +404,15 @@ class BBJ(object): `color`. On success, the newly updated user object is returned and is also internalized as self.user. """ - response = self("user_update", **params) if params.get("user_name"): self.user_name = params["user_name"] if params.get("auth_hash"): self.user_auth = params["auth_hash"] - self.user = self("get_me")["data"] - return response["data"] + self.user = dict(params) + return self.user + # unused def user_get(self, user_id_or_name): """ Return a full user object by their id or username. @@ -500,13 +490,14 @@ class BBJ(object): "body": self.format_message(body, format), "author": author or self.user["user_id"], "post_id": post_id, - "created": time(), + "created": time.time(), "edited": False, "send_raw": False, "thread_id": "gibberish" } + # unused def format_message(self, body, format="sequential"): """ Send `body` to the server to be formatted according to `format`, @@ -515,7 +506,7 @@ class BBJ(object): response = self("format_message", body=body, format=format) return response["data"] - + # unsupported def message_delete(self, thread_id, post_id): """ Delete message `post_id` from `thread_id`. The same rules apply @@ -526,7 +517,7 @@ class BBJ(object): response = self("delete_post", thread_id=thread_id, post_id=post_id) return response["data"] - + # done def edit_query(self, thread_id, post_id): """ Queries ther server database to see if a post can @@ -536,22 +527,19 @@ class BBJ(object): Returns a message object on success, or raises a UserWarning describing why it failed. """ - response = self("edit_query", thread_id=thread_id, post_id=int(post_id)) - return response["data"] + raise UserWarning("NNTP posts cannot be edited") + # done def can_edit(self, thread_id, post_id): """ Return bool True/False that the post at thread_id | post_id can be edited by the logged in user. Will not raise UserWarning. """ - try: - result = bool(self.edit_query(thread_id, post_id)) - except UserWarning: - result = False - return result + return False + # done def edit_message(self, thread_id, post_id, new_body): """ Requires the thread_id and post_id. The edit flag is then @@ -561,12 +549,9 @@ class BBJ(object): Will raise UserWarning if server editing rules are violated. See also `can_edit` and `edit_query` """ - response = self( - "edit_post", thread_id=thread_id, - post_id=post_id, body=new_body) - return response["data"] - + raise UserWarning("NNTP posts cannot be edited") + # unused def set_post_raw(self, thread_id, post_id, value): """ This is a subset of `edit_message` that retains the old @@ -582,16 +567,17 @@ class BBJ(object): return response["data"] + # done def user_is_admin(self, user_name_or_id): """ Return boolean True or False whether the given user identifier is an admin on the server. Will raise ValueError if this user is not registered. """ - response = self("is_admin", target_user=user_name_or_id) - return response["data"] + return False + # unsupported def thread_set_pin(self, thread_id, new_status): """ Set whether a thread should be pinned or not. new_status @@ -599,10 +585,11 @@ class BBJ(object): user is an admin, the thread is set to this status on the server, and the boolean is returned. """ - response = self("thread_set_pin", thread_id=thread_id, value=new_status) - return response["data"] + return None + #raise NotImplementedError + # unused def message_feed(self, time, format=None): """ Returns a special object representing all activity on the board since