@ -19,8 +19,10 @@ from threading import Lock
from aniDBresponses import *
from aniDBresponses import *
from aniDBerrors import *
from aniDBerrors import *
class Command :
class Command :
queue = { None : None }
queue = { None : None }
def __init__ ( self , command , * * parameters ) :
def __init__ ( self , command , * * parameters ) :
self . command = command
self . command = command
self . parameters = parameters
self . parameters = parameters
@ -74,27 +76,33 @@ class Command:
def cache ( self , interface , database ) :
def cache ( self , interface , database ) :
pass
pass
#first run
#first run
class AuthCommand ( Command ) :
class AuthCommand ( Command ) :
def __init__ ( self , username , password , protover , client , clientver , nat = None , comp = None , enc = None , mtu = None ) :
def __init__ ( self , username , password , protover , client , clientver , nat = None , comp = None , enc = None , mtu = None ) :
parameters = { ' user ' : username , ' pass ' : password , ' protover ' : protover , ' client ' : client , ' clientver ' : clientver , ' nat ' : nat , ' comp ' : comp , ' enc ' : enc , ' mtu ' : mtu }
parameters = { ' user ' : username , ' pass ' : password , ' protover ' : protover , ' client ' : client ,
' clientver ' : clientver , ' nat ' : nat , ' comp ' : comp , ' enc ' : enc , ' mtu ' : mtu }
Command . __init__ ( self , ' AUTH ' , * * parameters )
Command . __init__ ( self , ' AUTH ' , * * parameters )
class LogoutCommand ( Command ) :
class LogoutCommand ( Command ) :
def __init__ ( self ) :
def __init__ ( self ) :
Command . __init__ ( self , ' LOGOUT ' )
Command . __init__ ( self , ' LOGOUT ' )
#third run (at the same time as second)
#third run (at the same time as second)
class PushCommand ( Command ) :
class PushCommand ( Command ) :
def __init__ ( self , notify , msg , buddy = None ) :
def __init__ ( self , notify , msg , buddy = None ) :
parameters = { ' notify ' : notify , ' msg ' : msg , ' buddy ' : buddy }
parameters = { ' notify ' : notify , ' msg ' : msg , ' buddy ' : buddy }
Command . __init__ ( self , ' PUSH ' , * * parameters )
Command . __init__ ( self , ' PUSH ' , * * parameters )
class PushAckCommand ( Command ) :
class PushAckCommand ( Command ) :
def __init__ ( self , nid ) :
def __init__ ( self , nid ) :
parameters = { ' nid ' : nid }
parameters = { ' nid ' : nid }
Command . __init__ ( self , ' PUSHACK ' , * * parameters )
Command . __init__ ( self , ' PUSHACK ' , * * parameters )
class NotifyAddCommand ( Command ) :
class NotifyAddCommand ( Command ) :
def __init__ ( self , aid = None , gid = None , type = None , priority = None ) :
def __init__ ( self , aid = None , gid = None , type = None , priority = None ) :
if not ( aid or gid ) or ( aid and gid ) :
if not ( aid or gid ) or ( aid and gid ) :
@ -102,25 +110,30 @@ class NotifyAddCommand(Command):
parameters = { ' aid ' : aid , " gid " : gid , " type " : type , " priority " : priority }
parameters = { ' aid ' : aid , " gid " : gid , " type " : type , " priority " : priority }
Command . __init__ ( self , ' NOTIFICATIONADD ' , * * parameters )
Command . __init__ ( self , ' NOTIFICATIONADD ' , * * parameters )
class NotifyCommand ( Command ) :
class NotifyCommand ( Command ) :
def __init__ ( self , buddy = None ) :
def __init__ ( self , buddy = None ) :
parameters = { ' buddy ' : buddy }
parameters = { ' buddy ' : buddy }
Command . __init__ ( self , ' NOTIFY ' , * * parameters )
Command . __init__ ( self , ' NOTIFY ' , * * parameters )
class NotifyListCommand ( Command ) :
class NotifyListCommand ( Command ) :
def __init__ ( self ) :
def __init__ ( self ) :
Command . __init__ ( self , ' NOTIFYLIST ' )
Command . __init__ ( self , ' NOTIFYLIST ' )
class NotifyGetCommand ( Command ) :
class NotifyGetCommand ( Command ) :
def __init__ ( self , type , id ) :
def __init__ ( self , type , id ) :
parameters = { ' type ' : type , ' id ' : id }
parameters = { ' type ' : type , ' id ' : id }
Command . __init__ ( self , ' NOTIFYGET ' , * * parameters )
Command . __init__ ( self , ' NOTIFYGET ' , * * parameters )
class NotifyAckCommand ( Command ) :
class NotifyAckCommand ( Command ) :
def __init__ ( self , type , id ) :
def __init__ ( self , type , id ) :
parameters = { ' type ' : type , ' id ' : id }
parameters = { ' type ' : type , ' id ' : id }
Command . __init__ ( self , ' NOTIFYACK ' , * * parameters )
Command . __init__ ( self , ' NOTIFYACK ' , * * parameters )
class BuddyAddCommand ( Command ) :
class BuddyAddCommand ( Command ) :
def __init__ ( self , uid = None , uname = None ) :
def __init__ ( self , uid = None , uname = None ) :
if not ( uid or uname ) or ( uid and uname ) :
if not ( uid or uname ) or ( uid and uname ) :
@ -128,31 +141,37 @@ class BuddyAddCommand(Command):
parameters = { ' uid ' : uid , ' uname ' : uname . lower ( ) }
parameters = { ' uid ' : uid , ' uname ' : uname . lower ( ) }
Command . __init__ ( self , ' BUDDYADD ' , * * parameters )
Command . __init__ ( self , ' BUDDYADD ' , * * parameters )
class BuddyDelCommand ( Command ) :
class BuddyDelCommand ( Command ) :
def __init__ ( self , uid ) :
def __init__ ( self , uid ) :
parameters = { ' uid ' : uid }
parameters = { ' uid ' : uid }
Command . __init__ ( self , ' BUDDYDEL ' , * * parameters )
Command . __init__ ( self , ' BUDDYDEL ' , * * parameters )
class BuddyAcceptCommand ( Command ) :
class BuddyAcceptCommand ( Command ) :
def __init__ ( self , uid ) :
def __init__ ( self , uid ) :
parameters = { ' uid ' : uid }
parameters = { ' uid ' : uid }
Command . __init__ ( self , ' BUDDYACCEPT ' , * * parameters )
Command . __init__ ( self , ' BUDDYACCEPT ' , * * parameters )
class BuddyDenyCommand ( Command ) :
class BuddyDenyCommand ( Command ) :
def __init__ ( self , uid ) :
def __init__ ( self , uid ) :
parameters = { ' uid ' : uid }
parameters = { ' uid ' : uid }
Command . __init__ ( self , ' BUDDYDENY ' , * * parameters )
Command . __init__ ( self , ' BUDDYDENY ' , * * parameters )
class BuddyListCommand ( Command ) :
class BuddyListCommand ( Command ) :
def __init__ ( self , startat ) :
def __init__ ( self , startat ) :
parameters = { ' startat ' : startat }
parameters = { ' startat ' : startat }
Command . __init__ ( self , ' BUDDYLIST ' , * * parameters )
Command . __init__ ( self , ' BUDDYLIST ' , * * parameters )
class BuddyStateCommand ( Command ) :
class BuddyStateCommand ( Command ) :
def __init__ ( self , startat ) :
def __init__ ( self , startat ) :
parameters = { ' startat ' : startat }
parameters = { ' startat ' : startat }
Command . __init__ ( self , ' BUDDYSTATE ' , * * parameters )
Command . __init__ ( self , ' BUDDYSTATE ' , * * parameters )
#first run
#first run
class AnimeCommand ( Command ) :
class AnimeCommand ( Command ) :
def __init__ ( self , aid = None , aname = None , amask = None ) :
def __init__ ( self , aid = None , aname = None , amask = None ) :
@ -161,6 +180,7 @@ class AnimeCommand(Command):
parameters = { ' aid ' : aid , ' aname ' : aname , ' amask ' : amask }
parameters = { ' aid ' : aid , ' aname ' : aname , ' amask ' : amask }
Command . __init__ ( self , ' ANIME ' , * * parameters )
Command . __init__ ( self , ' ANIME ' , * * parameters )
class EpisodeCommand ( Command ) :
class EpisodeCommand ( Command ) :
def __init__ ( self , eid = None , aid = None , aname = None , epno = None ) :
def __init__ ( self , eid = None , aid = None , aname = None , epno = None ) :
if not ( eid or ( ( aname or aid ) and epno ) ) or ( aname and aid ) or ( eid and ( aname or aid or epno ) ) :
if not ( eid or ( ( aname or aid ) and epno ) ) or ( aname and aid ) or ( eid and ( aname or aid or epno ) ) :
@ -168,13 +188,21 @@ class EpisodeCommand(Command):
parameters = { ' eid ' : eid , ' aid ' : aid , ' aname ' : aname , ' epno ' : epno }
parameters = { ' eid ' : eid , ' aid ' : aid , ' aname ' : aname , ' epno ' : epno }
Command . __init__ ( self , ' EPISODE ' , * * parameters )
Command . __init__ ( self , ' EPISODE ' , * * parameters )
class FileCommand ( Command ) :
class FileCommand ( Command ) :
def __init__ ( self , fid = None , size = None , ed2k = None , aid = None , aname = None , gid = None , gname = None , epno = None , fmask = None , amask = None ) :
def __init__ ( self , fid = None , size = None , ed2k = None , aid = None , aname = None , gid = None , gname = None , epno = None ,
if not ( fid or ( size and ed2k ) or ( ( aid or aname ) and ( gid or gname ) and epno ) ) or ( fid and ( size or ed2k or aid or aname or gid or gname or epno ) ) or ( ( size and ed2k ) and ( fid or aid or aname or gid or gname or epno ) ) or ( ( ( aid or aname ) and ( gid or gname ) and epno ) and ( fid or size or ed2k ) ) or ( aid and aname ) or ( gid and gname ) :
fmask = None , amask = None ) :
if not ( fid or ( size and ed2k ) or ( ( aid or aname ) and ( gid or gname ) and epno ) ) or (
fid and ( size or ed2k or aid or aname or gid or gname or epno ) ) or (
( size and ed2k ) and ( fid or aid or aname or gid or gname or epno ) ) or (
( ( aid or aname ) and ( gid or gname ) and epno ) and ( fid or size or ed2k ) ) or ( aid and aname ) or (
gid and gname ) :
raise AniDBIncorrectParameterError , " You must provide <fid XOR size+ed2k XOR a(id|name)+g(id|name)+epno> for FILE command "
raise AniDBIncorrectParameterError , " You must provide <fid XOR size+ed2k XOR a(id|name)+g(id|name)+epno> for FILE command "
parameters = { ' fid ' : fid , ' size ' : size , ' ed2k ' : ed2k , ' aid ' : aid , ' aname ' : aname , ' gid ' : gid , ' gname ' : gname , ' epno ' : epno , ' fmask ' : fmask , ' amask ' : amask }
parameters = { ' fid ' : fid , ' size ' : size , ' ed2k ' : ed2k , ' aid ' : aid , ' aname ' : aname , ' gid ' : gid , ' gname ' : gname ,
' epno ' : epno , ' fmask ' : fmask , ' amask ' : amask }
Command . __init__ ( self , ' FILE ' , * * parameters )
Command . __init__ ( self , ' FILE ' , * * parameters )
class GroupCommand ( Command ) :
class GroupCommand ( Command ) :
def __init__ ( self , gid = None , gname = None ) :
def __init__ ( self , gid = None , gname = None ) :
if not ( gid or gname ) or ( gid and gname ) :
if not ( gid or gname ) or ( gid and gname ) :
@ -182,6 +210,7 @@ class GroupCommand(Command):
parameters = { ' gid ' : gid , ' gname ' : gname }
parameters = { ' gid ' : gid , ' gname ' : gname }
Command . __init__ ( self , ' GROUP ' , * * parameters )
Command . __init__ ( self , ' GROUP ' , * * parameters )
class GroupstatusCommand ( Command ) :
class GroupstatusCommand ( Command ) :
def __init__ ( self , aid = None , status = None ) :
def __init__ ( self , aid = None , status = None ) :
if not aid :
if not aid :
@ -189,6 +218,7 @@ class GroupstatusCommand(Command):
parameters = { ' aid ' : aid , ' status ' : status }
parameters = { ' aid ' : aid , ' status ' : status }
Command . __init__ ( self , ' GROUPSTATUS ' , * * parameters )
Command . __init__ ( self , ' GROUPSTATUS ' , * * parameters )
class ProducerCommand ( Command ) :
class ProducerCommand ( Command ) :
def __init__ ( self , pid = None , pname = None ) :
def __init__ ( self , pid = None , pname = None ) :
if not ( pid or pname ) or ( pid and pname ) :
if not ( pid or pname ) or ( pid and pname ) :
@ -233,11 +263,17 @@ class ProducerCommand(Command):
db . insert ( ' ptb ' , names , valueholders , * values )
db . insert ( ' ptb ' , names , valueholders , * values )
class MyListCommand ( Command ) :
class MyListCommand ( Command ) :
def __init__ ( self , lid = None , fid = None , size = None , ed2k = None , aid = None , aname = None , gid = None , gname = None , epno = None ) :
def __init__ ( self , lid = None , fid = None , size = None , ed2k = None , aid = None , aname = None , gid = None , gname = None , epno = None ) :
if not ( lid or fid or ( size and ed2k ) or ( aid or aname ) ) or ( lid and ( fid or size or ed2k or aid or aname or gid or gname or epno ) ) or ( fid and ( lid or size or ed2k or aid or aname or gid or gname or epno ) ) or ( ( size and ed2k ) and ( lid or fid or aid or aname or gid or gname or epno ) ) or ( ( aid or aname ) and ( lid or fid or size or ed2k ) ) or ( aid and aname ) or ( gid and gname ) :
if not ( lid or fid or ( size and ed2k ) or ( aid or aname ) ) or (
lid and ( fid or size or ed2k or aid or aname or gid or gname or epno ) ) or (
fid and ( lid or size or ed2k or aid or aname or gid or gname or epno ) ) or (
( size and ed2k ) and ( lid or fid or aid or aname or gid or gname or epno ) ) or (
( aid or aname ) and ( lid or fid or size or ed2k ) ) or ( aid and aname ) or ( gid and gname ) :
raise AniDBIncorrectParameterError , " You must provide <lid XOR fid XOR size+ed2k XOR a(id|name)+g(id|name)+epno> for MYLIST command "
raise AniDBIncorrectParameterError , " You must provide <lid XOR fid XOR size+ed2k XOR a(id|name)+g(id|name)+epno> for MYLIST command "
parameters = { ' lid ' : lid , ' fid ' : fid , ' size ' : size , ' ed2k ' : ed2k , ' aid ' : aid , ' aname ' : aname , ' gid ' : gid , ' gname ' : gname , ' epno ' : epno }
parameters = { ' lid ' : lid , ' fid ' : fid , ' size ' : size , ' ed2k ' : ed2k , ' aid ' : aid , ' aname ' : aname , ' gid ' : gid ,
' gname ' : gname , ' epno ' : epno }
Command . __init__ ( self , ' MYLIST ' , * * parameters )
Command . __init__ ( self , ' MYLIST ' , * * parameters )
def cached ( self , intr , db ) :
def cached ( self , intr , db ) :
@ -320,24 +356,39 @@ class MyListCommand(Command):
db . insert ( ' ltb ' , names , valueholders , * values )
db . insert ( ' ltb ' , names , valueholders , * values )
class MyListAddCommand ( Command ) :
class MyListAddCommand ( Command ) :
def __init__ ( self , lid = None , fid = None , size = None , ed2k = None , aid = None , aname = None , gid = None , gname = None , epno = None , edit = None , state = None , viewed = None , source = None , storage = None , other = None ) :
def __init__ ( self , lid = None , fid = None , size = None , ed2k = None , aid = None , aname = None , gid = None , gname = None , epno = None ,
if not ( lid or fid or ( size and ed2k ) or ( ( aid or aname ) and ( gid or gname ) ) ) or ( lid and ( fid or size or ed2k or aid or aname or gid or gname or epno ) ) or ( fid and ( lid or size or ed2k or aid or aname or gid or gname or epno ) ) or ( ( size and ed2k ) and ( lid or fid or aid or aname or gid or gname or epno ) ) or ( ( ( aid or aname ) and ( gid or gname ) ) and ( lid or fid or size or ed2k ) ) or ( aid and aname ) or ( gid and gname ) or ( lid and not edit ) :
edit = None , state = None , viewed = None , source = None , storage = None , other = None ) :
if not ( lid or fid or ( size and ed2k ) or ( ( aid or aname ) and ( gid or gname ) ) ) or (
lid and ( fid or size or ed2k or aid or aname or gid or gname or epno ) ) or (
fid and ( lid or size or ed2k or aid or aname or gid or gname or epno ) ) or (
( size and ed2k ) and ( lid or fid or aid or aname or gid or gname or epno ) ) or (
( ( aid or aname ) and ( gid or gname ) ) and ( lid or fid or size or ed2k ) ) or ( aid and aname ) or (
gid and gname ) or ( lid and not edit ) :
raise AniDBIncorrectParameterError , " You must provide <lid XOR fid XOR size+ed2k XOR a(id|name)+g(id|name)+epno> for MYLISTADD command "
raise AniDBIncorrectParameterError , " You must provide <lid XOR fid XOR size+ed2k XOR a(id|name)+g(id|name)+epno> for MYLISTADD command "
parameters = { ' lid ' : lid , ' fid ' : fid , ' size ' : size , ' ed2k ' : ed2k , ' aid ' : aid , ' aname ' : aname , ' gid ' : gid , ' gname ' : gname , ' epno ' : epno , ' edit ' : edit , ' state ' : state , ' viewed ' : viewed , ' source ' : source , ' storage ' : storage , ' other ' : other }
parameters = { ' lid ' : lid , ' fid ' : fid , ' size ' : size , ' ed2k ' : ed2k , ' aid ' : aid , ' aname ' : aname , ' gid ' : gid ,
' gname ' : gname , ' epno ' : epno , ' edit ' : edit , ' state ' : state , ' viewed ' : viewed , ' source ' : source ,
' storage ' : storage , ' other ' : other }
Command . __init__ ( self , ' MYLISTADD ' , * * parameters )
Command . __init__ ( self , ' MYLISTADD ' , * * parameters )
class MyListDelCommand ( Command ) :
class MyListDelCommand ( Command ) :
def __init__ ( self , lid = None , fid = None , aid = None , aname = None , gid = None , gname = None , epno = None ) :
def __init__ ( self , lid = None , fid = None , aid = None , aname = None , gid = None , gname = None , epno = None ) :
if not ( lid or fid or ( ( aid or aname ) and ( gid or gname ) and epno ) ) or ( lid and ( fid or aid or aname or gid or gname or epno ) ) or ( fid and ( lid or aid or aname or gid or gname or epno ) ) or ( ( ( aid or aname ) and ( gid or gname ) and epno ) and ( lid or fid ) ) or ( aid and aname ) or ( gid and gname ) :
if not ( lid or fid or ( ( aid or aname ) and ( gid or gname ) and epno ) ) or (
lid and ( fid or aid or aname or gid or gname or epno ) ) or (
fid and ( lid or aid or aname or gid or gname or epno ) ) or (
( ( aid or aname ) and ( gid or gname ) and epno ) and ( lid or fid ) ) or ( aid and aname ) or ( gid and gname ) :
raise AniDBIncorrectParameterError , " You must provide <lid+edit=1 XOR fid XOR a(id|name)+g(id|name)+epno> for MYLISTDEL command "
raise AniDBIncorrectParameterError , " You must provide <lid+edit=1 XOR fid XOR a(id|name)+g(id|name)+epno> for MYLISTDEL command "
parameters = { ' lid ' : lid , ' fid ' : fid , ' aid ' : aid , ' aname ' : aname , ' gid ' : gid , ' gname ' : gname , ' epno ' : epno }
parameters = { ' lid ' : lid , ' fid ' : fid , ' aid ' : aid , ' aname ' : aname , ' gid ' : gid , ' gname ' : gname , ' epno ' : epno }
Command . __init__ ( self , ' MYLISTDEL ' , * * parameters )
Command . __init__ ( self , ' MYLISTDEL ' , * * parameters )
class MyListStatsCommand ( Command ) :
class MyListStatsCommand ( Command ) :
def __init__ ( self ) :
def __init__ ( self ) :
Command . __init__ ( self , ' MYLISTSTATS ' )
Command . __init__ ( self , ' MYLISTSTATS ' )
class VoteCommand ( Command ) :
class VoteCommand ( Command ) :
def __init__ ( self , type , id = None , name = None , value = None , epno = None ) :
def __init__ ( self , type , id = None , name = None , value = None , epno = None ) :
if not ( id or name ) or ( id and name ) :
if not ( id or name ) or ( id and name ) :
@ -345,15 +396,18 @@ class VoteCommand(Command):
parameters = { ' type ' : type , ' id ' : id , ' name ' : name , ' value ' : value , ' epno ' : epno }
parameters = { ' type ' : type , ' id ' : id , ' name ' : name , ' value ' : value , ' epno ' : epno }
Command . __init__ ( self , ' VOTE ' , * * parameters )
Command . __init__ ( self , ' VOTE ' , * * parameters )
class RandomAnimeCommand ( Command ) :
class RandomAnimeCommand ( Command ) :
def __init__ ( self , type ) :
def __init__ ( self , type ) :
parameters = { ' type ' : type }
parameters = { ' type ' : type }
Command . __init__ ( self , ' RANDOMANIME ' , * * parameters )
Command . __init__ ( self , ' RANDOMANIME ' , * * parameters )
class PingCommand ( Command ) :
class PingCommand ( Command ) :
def __init__ ( self ) :
def __init__ ( self ) :
Command . __init__ ( self , ' PING ' )
Command . __init__ ( self , ' PING ' )
#second run
#second run
class EncryptCommand ( Command ) :
class EncryptCommand ( Command ) :
def __init__ ( self , user , apipassword , type ) :
def __init__ ( self , user , apipassword , type ) :
@ -361,11 +415,13 @@ class EncryptCommand(Command):
parameters = { ' user ' : user . lower ( ) , ' type ' : type }
parameters = { ' user ' : user . lower ( ) , ' type ' : type }
Command . __init__ ( self , ' ENCRYPT ' , * * parameters )
Command . __init__ ( self , ' ENCRYPT ' , * * parameters )
class EncodingCommand ( Command ) :
class EncodingCommand ( Command ) :
def __init__ ( self , name ) :
def __init__ ( self , name ) :
parameters = { ' name ' : type }
parameters = { ' name ' : type }
Command . __init__ ( self , ' ENCODING ' , * * parameters )
Command . __init__ ( self , ' ENCODING ' , * * parameters )
class SendMsgCommand ( Command ) :
class SendMsgCommand ( Command ) :
def __init__ ( self , to , title , body ) :
def __init__ ( self , to , title , body ) :
if len ( title ) > 50 or len ( body ) > 900 :
if len ( title ) > 50 or len ( body ) > 900 :
@ -373,15 +429,18 @@ class SendMsgCommand(Command):
parameters = { ' to ' : to . lower ( ) , ' title ' : title , ' body ' : body }
parameters = { ' to ' : to . lower ( ) , ' title ' : title , ' body ' : body }
Command . __init__ ( self , ' SENDMSG ' , * * parameters )
Command . __init__ ( self , ' SENDMSG ' , * * parameters )
class UserCommand ( Command ) :
class UserCommand ( Command ) :
def __init__ ( self , user ) :
def __init__ ( self , user ) :
parameters = { ' user ' : user }
parameters = { ' user ' : user }
Command . __init__ ( self , ' USER ' , * * parameters )
Command . __init__ ( self , ' USER ' , * * parameters )
class UptimeCommand ( Command ) :
class UptimeCommand ( Command ) :
def __init__ ( self ) :
def __init__ ( self ) :
Command . __init__ ( self , ' UPTIME ' )
Command . __init__ ( self , ' UPTIME ' )
class VersionCommand ( Command ) :
class VersionCommand ( Command ) :
def __init__ ( self ) :
def __init__ ( self ) :
Command . __init__ ( self , ' VERSION ' )
Command . __init__ ( self , ' VERSION ' )