Example #1
0
 def test_findall_emails(self):
     email1 = "[email protected] archive"
     self.assertItemsEqual(SanitationUtils.find_all_emails(email1),
                           [u'*****@*****.**'])
     email2 = "[email protected] [email protected]"
     self.assertItemsEqual(
         SanitationUtils.find_all_emails(email2),
         [u'*****@*****.**', '*****@*****.**'])
Example #2
0
 def test_similar_markup_comparison(self):
     markup1 = ('Complete A Frame Assembly  (No Insert) - '
                'A-Frame Sign Parts - A-Frame Signs - Generic Signage')
     markup2 = (
         '<p>Complete A Frame Assembly (No Insert) - '
         'A-Frame Sign Parts - A-Frame Signs - Generic Signage</p>\n')
     self.assertEqual(SanitationUtils.similar_markup_comparison(markup1),
                      SanitationUtils.similar_markup_comparison(markup2))
 def test_find_all_urls(self):
     self.assertEqual(
         SanitationUtils.find_all_urls("http://www.technotan.com.au/"),
         [u'http://www.technotan.com.au/'])
     self.assertEqual(
         SanitationUtils.find_all_urls("http://www.technotan.com.au/?p=1"),
         [u'http://www.technotan.com.au/?p=1'])
     self.assertEqual(SanitationUtils.find_all_urls("www.technotan.com.au"),
                      [])
Example #4
0
def print_basic_columns(users):
    # print len(users)
    usrList = UsrObjList()
    for user in users:
        usrList.append(user)
        # SanitationUtils.safe_print( "BILLING ADDRESS:", repr(user), user['First Name'], user.get('First Name'), user.name.__unicode__(out_schema="flat"))

    cols = col_data.get_col_data_native('basic')

    SanitationUtils.safe_print(usrList.tabulate(cols, tablefmt='simple'))
Example #5
0
    def test_analyse_remote(self):
        product_parser_class = self.settings.slave_parser_class
        product_parser = product_parser_class(
            **self.settings.slave_parser_args)

        cat_client_class = self.settings.slave_cat_sync_client_class
        cat_client_args = self.settings.slave_cat_sync_client_args

        with cat_client_class(**cat_client_args) as client:
            client.analyse_remote_categories(product_parser)

        if self.debug:
            print("parser tree:\n%s" %
                  SanitationUtils.coerce_bytes(product_parser.to_str_tree()))

        product_client_class = self.settings.slave_download_client_class
        product_client_args = self.settings.slave_download_client_args

        with product_client_class(**product_client_args) as client:
            client.analyse_remote(product_parser, limit=20)

        prod_list = ShopProdList(product_parser.products.values())
        self.assertTrue(prod_list)
        if self.debug:
            print(
                SanitationUtils.coerce_bytes(
                    prod_list.tabulate(tablefmt='simple')))
        var_list = ShopProdList(product_parser.variations.values())
        # This is no longer necessarily true
        # self.assertTrue(var_list)
        if self.debug:
            print(
                SanitationUtils.coerce_bytes(
                    var_list.tabulate(tablefmt='simple')))
        cat_list = ShopCatList(product_parser.categories.values())
        self.assertTrue(cat_list)
        if self.debug:
            print(
                SanitationUtils.coerce_bytes(
                    cat_list.tabulate(tablefmt='simple')))
        attr_list = product_parser.attributes.items()
        self.assertTrue(attr_list)
        if self.debug:
            print(
                SanitationUtils.coerce_bytes(
                    tabulate(attr_list, headers='keys', tablefmt="simple")))
Example #6
0
 def test_wp_v2_read_post_1(self):
     sync_client_class = SyncClientWP
     sync_client_args = {
         'connect_params': self.settings.slave_wp_api_params
     }
     sync_client_args['connect_params']['version'] = 'wp/v2'
     with sync_client_class(**sync_client_args) as client:
         first_post = client.service.get('posts/1').json()
         if client.page_nesting:
             first_post = first_post['post']
         if self.debug:
             first_post_json = SanitationUtils.encode_json(first_post)
             print('first post json: \n%s' % pformat(first_post_json))
