kmisc 2.1.93__py3-none-any.whl → 2.1.95__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
kmisc/__init__.py CHANGED
@@ -15,6 +15,7 @@ import copy
15
15
  import json
16
16
  import random
17
17
  import string
18
+ import socket
18
19
  import pickle
19
20
  import base64
20
21
  import hashlib
@@ -47,6 +48,8 @@ except:
47
48
  print('Can not install kmport')
48
49
  os._exit(1)
49
50
 
51
+ Import('import whois',install_name='python-whois')
52
+ #Import('import whois') # it print some comment on screen
50
53
 
51
54
  global krc_define
52
55
  global printf_log_base
@@ -1473,6 +1476,51 @@ class COLOR:
1473
1476
  msg=fmt_msg % (color_code,msg)
1474
1477
  return msg+reset
1475
1478
 
1479
+ def Domainname(source=None,info=False):
1480
+ if source:
1481
+ try:
1482
+ d=whois.whois(source) # python-whois
1483
+ # d=whois.query(source) # use whois
1484
+ except Exception:
1485
+ return False,source
1486
+ else:
1487
+ # if info:
1488
+ # if d is None: return False,None
1489
+ # return True,d.__dict__
1490
+ # if d is None: return False,source
1491
+ # return d.expiration_date >= datetime.now(),source # whois
1492
+ return bool(d.domain_name),source # python-whois
1493
+ else:
1494
+ dn=socket.getfqdn().split('.', 1)
1495
+ if len(dn) == 1:
1496
+ return True,dn[0]
1497
+ else:
1498
+ return True,dn[1]
1499
+
1500
+ def EmailAddress(email,local=False,check_domain=True):
1501
+ if isinstance(email,str):
1502
+ src_a=email.split('@')
1503
+ if not local and len(src_a) == 2:
1504
+ if len(src_a[0]) > 1 and len(src_a[1]) > 3 and '.' in src_a[1]:
1505
+ if check_domain is True:
1506
+ username=src_a[0]
1507
+ domain=src_a[1]
1508
+ if Domainname(domain)[0]:
1509
+ return True,email
1510
+ else:
1511
+ return True,email
1512
+ elif local or len(src_a) in [1,2]:
1513
+ with open('/etc/passwd','r') as f:
1514
+ pwi=f.read()
1515
+ user_list=[i.split(':')[0] for i in pwi.split('\n')]
1516
+ local_domain=Domainname()[1]
1517
+ if len(src_a) == 2 and src_a[1]:
1518
+ if local_domain == src_a[1] and src_a[0] in user_list:
1519
+ return True,email
1520
+ elif src_a[0] in user_list:
1521
+ return True,'{}@{}'.format(src_a[0],local_domain)
1522
+ return False,email
1523
+
1476
1524
  class EMAIL:
1477
1525
  ############################
1478
1526
  # GMAIL Information
@@ -1480,6 +1528,7 @@ class EMAIL:
1480
1528
  # SSL Port: 465
1481
1529
  # user : email address
1482
1530
  # password: email password
1531
+ # ex) email.Send('<to user>@gmail.com',sender='<from user>@<your domain>',title='test2',msg='test body2',filename='test.tgz',html=True,dbg=True)
1483
1532
  ############################
1484
1533
  def __init__(self,server='127.0.0.1',port=25,user=None,password=None,ssl=False,tls=False):
1485
1534
  self.server=server
@@ -1516,7 +1565,7 @@ class EMAIL:
1516
1565
  part=MIMEBase("application", "octet-stream")
1517
1566
  part.set_payload(attachment.read())
1518
1567
  encoders.encode_base64(part)
1519
- part.add_header('Content-Disposition','attachment; filename="{filename}"')
1568
+ part.add_header('Content-Disposition','attachment; filename="{}"'.format(filename))
1520
1569
  _body.attach(part)
1521
1570
  else:
1522
1571
  if html:
@@ -1567,7 +1616,7 @@ class EMAIL:
1567
1616
 
1568
1617
  #def Send(self,sender,receivers,title='Subject',msg='MSG',dbg=False,filename=None,html=False):
1569
1618
  def Send(self,*receivers,**opts):
1570
- sender=opts.get('sender',opts.get('from','root@localhost'))
1619
+ sender=opts.get('sender',opts.get('from','admin@localhost'))
1571
1620
  title=opts.get('title',opts.get('subject','Unknown Subject'))
1572
1621
  msg=opts.get('msg',opts.get('body','No body'))
1573
1622
  dbg=opts.get('dbg',False)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: kmisc
3
- Version: 2.1.93
3
+ Version: 2.1.95
4
4
  Summary: Enginering useful library
5
5
  Home-page: https://github.com/kagepark/kmisc
6
6
  Author: Kage Park
@@ -0,0 +1,6 @@
1
+ kmisc/__init__.py,sha256=zeAC6HEUSEdmVSno4YTleoFDH0UMDE4hAvQoDoks2iQ,132810
2
+ kmisc-2.1.95.dist-info/LICENSE,sha256=mn9ekhb34HJxsrVhcxrLXJUzy55T62zg-Gh9Ro0mVJI,1066
3
+ kmisc-2.1.95.dist-info/METADATA,sha256=DiVwCUtN69_T8dUJDUnJ1-6MG5u4nI7lOitsuJFQe4w,5522
4
+ kmisc-2.1.95.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
5
+ kmisc-2.1.95.dist-info/top_level.txt,sha256=wvdHf5aQTqcGYvxk-F9E_BMWLMhlwC8INBmwO-V6_X4,6
6
+ kmisc-2.1.95.dist-info/RECORD,,
@@ -1,6 +0,0 @@
1
- kmisc/__init__.py,sha256=yLNhrnYETJghBm6cPk4UHgD7QK0e-lU_zhUuuN59z1g,130843
2
- kmisc-2.1.93.dist-info/LICENSE,sha256=mn9ekhb34HJxsrVhcxrLXJUzy55T62zg-Gh9Ro0mVJI,1066
3
- kmisc-2.1.93.dist-info/METADATA,sha256=rbCSKnlyeBanDbxj8g5-jhKUa56LalJexo_H4I1XRDg,5522
4
- kmisc-2.1.93.dist-info/WHEEL,sha256=2wepM1nk4DS4eFpYrW1TTqPcoGNfHhhO_i5m4cOimbo,92
5
- kmisc-2.1.93.dist-info/top_level.txt,sha256=wvdHf5aQTqcGYvxk-F9E_BMWLMhlwC8INBmwO-V6_X4,6
6
- kmisc-2.1.93.dist-info/RECORD,,
File without changes