本文整理汇总了Python中normality.slugify方法的典型用法代码示例。如果您正苦于以下问题:Python normality.slugify方法的具体用法?Python normality.slugify怎么用?Python normality.slugify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类normality
的用法示例。
在下文中一共展示了normality.slugify方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_empty
# 需要导入模块: import normality [as 别名]
# 或者: from normality import slugify [as 别名]
def test_empty(self):
self.assertEqual(None, slugify(None))
self.assertEqual(None, ascii_text(None))
self.assertEqual(None, latinize_text(None))
self.assertEqual(None, normalize(None))
self.assertEqual(None, normalize(''))
self.assertEqual(None, normalize(' '))
示例2: test_petro
# 需要导入模块: import normality [as 别名]
# 或者: from normality import slugify [as 别名]
def test_petro(self):
text = u'Порошенко Петро Олексійович'
self.assertEqual('porosenko-petro-oleksijovic', slugify(text))
self.assertEqual('Porosenko Petro Oleksijovic', ascii_text(text))
self.assertEqual(u'Porošenko Petro Oleksíjovič', latinize_text(text))
self.assertEqual(u'порошенко петро олексіиович', normalize(text))
示例3: test_slugify
# 需要导入模块: import normality [as 别名]
# 或者: from normality import slugify [as 别名]
def test_slugify(self):
text = u'BABY! camel-is good'
self.assertEqual('baby-camel-is-good', slugify(text, sep='-'))
示例4: column_alias
# 需要导入模块: import normality [as 别名]
# 或者: from normality import slugify [as 别名]
def column_alias(cell, names):
""" Generate a normalized version of the column name. """
column = slugify(cell.column or '', sep='_')
column = column.strip('_')
column = 'column' if not len(column) else column
name, i = column, 2
# de-dupe: column, column_2, column_3, ...
while name in names:
name = '%s_%s' % (name, i)
i += 1
return name
示例5: slug
# 需要导入模块: import normality [as 别名]
# 或者: from normality import slugify [as 别名]
def slug(name):
return slugify(name, sep='_')
示例6: get_queries
# 需要导入模块: import normality [as 别名]
# 或者: from normality import slugify [as 别名]
def get_queries():
for ds, map in get_mappings():
ds_name = ds['name']
table_pattern = ds_name + '__'
entry_table = '"' + table_pattern + 'entry"'
fields = [(entry_table + '.id', '_openspending_id')]
joins = []
for dim, desc in map.items():
if desc.get('type') == 'compound':
dim_table = '"%s%s"' % (table_pattern, dim)
joins.append((dim_table, dim))
for attr, attr_desc in desc.get('attributes').items():
alias = '%s_%s' % (dim, attr)
fields.append(('%s."%s"' % (dim_table, attr), alias))
elif desc.get('type') == 'date':
dim_table = '"%s%s"' % (table_pattern, dim)
joins.append((dim_table, dim))
for attr in ['name', 'year', 'month', 'day', 'week',
'yearmonth', 'quarter']:
alias = '%s_%s' % (dim, attr)
fields.append(('%s."%s"' % (dim_table, attr), alias))
fields.append(('%s.name' % dim_table, dim))
else:
fields.append(('%s."%s"' % (entry_table, dim), dim))
select_clause = []
for src, alias in fields:
select_clause.append('%s AS "%s"' % (src, slugify(alias, sep='_')))
select_clause = ', '.join(select_clause)
join_clause = []
for table, dim in joins:
qb = 'LEFT JOIN %s ON %s."%s_id" = %s.id'
qb = qb % (table, entry_table, dim, table)
join_clause.append(qb)
join_clause = ' '.join(join_clause)
yield ds, 'SELECT %s FROM %s %s' % (select_clause, entry_table,
join_clause)
示例7: slugify
# 需要导入模块: import normality [as 别名]
# 或者: from normality import slugify [as 别名]
def slugify(mapping, bind, values):
""" Transform all values into URL-capable slugs. """
for value in values:
if isinstance(value, six.string_types):
value = transliterate(value)
value = normality.slugify(value)
yield value
示例8: node_id
# 需要导入模块: import normality [as 别名]
# 或者: from normality import slugify [as 别名]
def node_id(self, value):
return 'name:%s' % slugify(value)
示例9: node_id
# 需要导入模块: import normality [as 别名]
# 或者: from normality import slugify [as 别名]
def node_id(self, value: str) -> str:
return 'addr:%s' % slugify(value)
示例10: convert_snakecase
# 需要导入模块: import normality [as 别名]
# 或者: from normality import slugify [as 别名]
def convert_snakecase(name):
if name.upper() != name:
name = titlecase(name)
return slugify(name, sep='_')
示例11: parse
# 需要导入模块: import normality [as 别名]
# 或者: from normality import slugify [as 别名]
def parse(context, data):
emitter = EntityEmitter(context)
references = defaultdict(list)
with context.http.rehash(data) as res:
xls = xlrd.open_workbook(res.file_path)
ws = xls.sheet_by_index(0)
headers = [slugify(h, sep='_') for h in ws.row_values(0)]
for r in range(1, ws.nrows):
row = ws.row(r)
row = dict(zip(headers, row))
for header, cell in row.items():
if cell.ctype == 2:
row[header] = str(int(cell.value))
elif cell.ctype == 3:
date = xldate_as_datetime(cell.value, xls.datemode)
row[header] = date.isoformat()
elif cell.ctype == 0:
row[header] = None
row[header] = cell.value
reference = clean_reference(row.get('reference'))
references[reference].append(row)
for ref, rows in references.items():
parse_reference(emitter, ref, rows)
emitter.finalize()