Example #7
0
    def test_get_first_item(self):
        # self.settings.wc_api_namespace = 'wc-api'
        # self.settings.wc_api_version = 'v3'
        product_client_class = self.settings.slave_download_client_class
        product_client_args = self.settings.slave_download_client_args

        with product_client_class(**product_client_args) as client:
            first_item = client.get_first_endpoint_item()
            self.assertTrue(first_item)
            if self.debug:
                print("fist item:\n%s" % pformat(first_item))
                first_item_json = SanitationUtils.encode_json(first_item)
                print("fist item json:\n%s" % pformat(first_item_json))
Example #8
0
 def test_wp_read_first_post(self):
     sync_client_class = SyncClientWP
     sync_client_args = {
         'connect_params': self.settings.slave_wp_api_params
     }
     with sync_client_class(**sync_client_args) as client:
         post_pager = client.get_iterator('posts')
         post_page = post_pager.next()
         if self.debug:
             print('first post page: %s' % pformat(post_page))
         if client.page_nesting:
             post_page = post_page['posts']
         first_post = post_page[0]
         if self.debug:
             first_post_json = SanitationUtils.encode_json(first_post)
             print('first post json: \n%s' % pformat(first_post_json))
Example #9
0

username = '******'
password = '******'
store_url = 'http://minimac.ddns.me:11182/'

# store_url = 'http://technotea.com.au/'
# username = '******'
# password = '******'
xmlrpc_uri = store_url + 'xmlrpc.php'

client = Client(xmlrpc_uri, username, password)
# posts = client.call(posts.GetPosts())
# print posts

# print client.normalize_string(u'no\u2015odle')

fields = {
    'first_name': 'no👌od👌le'.decode('utf8'),
    'user_url': "http://www.laserphile.com/",
    'user_login': "******"
}
fields_json = SanitationUtils.encode_json(fields)
SanitationUtils.safe_print(repr(fields_json))
# fields_json_base64 = SanitationUtils.encode_base64( fields_json )
fields_json_base64 = "eyJidXNpbmVzc190eXBlIjogIk90aGVyIiwgInByZWZfdGVsIjogIkZhbHNlIiwgImFjdF9yb2xlIjogIlJOIiwgInByZWZfbW9iIjogIkZhbHNlIiwgImhvd19oZWFyX2Fib3V0IjogIkV2ZW50IiwgInVzZXJfZW1haWwiOiAiZW1tYS1hbGxlbjk0QGhvdG1haWwuY29tIn0="
# print fields_json_base64
# eyJ1c2VyX2xvZ2luIjogImFkbWluIiwgImZpcnN0X25hbWUiOiAibm_wn5GMb2Twn5GMbGUiLCAidXNlcl91cmwiOiAiaHR0cDovL3d3dy5sYXNlcnBoaWxlLmNvbS8ifQ==
test_out = client.call(UpdateUser(1, fields_json_base64))
print test_out
Example #10
0
sshClient = paramiko.SSHClient()
sshClient.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
    sshClient.connect(**paramikoSSHParams)
    stdin, stdout, stderr = sshClient.exec_command(command)
    possible_errors = stdout.readlines()
    assert not possible_errors, "command returned errors: " + possible_errors
    try:
        sftp_client = sshClient.open_sftp()
        sftp_client.chdir(remote_export_folder)
        fstat = sftp_client.stat(exportFilename)
        if fstat:
            sftp_client.get(exportFilename, ma_path)
    except Exception as exc:
        SanitationUtils.safe_print("ERROR IN SFTP: " + str(exc))
    finally:
        sftp_client.close()

except Exception as exc:
    SanitationUtils.safe_print("ERROR IN SSH: " + str(exc))
finally:
    sshClient.close()

ma_parser = CsvParseUser(
    cols=col_data.get_import_cols(),
    defaults=col_data.get_defaults(),
    contact_schema='act',
)

ma_parser.analyse_file(ma_path, maEncoding)
Example #11
0
# -*- coding: utf-8 -*-
from woogenerator.utils import SanitationUtils
from kitchen.text import converters


def printandrep(name, thing, back=""):
    fmt_str = "%32s |"
    print fmt_str % name, fmt_str % converters.to_bytes(thing), fmt_str % repr(
        thing), fmt_str % converters.to_bytes(
            back), fmt_str % converters.to_bytes(unicode(back))


u_str = u"<\U0001F44C'&>"
utf8_str = SanitationUtils.unicode_to_utf8(u_str)
utf8_back = SanitationUtils.utf8_to_unicode(utf8_str)
xml_str = SanitationUtils.unicode_to_xml(u_str)
xml_back = SanitationUtils.xml_to_unicode(xml_str)
ascii_str = SanitationUtils.unicode_to_ascii(u_str)
ascii_back = SanitationUtils.ascii_to_unicode(u_str)

printandrep("u_str", u_str)
printandrep("utf8_str", utf8_str, utf8_back)
printandrep("xml_str", xml_str, xml_back)
printandrep("ascii_str", ascii_str, ascii_back)

print SanitationUtils.unicode_to_utf8(None)
print SanitationUtils.utf8_to_unicode(None)
print SanitationUtils.unicode_to_xml(None)
print SanitationUtils.xml_to_unicode(None)
print SanitationUtils.unicode_to_ascii(None)
print SanitationUtils.ascii_to_unicode(None)
Example #12
0
 def test_slugify(self):
     result = SanitationUtils.slugify("Tanbience Specials")
     self.assertEqual(result, 'tanbience_specials')
 def test_strip_protocol(self):
     self.assertEqual(
         'www.google.com/',
         SanitationUtils.strip_url_protocol('http://www.google.com/'))
Example #14
0
 def test_stripURLHost(self):
     test_url = 'http://localhost/woocommerce/wc-api/v3/products?oauth_consumer_key=ck_0297450a41484f27184d1a8a3275f9bab5b69143&oauth_timestamp=1473914520&oauth_nonce=c430d5c707d1c8c8ff446b380eddc3218a366d0a&oauth_signature_method=HMAC-SHA256&oauth_signature=dYXFhWavVbLHeqeDMbUhWxghrnBBwCwqFaS+wYAxcy8=&page=2'
     expected_result = '/woocommerce/wc-api/v3/products?oauth_consumer_key=ck_0297450a41484f27184d1a8a3275f9bab5b69143&oauth_timestamp=1473914520&oauth_nonce=c430d5c707d1c8c8ff446b380eddc3218a366d0a&oauth_signature_method=HMAC-SHA256&oauth_signature=dYXFhWavVbLHeqeDMbUhWxghrnBBwCwqFaS+wYAxcy8=&page=2'
     self.assertEqual(SanitationUtils.strip_url_host(test_url),
                      expected_result)
Example #15
0
 def test_similar_url(self):
     url1 = 'http://www.technotan.com.au'
     url2 = 'www.technotan.com.au'
     self.assertEqual(SanitationUtils.similar_url_comparison(url1), url2)
     self.assertEqual(SanitationUtils.similar_url_comparison(url2), url2)
Example #16
0
 def test_similar_comparison(self):
     url = 'http://www.facebook.com/search/?flt=1&amp;q=amber+melrose&amp;o=2048&amp;s=0#'
     self.assertItemsEqual(url, SanitationUtils.similar_comparison(url))
Example #17
0
 def test_sanitize_cell(self):
     url = 'http://www.facebook.com/search/?flt=1&amp;q=amber+melrose&amp;o=2048&amp;s=0#'
     self.assertItemsEqual(url, SanitationUtils.sanitize_cell(url))
Example #18
0
 def test_find_url_hard(self):
     url = 'http://www.facebook.com/search/?flt=1&amp;q=amber+melrose&amp;o=2048&amp;s=0#'
     self.assertItemsEqual(SanitationUtils.find_all_urls(url), [
         'http://www.facebook.com/search/?flt=1&q=amber+melrose&o=2048&s=0#'
     ])
Example #19
0
 def test_find_url(self):
     url1 = "http://www.laserphile.com/ lol"
     self.assertItemsEqual(SanitationUtils.find_all_urls(url1),
                           ['http://www.laserphile.com/'])